예제 #1
0
    def run(self, *args, **varargs):
        this = yield
        window = sublime.active_window()
        view = window.active_view()
        view_name = os.path.split(view.file_name() or view.name())[1]

        frames = ["Running Nim Check" + f for f in busy_frames]
        stop_status_loop = loop_status_msg(frames, 0.15)

        # Save view text
        if view.is_dirty():
            view.run_command('save')

        # Run 'nim check' on the current view and retrieve the output.
        # project_file = get_nim_project(window, view) or view.file_name()
        process, output, err = yield run_nimcheck(view.file_name(), self.verbosity, this.send)
        messages = parse_nimcheck_output(output)

        yield stop_status_loop(get_next_method(this))
        sublime.status_message("Nim Check Finished.")

        self.highlight_and_list_messages(messages, window, view)

        if self.send_output:
            if self.raw_output:
                content = output
            else:
                gen = (m[5] for m in messages if view_name == m[0])
                content = "\n".join(gen)
            self.write_to_output(content, window, view)
        yield
예제 #2
0
파일: nimble.py 프로젝트: tulayang/NimLime
    def run(self):
        this = yield
        window = sublime.active_window()
        view = window.active_view()

        # Setup the loading notice
        frames = ['Updating Nimble package list' + f for f in busy_frames]
        stop_status_loop = loop_status_msg(frames, 0.15)

        # Run the main command
        process, stdout, _, error = yield run_process(
            (configuration.nimble_exe, '-y', 'update'),
            callback=this.send,
            timeout=self.timeout,
            stdout=subprocess.PIPE,
            stderr=subprocess.STDOUT)
        yield stop_status_loop(get_next_method(this))

        # Handle possible errors
        if handle_process_error(error, 'Nimble Update Failed', 'Nimble'):
            yield

        # Write output
        self.write_to_output(stdout, window, view)

        if process.poll() == 0:
            sublime.status_message('Nimble Package List Updated')
        else:
            sublime.status_message('Nimble Update Failed')

        yield
예제 #3
0
    def run(self):
        this = yield
        window = sublime.active_window()
        view = window.active_view()

        # Setup the loading notice
        frames = ['Updating Nimble package list' + f for f in busy_frames]
        stop_status_loop = loop_status_msg(frames, 0.15)

        # Run the main command
        process, output, errors = yield run_nimble(
            (configuration.nimble_executable, '-y', 'update'),
            this.send, self.timeout
        )
        return_code = process.poll()

        # Set the status to show we've finished
        yield stop_status_loop(get_next_method(this))

        # Write output
        self.write_to_output(output, window, view)

        if return_code == 0:
            sublime.status_message("Nimble Package List Updated")
        else:
            sublime.status_message('Updating Nimble Package List Failed')

        yield
예제 #4
0
    def run(self):
        this = yield
        window = sublime.active_window()
        view = window.active_view()

        nimsuggest = self.get_nimsuggest_instance(view.file_name())
        ide_params = self.get_ide_parameters(window, view)
        nim_file, dirty_file, line, column = ide_params

        output, entries = yield nimsuggest.find_definition(
            nim_file, dirty_file, line, column, this.send)

        # Get the file and open it.
        if len(entries):
            # Retrieve the correct entry
            index = 0
            if len(entries) > 1:
                input_list = [[e[5] + ', ' + e[6] + ': ' + e[3], e[4]]
                              for e in entries]
                index = yield window.show_quick_panel(input_list, this.send)
                if index == -1:
                    yield

            # Open the entry file and go to the point
            entry = entries[index]
            view = window.open_file(entry[4], sublime.TRANSIENT)
            while view.is_loading():
                yield sublime.set_timeout(get_next_method(this), 1000)
            view.show_at_center(view.text_point(int(entry[5]), int(entry[6])))
        else:
            sublime.status_message('NimLime: No definition found in project '
                                   'files.')

        yield
예제 #5
0
파일: nimble.py 프로젝트: jdah/NimLime
    def run(self):
        this = yield
        window = sublime.active_window()
        view = window.active_view()

        # Setup the loading notice
        frames = ['Updating Nimble package list' + f for f in busy_frames]
        stop_status_loop = loop_status_msg(frames, 0.15)

        # Run the main command
        process, stdout, _, error = yield run_process(
            (configuration.nimble_exe, '-y', 'update'),
            callback=this.send, timeout=self.timeout,
            stdout=subprocess.PIPE, stderr=subprocess.STDOUT
        )
        yield stop_status_loop(get_next_method(this))

        # Handle possible errors
        if handle_process_error(error, 'Nimble Update Failed', 'Nimble'):
            yield

        # Write output
        self.write_to_output(stdout, window, view)

        if process.poll() == 0:
            sublime.status_message('Nimble Package List Updated')
        else:
            sublime.status_message('Nimble Update Failed')

        yield
