示例#1
0
    def run(self, edit):
        try:
            code = self.view.substr(sublime.Region(0, self.view.size()))
            row, col = self.view.rowcol(self.view.sel()[0].begin())
            racer = get_settings(self.view, 'racer_binary_path', 'racer')
            if racer == '':
                racer = 'racer'

            data = {
                'vid': self.view.id(),
                'filename': self.view.file_name(),
                'settings': {
                    'racer_binary_path': racer,
                    'rust_src_path': get_settings(self.view, 'rust_src_path'),
                    'row': row,
                    'col': col,
                    'source': code
                },
                'method': 'goto',
                'handler': 'racer'
            }
            Worker().execute(
                Callback(on_success=partial(JediUsages(self).process, False),
                         on_failure=self._on_failure,
                         on_timeout=self._on_timeout), **data)
        except:
            pass
示例#2
0
def run_linter(view=None):
    """Run the linter for the given view
    """

    if view is None:
        view = active_view()

    if not get_settings(view, 'anaconda_rust_linting', False):
        return

    if view.file_name() in anaconda_sublime.ANACONDA['DISABLED']:
        anaconda_sublime.erase_lint_marks(view)
        return

    rustc = get_settings(view, 'rustc_binary_path', 'rustc')
    if rustc == '':
        rustc = 'rustc'

    data = {
        'vid': view.id(),
        'code': '',
        'settings': {'rustc_binary_path': rustc},
        'filename': view.file_name(),
        'method': 'lint',
        'handler': 'rust_linter'
    }

    callback = partial(anaconda_sublime.parse_results, **dict(code='rust'))
    Worker().execute(Callback(on_success=callback), **data)
示例#3
0
    def run(self, edit):
        if self.documentation is not None:
            return self.print_doc(edit)

        try:
            code = self.view.substr(sublime.Region(0, self.view.size()))
            row, col = self.view.rowcol(self.view.sel()[0].begin())
            racer = get_settings(self.view, 'racer_binary_path', 'racer')
            if racer == '':
                racer = 'racer'

            data = {
                'vid': self.view.id(),
                'filename': self.view.file_name(),
                'settings': {
                    'racer_binary_path': racer,
                    'rust_src_path': get_settings(self.view, 'rust_src_path'),
                    'row': row,
                    'col': col,
                    'source': code
                },
                'method': 'doc',
                'handler': 'racer'
            }

            Worker().execute(
                Callback(on_success=self.prepare_data,
                         on_failure=self._on_failure,
                         on_timeout=self._on_timeout), **data)
        except Exception as error:
            print(error)
示例#4
0
    def run(self, edit):

        if self.data is not None:
            self.update_buffer(edit)
            return

        try:
            messages = {
                'start': 'Auto formatting file...',
                'end': 'done!',
                'fail': 'The auto formatting failed!',
                'timeout': 'The auto formatiing timed out!'
            }
            self.pbar = ProgressBar(messages)
            self.pbar.start()
            self.view.set_read_only(True)

            rustfmt = get_settings(self.view, 'rustfmt_binary_path', 'rustfmt')
            if rustfmt == '':
                rustfmt = 'rustfmt'

            self.code = self.view.substr(sublime.Region(0, self.view.size()))

            # the JonServer deletes the temp file so we don't worry
            fd, path = tempfile.mkstemp(suffix=".rs", dir=file_directory())
            try:
                with os.fdopen(fd, "wb") as tmp:
                    tmp.write(self.code.encode('utf-8'))
            except Exception as e:
                self.clean_tmp_file(path)
                raise e

            config_path = get_settings(self.view, 'rust_rustfmt_config_path')
            if config_path is None or config_path == '':
                config_path = self._get_working_directory()

            data = {
                'vid': self.view.id(),
                'filename': path,
                'settings': {
                    'rustfmt_binary_path': rustfmt,
                    'config_path': config_path
                },
                'method': 'format',
                'handler': 'rustfmt'
            }
            timeout = get_settings(self.view, 'rust_rustfmt_timeout', 1)

            callback = Callback(timeout=timeout)
            callback.on(success=self.prepare_data)
            callback.on(error=self.on_failure)
            callback.on(timeout=partial(self.clean_tmp_file, path))

            Worker().execute(callback, **data)
        except:
            logging.error(traceback.format_exc())
示例#5
0
    def run(self, edit):

        if self.data is not None:
            self.update_buffer(edit)
            return

        try:
            messages = {
                'start': 'Auto formatting file...',
                'end': 'done!',
                'fail': 'The auto formatting failed!',
                'timeout': 'The auto formatiing timed out!'
            }
            self.pbar = ProgressBar(messages)
            self.pbar.start()
            self.view.set_read_only(True)

            rustfmt = get_settings(
                self.view, 'rustfmt_binary_path', 'rustfmt'
            )
            if rustfmt == '':
                rustfmt = 'rustfmt'

            self.code = self.view.substr(
                sublime.Region(0, self.view.size())
            )

            # the JonServer deletes the temp file so we don't worry
            fd, path = tempfile.mkstemp(suffix=".rs", dir=file_directory())
            with os.fdopen(fd, "w", encoding="utf-8") as tmp:
                tmp.write(self.code)

            config_path = get_settings(self.view, 'rust_rustfmt_config_path', '')

            data = {
                'vid': self.view.id(),
                'filename': path,
                'settings': {
                    'rustfmt_binary_path': rustfmt,
                    'config_path': config_path
                },
                'method': 'format',
                'handler': 'rustfmt'
            }
            timeout = get_settings(self.view, 'rust_rustfmt_timeout', 1)

            callback = Callback(timeout=timeout)
            callback.on(success=self.prepare_data)
            callback.on(error=self.on_failure)
            callback.on(timeout=partial(self.clean_tmp_file, path))

            Worker().execute(callback, **data)
        except:
            logging.error(traceback.format_exc())
示例#6
0
    def on_query_completions(self, view, prefix, locations):
        """Sublime Text autocompletion event handler
        """

        if not is_code(view, lang='rust'):
            return

        if self.ready_from_defer is True:
            completion_flags = 0

            if ags(view, 'suppress_word_completions', False):
                completion_flags = sublime.INHIBIT_WORD_COMPLETIONS

            if ags(view, 'suppress_explicit_completions', False):
                completion_flags = sublime.INHIBIT_EXPLICIT_COMPLETIONS

            cpl = self.completions
            self.completions = []
            self.ready_from_defer = False

            return (cpl, completion_flags)

        code = view.substr(sublime.Region(0, view.size()))
        row, col = view.rowcol(locations[0])
        racer = get_settings(view, 'racer_binary_path', 'racer')
        if racer == '':
            racer = 'racer'

        data = {
            'vid': view.id(),
            'filename': view.file_name(),
            'settings': {
                'racer_binary_path': racer,
                'rust_src_path': get_settings(view, 'rust_src_path'),
                'row': row,
                'col': col,
                'source': code,
            },
            'method': 'autocomplete',
            'handler': 'racer'
        }
        Worker().execute(
            Callback(
                on_success=self._complete,
                on_failure=self._on_failure,
                on_timeout=self._on_timeout
            ),
            **data
        )