Пример #1
0
    def is_enabled(self):
        """Determine if this command is enabled or not
        """

        if not go.ANAGONDA_PRESENT:
            return False

        return is_code(self.view, lang='go')
Пример #2
0
    def is_enabled(self) -> bool:
        """Determine if this command is enabled or not
        """

        if not go.ANAGONDA_PRESENT:
            return False

        return is_code(self.view, lang='go', ignore_comments=True)
Пример #3
0
    def is_enabled(self):
        """Determine if this command is enabled or not
        """

        if not go.ANAGONDA_PRESENT:
            return False

        return is_code(self.view, lang='go')
Пример #4
0
    def on_query_completions(self, view, prefix, locations):
        """Fired directly from Sublime Text 3 events systems
        """

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

        if not go.ANAGONDA_PRESENT:
            if go.AVAILABLE:
                go.init()
            else:
                return

        if self.ready_from_defer is True:
            completion_flags = 0

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

            if get_settings(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])
        data = {
            'vid':
            view.id(),
            'path':
            view.file_name(),
            'code':
            code,
            'offset':
            view.text_point(row, col),
            'add_params':
            get_settings(view, 'anaconda_go_add_completion_params', True),
            'go_env': {
                'GOROOT': go.GOROOT,
                'GOPATH': go.GOPATH,
                'CGO_ENABLED': go.CGO_ENABLED
            },
            'method':
            'autocomplete',
            'handler':
            'anaGonda'
        }
        Worker.execute(
            Callback(on_success=self._complete,
                     on_failure=self._on_failure,
                     on_timeout=self._on_timeout), **data)
Пример #5
0
    def is_enabled(self) -> bool:
        """Determine if this command is enabled or not
        """

        if len(sublime.active_window().views()) == 0:
            return False

        if not go.ANAGONDA_PRESENT:
            return False

        return is_code(self.window.active_view(), lang='go')
Пример #6
0
    def is_enabled(self) -> bool:
        """Determine if this command is enabled or not
        """

        if len(sublime.active_window().views()) == 0:
            return False

        if not go.ANAGONDA_PRESENT:
            return False

        return is_code(self.window.active_view(), lang='go')
Пример #7
0
    def on_query_completions(self, view, prefix, locations):
        """Fired directly from Sublime Text 3 events systems
        """

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

        if not go.ANAGONDA_PRESENT:
            if go.AVAILABLE:
                go.init()
            else:
                return

        if self.ready_from_defer is True:
            completion_flags = 0

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

            if get_settings(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])
        data = {
            'vid': view.id(),
            'path': view.file_name(),
            'code': code,
            'offset': view.text_point(row, col),
            'add_params': get_settings(
                view, 'anaconda_go_add_completion_params', True),
            'go_env': {
                'GOROOT': go.GOROOT,
                'GOPATH': go.GOPATH,
                'CGO_ENABLED': go.CGO_ENABLED
            },
            'method': 'autocomplete',
            'handler': 'anaGonda'
        }
        Worker.execute(
            Callback(
                on_success=self._complete,
                on_failure=self._on_failure,
                on_timeout=self._on_timeout
            ),
            **data
        )
Пример #8
0
    def on_pre_save(self, view: sublime_plugin.sublime.View) -> None:
        """Called just before the file is going to be saved
        """

        if time.time() - self._last_save < 2:
            return

        auto_format = get_settings(view, 'anaconda_go_auto_format', False)
        if auto_format and is_code(view, lang='go'):
            view.run_command('anaconda_go_format')

        self._last_save = time.time()
    def on_pre_save(self, view: sublime_plugin.sublime.View) -> None:
        """Called just before the file is going to be saved
        """

        if time.time() - self._last_save < 2:
            return

        auto_format = get_settings(view, 'anaconda_go_auto_format', False)
        if auto_format and is_code(view, lang='go'):
            filename = os.path.join(tempfile.gettempdir(), view.file_name())
            buf = view.substr(sublime.Region(0, view.size()))
            self._save_tmp_buffer(buf, filename)
            view.run_command('anaconda_go_format_sync',
                             args={"path": filename})
            self._remove_tmp_buffer(filename)

        AnacondaGoAutoFormatEventListener._last_save = time.time()
Пример #10
0
    def on_pre_save(self, view: sublime_plugin.sublime.View) -> None:
        """Called just before the file is going to be saved
        """

        if time.time() - self._last_save < 2:
            return

        auto_format = get_settings(view, 'anaconda_go_auto_format', False)
        if auto_format and is_code(view, lang='go'):
            filename = os.path.join(tempfile.gettempdir(), view.file_name())
            buf = view.substr(sublime.Region(0, view.size()))
            self._save_tmp_buffer(buf, filename)
            view.run_command(
                'anaconda_go_format_sync', args={"path": filename}
            )
            self._remove_tmp_buffer(filename)

        AnacondaGoAutoFormatEventListener._last_save = time.time()