예제 #6
0
    def run(self, *args, **varargs):
        this = yield
        window = sublime.active_window()
        view = window.active_view()
        view_name = os.path.split(view.file_name() or view.name())[1]

        frames = ['Running Nim Check' + f for f in busy_frames]
        stop_status_loop = loop_status_msg(frames, 0.15)

        # Save view text
        if view.is_dirty():
            view.run_command('save')

        # Run 'nim check' on the current view and retrieve the output.
        # project_file = get_nim_project(window, view) or view.file_name()
        process, stdout, stderr, error = yield run_nimcheck(
            view.file_name(), this.send, self.verbosity)
        yield stop_status_loop(get_next_method(this))

        if handle_process_error(error, 'Nim Check Failed', 'Nim'):
            yield

        messages = parse_nimcheck_output(stdout)
        sublime.status_message('Nim Check Finished.')

        self.highlight_and_list_messages(messages, window, view)

        if self.send_output:
            if self.raw_output:
                content = stdout
            else:
                gen = (m[5] for m in messages if view_name == m[0])
                content = '\n'.join(gen)
            self.write_to_output(content, window, view)
        yield
예제 #7
0
    def run(self, *args, **varargs):
        this = yield
        window = sublime.active_window()
        view = window.active_view()

        # Retrieve user input
        initial_text = ''
        if self.remember_input:
            initial_text = self.last_entry

        path = yield window.show_input_panel(
            "File to check?", initial_text, this.send, None, None
        )
        self.last_entry = path

        if not os.path.isfile(path):
            sublime.error_message(
                "File '{0}' does not exist, or isn't a file.".format(path)
            )
            yield

        # Run 'nim check' on the external file.
        frames = ['Checking External File' + f for f in busy_frames]
        stop_status_loop = loop_status_msg(frames, 0.25)

        process, stdout, stderr, error = yield run_nimcheck(
            path, this.send, self.verbosity
        )
        yield stop_status_loop(get_next_method(this))

        if handle_process_error(error, "Nim Check Failed", "Nim"):
            yield

        # Prepare output
        error_list = parse_nimcheck_output(stdout)
        error_output = '\n'.join(
            [error[5] for error in error_list]
        )

        # Stop the status loop
        sublime.status_message("External File Checked.")

        # Print to the output view
        if self.send_output or True:
            self.write_to_output(error_output, window, view)

        yield
예제 #8
0
파일: nimcheck.py 프로젝트: jdah/NimLime
    def run(self, *args, **varargs):
        this = yield
        window = sublime.active_window()
        view = window.active_view()

        # Retrieve user input
        initial_text = ''
        if self.remember_input:
            initial_text = self.last_entry

        path = yield window.show_input_panel(
            'File to check?', initial_text, this.send, None, None
        )
        self.last_entry = path

        if not os.path.isfile(path):
            sublime.error_message(
                'File \'{0}\' does not exist, or isn\'t a file.'.format(path)
            )
            yield

        # Run 'nim check' on the external file.
        frames = ['Checking External File' + f for f in busy_frames]
        stop_status_loop = loop_status_msg(frames, 0.25)

        process, stdout, stderr, error = yield run_nimcheck(
            path, this.send, self.verbosity
        )
        yield stop_status_loop(get_next_method(this))

        if handle_process_error(error, 'Nim Check Failed', 'Nim'):
            yield

        # Prepare output
        error_list = parse_nimcheck_output(stdout)
        error_output = '\n'.join(
            [error[5] for error in error_list]
        )

        # Stop the status loop
        sublime.status_message('External File Checked.')

        # Print to the output view
        if self.send_output or True:
            self.write_to_output(error_output, window, view)

        yield
예제 #9
0
파일: nimble.py 프로젝트: tulayang/NimLime
    def run(self):
        this = yield
        window = sublime.active_window()
        view = window.active_view()

        # Get user input
        search_term = yield window.show_input_panel('Package Search Term?', '',
                                                    this.send, None, None)

        # Setup the loading notice
        frames = ['Searching Package List' + f for f in busy_frames]
        stop_status_loop = loop_status_msg(frames, 0.15)

        # Run the main command
        process, stdout, _, error = yield run_process(
            (configuration.nimble_exe, '-y', 'search', search_term),
            callback=this.send,
            timeout=self.timeout,
            stdout=subprocess.PIPE,
            stderr=subprocess.STDOUT)
        yield stop_status_loop(get_next_method(this))

        # Handle errors
        if handle_process_error(error, 'Nimble Search Failed', 'Nimble'):
            yield

        # List output
        if self.send_to_quickpanel:
            items = []
            packages = parse_package_descriptions(stdout)
            for package in packages:
                items.append([
                    package['name'],
                    package.get('description', ''),
                    package.get('url', '')
                ])
            window.show_quick_panel(items, None)

        # Show output
        self.write_to_output(stdout, window, view)

        if process.poll() == 0:
            sublime.status_message('Listing Nimble Packages')
        else:
            sublime.status_message('Nimble Package List Retrieval Failed')
        yield
예제 #10
0
파일: nimble.py 프로젝트: jdah/NimLime
    def run(self):
        this = yield
        window = sublime.active_window()
        view = window.active_view()

        # Get user input
        search_term = yield window.show_input_panel(
            'Package Search Term?', '', this.send, None, None
        )

        # Setup the loading notice
        frames = ['Searching Package List' + f for f in busy_frames]
        stop_status_loop = loop_status_msg(frames, 0.15)

        # Run the main command
        process, stdout, _, error = yield run_process(
            (configuration.nimble_exe, '-y', 'search', search_term),
            callback=this.send, timeout=self.timeout,
            stdout=subprocess.PIPE, stderr=subprocess.STDOUT
        )
        yield stop_status_loop(get_next_method(this))

        # Handle errors
        if handle_process_error(error, 'Nimble Search Failed', 'Nimble'):
            yield

        # List output
        if self.send_to_quickpanel:
            items = []
            packages = parse_package_descriptions(stdout)
            for package in packages:
                items.append([
                    package['name'],
                    package.get('description', ''),
                    package.get('url', '')
                ])
            window.show_quick_panel(items, None)

        # Show output
        self.write_to_output(stdout, window, view)

        if process.poll() == 0:
            sublime.status_message('Listing Nimble Packages')
        else:
            sublime.status_message('Nimble Package List Retrieval Failed')
        yield
예제 #11
0
    def run(self):
        this = yield
        window = sublime.active_window()
        view = window.active_view()

        # Get user input
        search_term = yield window.show_input_panel(
            "Package Search Term?", '', this.send, None, None
        )

        # Setup the loading notice
        frames = ['Searching package list' + f for f in busy_frames]
        stop_status_loop = loop_status_msg(frames, 0.15)

        # Run the main command
        process, output, error = yield run_nimble(
            (configuration.nimble_executable, '-y', 'search', search_term),
            this.send, self.timeout
        )
        return_code = process.poll()

        # Set the status to show we've finished
        yield stop_status_loop(get_next_method(this))

        # List output
        if self.send_to_quickpanel:
            items = []
            packages = parse_package_descriptions(output)
            for package in packages:
                items.append([
                    package['name'],
                    package.get('description', ''),
                    package.get('url', '')
                ])
            window.show_quick_panel(items, None)

        # Show output
        self.write_to_output(output, window, view)

        if return_code == 0:
            sublime.status_message("Listing Nimble Packages")
        else:
            sublime.status_message('Nimble Package List Retrieval Failed')
        yield
예제 #12
0
    def run(self, *args, **varargs):
        this = yield
        window = sublime.active_window()
        view = window.active_view()

        # Retrieve user input
        initial_text = ''
        if self.remember_input:
            initial_text = self.last_entry

        path = yield window.show_input_panel(
            "File to check?", initial_text, this.send, None, None
        )
        self.last_entry = path

        # Run 'nim check' on the external file.
        if os.path.isfile(path):
            frames = ['Checking external file' + f for f in busy_frames]
            stop_status_loop = loop_status_msg(frames, 0.25)

            process, output, errors = yield run_nimcheck(path, self.verbosity, this.send)

        else:
            sublime.error_message(
                "File '{0}' does not exist, or isn't a file.".format(path)
            )
            yield

        error_list = parse_nimcheck_output(output)
        # Prepare output
        error_output = '\n'.join(
            [error[5] for error in error_list]
        )

        # Stop the status loop
        yield stop_status_loop(get_next_method(this))
        sublime.status_message("External file checked.")

        # Print to the output view
        fallback_view_name = path + " - Nim Check Output"
        if self.send_output or True:
            self.write_to_output(error_output, window, view)

        yield
예제 #13
0
    def process_entries(self, window, view, output, entries):
        this = yield

        index = 0
        if len(entries) > 1:
            input_list = [
                ['{5}, {6}: {3}'.format(*e), e[4]] for e in entries
                ]
            index = yield window.show_quick_panel(input_list, this.send)
            if index == -1:
                yield

        # Open the entry file and go to the point
        entry = entries[index]
        target_view = window.open_file(entry[4])
        while target_view.is_loading():
            yield sublime.set_timeout(get_next_method(this), 100)

        target_view.show_at_center(
            target_view.text_point(int(entry[5]), int(entry[6]))
        )
예제 #14
0
    def run(self):
        this = yield
        window = sublime.active_window()
        view = window.active_view()

        nimsuggest = self.get_nimsuggest_instance(view.file_name())
        ide_params = self.get_ide_parameters(window, view)
        nim_file, dirty_file, line, column = ide_params

        output, entries = yield nimsuggest.find_definition(
            nim_file, dirty_file, line, column, this.send
        )

        # Get the correct definition entry
        index = 0

        if len(entries) == 0:
            sublime.status_message(
                'NimLime: No definition found in project files.'
            )
            yield
        elif len(entries) > 1 and not self.ask_on_multiple_results:
            input_list = [[e[5] + ', ' + e[6] + ': ' + e[3], e[4]] for e in
                          entries]
            index = yield window.show_quick_panel(input_list, this.send)
            if index == -1:
                yield

        # Open the entry file and go to the point
        entry = entries[index]
        target_view = window.open_file(entry[4])
        while target_view.is_loading():
            yield sublime.set_timeout(get_next_method(this), 1000)

        target_view.show_at_center(
            target_view.text_point(int(entry[5]), int(entry[6]))
        )

        yield
예제 #15
0
    def run(self):
        this = yield
        window = sublime.active_window()
        view = window.active_view()

        nimsuggest = self.get_nimsuggest_instance(view.file_name())
        ide_params = self.get_ide_parameters(window, view)
        nim_file, dirty_file, line, column = ide_params

        output, entries = yield nimsuggest.find_definition(
            nim_file, dirty_file, line, column, this.send
        )

        # Get the file and open it.
        if len(entries):
            # Retrieve the correct entry
            index = 0
            if len(entries) > 1:
                input_list = [
                    [e[5] + ', ' + e[6] + ': ' + e[3], e[4]] for e in entries
                    ]
                index = yield window.show_quick_panel(input_list, this.send)
                if index == -1:
                    yield

            # Open the entry file and go to the point
            entry = entries[index]
            view = window.open_file(entry[4], sublime.TRANSIENT)
            while view.is_loading():
                yield sublime.set_timeout(get_next_method(this), 1000)
            view.show_at_center(view.text_point(int(entry[5]), int(entry[6])))
        else:
            sublime.status_message("NimLime: No definition found in project "
                                   "files.")

        yield
예제 #16
0
    def run(self):
        this = yield
        window = sublime.active_window()

        # Retrieve and check the destination path for the Nimsuggest executable
        exe_output_dir = yield window.show_input_panel(
            'Path to copy nimsuggest to? (Blank for home directory)', '',
            this.send, None, None
        )

        exe_output_dir = exe_output_dir or os.path.expanduser('~')
        debug_print('exe_dir: ', exe_output_dir)

        if not (os.path.exists(exe_output_dir) or not os.path.isdir(
            exe_output_dir)):
            sublime.error_message('Invalid path for nimsuggest executable.')
            yield

        # Signal that we are compiling Nimsuggest
        frames = ['Compiling Internal Nimsuggest' + f for f in busy_frames]
        stop_status_loop = loop_status_msg(frames, 0.15)

        # Generate the paths needed to extract and compile Nimsuggest
        temp_dir = mkdtemp()
        nimsuggest_source_dir = os.path.join(temp_dir, 'nimsuggest')
        nimlime_dir = os.path.dirname(NimLime.__file__)
        exe_output_file = os.path.join(exe_output_dir, 'nimsuggest')

        if configuration.on_windows:
            exe_output_file += '.exe'

        debug_print('temp_dir: ', temp_dir)
        debug_print('nimlime_dir: ', nimlime_dir)
        debug_print('exe_output_file: ', exe_output_file)

        # Extract the Nimsuggest source
        if configuration.is_zipped:
            # We're in a zipped package, so we need to extract the tarball
            # from our package file, then extract the tarball
            debug_print('Extracting nimsuggest tarball to temp_dir')
            ZipFile(nimlime_dir).extractall(temp_dir)
        else:
            # We're an actual directory, so we just need to copy the source
            # tree to the temp directory.
            debug_print('Copying nimsuggest source to', temp_dir)
            copytree(
                os.path.join(nimlime_dir, 'nimsuggest'),
                nimsuggest_source_dir
            )

        # Compile the nimsuggest source
        debug_print('Compiling with Nim exe: ', configuration.nim_exe)
        process, stdout, _, error = yield run_process(
            [configuration.nim_exe, 'c', '--out:' + exe_output_file,
             '-d:release',
             'nimsuggest.nim'],
            cwd=nimsuggest_source_dir, callback=this.send,
            stdout=subprocess.PIPE, stderr=subprocess.STDOUT
        )
        yield stop_status_loop(get_next_method(this))

        # Handle possible errors
        if handle_process_error(error, 'Nimsuggest setup failed', 'Nim'):
            yield
        elif process.poll() != 0:
            sublime.error_message(setup_error_msg)
            debug_print('Compilation unsuccessful.')
            print(stdout)
            yield

        # Tell the user the process was successful, and remind them
        # to set the nimsuggest settings.
        sublime.status_message('Nimsuggest compiled and copied.')
        sublime.run_command('open_file', {
            'file': '${packages}/User/NimLime/NimLime.sublime-settings'
        })
        sublime.message_dialog(
            'Please make sure to set the \'nimsuggest.executable\' setting!'
        )
        start_file(exe_output_dir)
        yield
예제 #17
0
    def run(self):
        this = yield
        window = sublime.active_window()
        view = window.active_view()

        if self.preemptive_search:
            # Get user input
            search_term = yield window.show_input_panel(
                "Package to install?", '', this.send, None, None
            )

            loading_notice = 'Searching package list'
            process_args = (
                configuration.nimble_executable, '-y', 'search',
                escape_shell(search_term)
            )
        else:
            loading_notice = 'Loading package list'
            process_args = (configuration.nimble_executable, '-y', 'list ')

        # Setup the loading notice
        frames = [loading_notice + f for f in busy_frames]
        stop_status_loop = loop_status_msg(frames, 0.15)

        # Run the search/list command
        process, output, errors = run_process(
            process_args, this.send, self.timeout
        )
        return_code = process.poll()

        # Set the status to show we've finished searching
        yield stop_status_loop(get_next_method(this))

        if return_code != 0:
            sublime.status_message("Nimble Package Load Failed")
        else:
            items = []
            packages = parse_package_descriptions(output)

            if len(packages) == 0:
                sublime.status_message("No Matching Packages Found")
            else:
                for package in packages:
                    items.append([
                        package['name'],
                        package.get('description', ''),
                        package.get('url', '')
                    ])

                selection = yield window.show_quick_panel(items, this.send)

                if selection != -1:
                    target_name = items[selection][0]

                    # Setup the loading notice
                    loading_notice = "Installing package"
                    frames = [loading_notice + f for f in busy_frames]
                    stop_status_loop = loop_status_msg(frames, 0.15)

                    # Run the install command
                    process, output, errors = run_process(
                        [configuration.nimble_executable, '-y', 'install',
                         escape_shell(target_name)], this.send, self.timeout
                    )

                    # Stop the status notice
                    yield stop_status_loop(get_next_method(this))

                    self.write_to_output(output, window, view)
                    if return_code == 0:
                        sublime.status_message("Installed Nimble Package")
                    else:
                        sublime.status_message(
                            'Nimble Package Installation Failed'
                        )
        yield
예제 #18
0
파일: nimble.py 프로젝트: jdah/NimLime
    def run(self):
        this = yield
        window = sublime.active_window()
        view = window.active_view()

        # Setup the loading notice
        frames = ['Loading package list' + f for f in busy_frames]
        stop_status_loop = loop_status_msg(frames, 0.15)

        # Run the search/list command
        process, stdout, stderr, error = yield run_process(
            [configuration.nimble_exe, '-y', 'list', '-i'],
            this.send, self.timeout
        )
        yield stop_status_loop(get_next_method(this))

        # Handle errors
        if handle_process_error(error, 'Nimble Package Uninstall Failed',
                                'Nimble'):
            yield
        elif process.poll() != 0:
            sublime.status_message('Nimble Installed Package Listing Failed')
            yield

        # Parse the package descriptions
        packages = parse_package_descriptions(stdout)
        if len(packages) == 0:
            sublime.status_message('No Installed Packages Found')
            yield

        items = []
        for package in packages:
            items.append([
                package['name'],
                package.get('description', ''),
                package.get('url', '')
            ])

        # Display packages and retrieve the selection
        selection = yield window.show_quick_panel(items, this.send)
        if selection == -1:
            yield

        target_name = items[selection][0]

        # Setup the loading notice
        frames = ['Uninstalling Package' + f for f in busy_frames]
        stop_status_loop = loop_status_msg(frames, 0.15)

        # Run the install command
        process, stdout, stderr, error = yield run_process(
            [configuration.nimble_exe, '-y', 'uninstall',
             target_name],
            this.send, self.timeout
        )
        yield stop_status_loop(get_next_method(this))

        # Handle errors
        if handle_process_error(error, 'Nimble Package Uninstallation Failed',
                                'Nimble'):
            yield

        # Write output
        self.write_to_output(stdout, window, view)

        if process.poll() == 0:
            sublime.status_message('Uninstalled Nimble Package')
        else:
            sublime.status_message(
                'Nimble Package Uninstallation Failed')
        yield
예제 #19
0
파일: nimble.py 프로젝트: jdah/NimLime
    def run(self):
        this = yield
        window = sublime.active_window()
        view = window.active_view()

        if self.preemptive_search:
            # Get user input
            search_term = yield window.show_input_panel(
                'Package to install?', '', this.send, None, None
            )

            loading_notice = 'Searching Package List'
            process_args = (
                configuration.nimble_exe, '-y', 'search',
                escape_shell(search_term)
            )
        else:
            loading_notice = 'Loading Package List'
            process_args = (configuration.nimble_exe, '-y', 'list ')

        # Setup the loading notice
        frames = [loading_notice + f for f in busy_frames]
        stop_status_loop = loop_status_msg(frames, 0.15)

        # Run the search/list command
        process, stdout, _, error = yield run_process(
            process_args, callback=this.send, timeout=self.timeout
        )
        stop_status_loop(get_next_method(this))

        # Handle errors
        if handle_process_error(error, 'Loading Nimble Packages Failed',
                                'Nimble'):
            yield

        if process.poll() != 0:
            sublime.status_message('Nimble Package Load Failed')
            yield

        # Parse the package list
        items = []
        packages = parse_package_descriptions(stdout)

        if len(packages) == 0:
            sublime.status_message('No Matching Packages Found')
            yield

        # Display the list and get the selected package.
        for package in packages:
            items.append([
                package['name'],
                package.get('description', ''),
                package.get('url', '')
            ])

        selection = yield window.show_quick_panel(items, this.send)
        if selection == -1:
            yield
        target_name = items[selection][0]

        # Setup the loading notice
        frames = ['Installing Package' + f for f in busy_frames]
        stop_status_loop = loop_status_msg(frames, 0.15)

        # Run the install command
        process, stdout, _, error = yield run_process(
            [configuration.nimble_exe, '-y', 'install',
             escape_shell(target_name)], this.send, self.timeout
        )
        yield stop_status_loop(get_next_method(this))

        if handle_process_error(error, 'Nimble Package Install Failed',
                                'Nimble'):
            yield

        self.write_to_output(stdout, window, view)
        if process.poll() == 0:
            sublime.status_message('Installed Nimble Package')
        else:
            sublime.status_message('Nimble Package Installation Failed')
        yield
예제 #20
0
    def run(self):
        window = sublime.active_window()
        view = window.active_view()

        this = yield

        # Setup the loading notice
        frames = ['Loading package list' + f for f in busy_frames]
        stop_status_loop = loop_status_msg(frames, 0.15)

        # Run the search/list command
        process, output, errors = run_process(
            [configuration.nimble_executable, '-y', 'list', '-i'],
            this.send, self.timeout
        )
        return_code = process.poll()

        # Set the status to show we've finished searching
        yield stop_status_loop(get_next_method(this))

        if return_code != 0:
            sublime.status_message(
                "Nimble Installed Package Listing Failed")
        else:
            items = []
            packages = parse_package_descriptions(output)

            if len(packages) == 0:
                sublime.status_message("No Installed Packages Found")
            else:
                for package in packages:
                    items.append([
                        package['name'],
                        package.get('description', ''),
                        package.get('url', '')
                    ])

                selection = yield window.show_quick_panel(items, this.send)

                if selection != -1:
                    target_name = items[selection][0]
                    # Setup the loading notice
                    loading_notice = "Uninstalling package"
                    frames = [loading_notice + f for f in busy_frames]
                    stop_status_loop = loop_status_msg(frames, 0.15)

                    # Run the install command
                    process, output, errors = run_process(
                        [configuration.nimble_executable, '-y', 'uninstall'],
                        this.send, self.timeout
                    )
                    return_code = process.poll()

                    yield stop_status_loop(get_next_method(this))

                    self.write_to_output(output, window, view)
                    if return_code == 0:
                        sublime.status_message(
                            "Uninstalled Nimble Package")
                    else:
                        sublime.status_message(
                            'Nimble Package Uninstallation Failed'
                        )
        yield
예제 #21
0
파일: nimble.py 프로젝트: tulayang/NimLime
    def run(self):
        this = yield
        window = sublime.active_window()
        view = window.active_view()

        if self.preemptive_search:
            # Get user input
            search_term = yield window.show_input_panel(
                'Package to install?', '', this.send, None, None)

            loading_notice = 'Searching Package List'
            process_args = (configuration.nimble_exe, '-y', 'search',
                            escape_shell(search_term))
        else:
            loading_notice = 'Loading Package List'
            process_args = (configuration.nimble_exe, '-y', 'list ')

        # Setup the loading notice
        frames = [loading_notice + f for f in busy_frames]
        stop_status_loop = loop_status_msg(frames, 0.15)

        # Run the search/list command
        process, stdout, _, error = yield run_process(process_args,
                                                      callback=this.send,
                                                      timeout=self.timeout)
        stop_status_loop(get_next_method(this))

        # Handle errors
        if handle_process_error(error, 'Loading Nimble Packages Failed',
                                'Nimble'):
            yield

        if process.poll() != 0:
            sublime.status_message('Nimble Package Load Failed')
            yield

        # Parse the package list
        items = []
        packages = parse_package_descriptions(stdout)

        if len(packages) == 0:
            sublime.status_message('No Matching Packages Found')
            yield

        # Display the list and get the selected package.
        for package in packages:
            items.append([
                package['name'],
                package.get('description', ''),
                package.get('url', '')
            ])

        selection = yield window.show_quick_panel(items, this.send)
        if selection == -1:
            yield
        target_name = items[selection][0]

        # Setup the loading notice
        frames = ['Installing Package' + f for f in busy_frames]
        stop_status_loop = loop_status_msg(frames, 0.15)

        # Run the install command
        process, stdout, _, error = yield run_process([
            configuration.nimble_exe, '-y', 'install',
            escape_shell(target_name)
        ], this.send, self.timeout)
        yield stop_status_loop(get_next_method(this))

        if handle_process_error(error, 'Nimble Package Install Failed',
                                'Nimble'):
            yield

        self.write_to_output(stdout, window, view)
        if process.poll() == 0:
            sublime.status_message('Installed Nimble Package')
        else:
            sublime.status_message('Nimble Package Installation Failed')
        yield
예제 #22
0
파일: nimble.py 프로젝트: tulayang/NimLime
    def run(self):
        this = yield
        window = sublime.active_window()
        view = window.active_view()

        # Setup the loading notice
        frames = ['Loading package list' + f for f in busy_frames]
        stop_status_loop = loop_status_msg(frames, 0.15)

        # Run the search/list command
        process, stdout, stderr, error = yield run_process(
            [configuration.nimble_exe, '-y', 'list', '-i'], this.send,
            self.timeout)
        yield stop_status_loop(get_next_method(this))

        # Handle errors
        if handle_process_error(error, 'Nimble Package Uninstall Failed',
                                'Nimble'):
            yield
        elif process.poll() != 0:
            sublime.status_message('Nimble Installed Package Listing Failed')
            yield

        # Parse the package descriptions
        packages = parse_package_descriptions(stdout)
        if len(packages) == 0:
            sublime.status_message('No Installed Packages Found')
            yield

        items = []
        for package in packages:
            items.append([
                package['name'],
                package.get('description', ''),
                package.get('url', '')
            ])

        # Display packages and retrieve the selection
        selection = yield window.show_quick_panel(items, this.send)
        if selection == -1:
            yield

        target_name = items[selection][0]

        # Setup the loading notice
        frames = ['Uninstalling Package' + f for f in busy_frames]
        stop_status_loop = loop_status_msg(frames, 0.15)

        # Run the install command
        process, stdout, stderr, error = yield run_process(
            [configuration.nimble_exe, '-y', 'uninstall', target_name],
            this.send, self.timeout)
        yield stop_status_loop(get_next_method(this))

        # Handle errors
        if handle_process_error(error, 'Nimble Package Uninstallation Failed',
                                'Nimble'):
            yield

        # Write output
        self.write_to_output(stdout, window, view)

        if process.poll() == 0:
            sublime.status_message('Uninstalled Nimble Package')
        else:
            sublime.status_message('Nimble Package Uninstallation Failed')
        yield
예제 #23
0
    def run(self):
        this = yield
        window = sublime.active_window()

        # Retrieve and check the destination path for the Nimsuggest executable
        exe_output_dir = yield window.show_input_panel(
            'Path to copy nimsuggest to? (Blank for home directory)', '',
            this.send, None, None
        )

        exe_output_dir = exe_output_dir or os.path.expanduser('~')
        debug_print('exe_dir: ', exe_output_dir)

        if not (os.path.exists(exe_output_dir) or not os.path.isdir(
            exe_output_dir)):
            sublime.error_message('Invalid path for nimsuggest executable.')
            yield

        # Signal that we are compiling Nimsuggest
        frames = ['Compiling Internal Nimsuggest' + f for f in busy_frames]
        stop_status_loop = loop_status_msg(frames, 0.15)

        # Generate the paths needed to extract and compile Nimsuggest
        temp_dir = mkdtemp()
        nimsuggest_source_dir = os.path.join(temp_dir, 'nimsuggest')
        nimlime_dir = os.path.dirname(NimLime.__file__)
        exe_output_file = os.path.join(exe_output_dir, 'nimsuggest')

        if configuration.on_windows:
            exe_output_file += '.exe'

        debug_print('temp_dir: ', temp_dir)
        debug_print('nimlime_dir: ', nimlime_dir)
        debug_print('exe_output_file: ', exe_output_file)

        # Extract the Nimsuggest source
        if configuration.is_zipped:
            # We're in a zipped package, so we need to extract the tarball
            # from our package file, then extract the tarball
            debug_print('Extracting nimsuggest tarball to temp_dir')
            ZipFile(nimlime_dir).extractall(temp_dir)
        else:
            # We're an actual directory, so we just need to copy the source
            # tree to the temp directory.
            debug_print('Copying nimsuggest source to', temp_dir)
            copytree(
                os.path.join(nimlime_dir, 'nimsuggest'),
                nimsuggest_source_dir
            )

        # Compile the nimsuggest source
        debug_print('Compiling with Nim exe: ', configuration.nim_exe)
        process, stdout, _, error = yield run_process(
            [configuration.nim_exe, 'c', '--out:' + exe_output_file,
             '-d:release',
             'nimsuggest.nim'],
            cwd=nimsuggest_source_dir, callback=this.send,
            stdout=subprocess.PIPE, stderr=subprocess.STDOUT
        )
        yield stop_status_loop(get_next_method(this))

        # Handle possible errors
        if handle_process_error(error, 'Nimsuggest setup failed', 'Nim'):
            yield
        elif process.poll() != 0:
            sublime.error_message(setup_error_msg)
            debug_print('Compilation unsuccessful.')
            print(stdout)
            yield

        # Tell the user the process was successful, and remind them
        # to set the nimsuggest settings.
        sublime.status_message('Nimsuggest compiled and copied.')
        sublime.run_command('open_file', {
            'file': '${packages}/User/NimLime/NimLime.sublime-settings'
        })
        sublime.message_dialog(
            'Please make sure to set the \'nimsuggest.executable\' setting!'
        )
        start_file(exe_output_dir)
        yield