Esempio n. 1
0
def slow_linters(view=None, hook=None):
    """Run slow gometalinter linters
    """

    if view is None:
        view = active_view()

    if not get_settings(view, 'anaconda_go_linting', True):
        return

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

    settings = _get_settings(view)

    data = {
        'vid': view.id(),
        'code': view.substr(st3_sublime.Region(0, view.size())),
        'settings': settings,
        'filepath': view.file_name(),
        'method': 'slow_lint',
        'handler': 'anaGonda',
        'go_env': {
            'GOROOT': go.GOROOT,
            'GOPATH': go.GOPATH,
            'CGO_ENABLED': go.CGO_ENABLED
        }
    }

    callback = partial(anaconda_sublime.parse_results, **dict(code='go'))
    if hook is None:
        Worker().execute(Callback(on_success=callback), **data)
    else:
        Worker().execute(Callback(partial(hook, callback)), **data)
Esempio n. 2
0
 def run(self, operation='analyze') -> None:
     self.operation = operation
     try:
         view = self.window.active_view()
         self.view = view
         scope = get_settings(view, 'anaconda_go_guru_scope')
         data = {
             'vid': self.view.id(),
             'scope': scope if scope is not None else get_scope(
                 view, go.GOPATH),  # noqa
             'code': view.substr(sublime.Region(0, view.size())),
             'offset': view.text_point(*view.rowcol(view.sel()[0].begin())),
             'path': view.file_name(),
             'buf': self.modified_buffer(view),
             'mode': self.operation,
             'go_env': {
                 'GOROOT': go.GOROOT,
                 'GOPATH': go.GOPATH,
                 'CGO_ENABLED': go.CGO_ENABLED
             },
             'method': 'analyze_symbol',
             'handler': 'anaGonda'
         }
         Worker().execute(
             Callback(on_success=self.on_success,
                      on_failure=self._on_failure,
                      on_timeout=self._on_timeout), **data)
     except Exception as err:
         print('anaconda_go: {}'.format(self.method.replace('_', '')))
         print(err)
Esempio n. 3
0
    def run(self, edit):

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

        try:
            self.code = self.view.substr(sublime.Region(0, self.view.size()))
            data = {
                'vid': self.view.id(),
                'code': self.code,
                'path': self.view.file_name(),
                'go_env': {
                    'GOROOT': go.GOROOT,
                    'GOPATH': go.GOPATH,
                    'CGO_ENABLED': go.CGO_ENABLED
                },
                'method': 'goimports',
                'handler': 'anaGonda'
            }
            Worker().execute(
                Callback(on_success=self.prepare_data,
                         on_failure=self.on_failure,
                         on_timeout=self.on_timeout), **data)
        except Exception as error:
            logging.error(error)
            logging.debug(traceback.format_exc())
Esempio n. 4
0
    def run(self, edit: sublime.Edit) -> None:
        try:
            view = self.view
            scope = get_settings(view, 'anaconda_go_guru_scope')
            row, col = view.rowcol(view.sel()[0].begin())
            offset = view.text_point(row, col)
            code = view.substr(sublime.Region(0, view.size()))

            data = {
                'vid': view.id(),
                'scope': scope if scope is not None else get_scope(view, go.GOPATH),  # noqa
                'path': view.file_name(),
                'offset': offset,
                'modified_buffer': self._modified_buffer(view, code),
                'go_env': {
                    'GOROOT': go.GOROOT,
                    'GOPATH': go.GOPATH,
                    'CGO_ENABLED': go.CGO_ENABLED
                },
                'method': 'callstack',
                'handler': 'anaGonda'
            }
            Worker().execute(
                Callback(
                    on_success=self._on_success,
                    on_failure=self._on_failure,
                    on_timeout=self._on_timeout
                ),
                **data
            )
        except:
            print('anaconda_go: callers error')
            print(traceback.print_exc())
Esempio n. 5
0
 def run(self) -> None:
     try:
         view = self.window.active_view()
         self.view = view
         scope = get_settings(view, 'anaconda_go_guru_scope')
         data = {
             'vid': view.id(),
             'scope': scope if scope is not None else get_scope(
                 view, go.GOPATH),  # noqa
             'code': view.substr(sublime.Region(0, view.size())),
             'path': view.file_name(),
             'buf': self.modified_buffer(view),
             'go_env': {
                 'GOROOT': go.GOROOT,
                 'GOPATH': go.GOPATH,
                 'CGO_ENABLED': go.CGO_ENABLED
             },
             'method': 'get_package_decls',
             'handler': 'anaGonda'
         }
         Worker().execute(
             Callback(on_success=ExplorerPanel(view).run,
                      on_failure=self._on_failure,
                      on_timeout=self._on_timeout), **data)
     except Exception as err:
         print('anaconda_go: {}'.format(self.method.replace('_', ' ')))
         print(err)
Esempio n. 6
0
 def run(self) -> None:
     try:
         view = self.window.active_view()
         self.view = view
         data = {
             'vid':
             view.id(),
             'file_path':
             view.file_name(),
             'parse_comments':
             get_settings(view, 'anaconda_go_motion_parse_comments', False),
             'go_env': {
                 'GOROOT': go.GOROOT,
                 'GOPATH': go.GOPATH,
                 'CGO_ENABLED': go.CGO_ENABLED
             },
             'method':
             self.method,
             'handler':
             'anaGonda'
         }
         Worker().execute(
             Callback(on_success=ExplorerPanel(view).run,
                      on_failure=self._on_failure,
                      on_timeout=self._on_timeout), **data)
     except Exception as err:
         print('anaconda_go: {}'.format(self.method.replace('_', ' ')))
         print(err)
Esempio n. 7
0
 def run(self) -> None:
     try:
         view = self.window.active_view()
         self.view = view
         data = {
             'vid':
             view.id(),
             'file_path':
             view.file_name(),
             'offset':
             view.sel()[0].begin(),
             'parse_comments':
             get_settings(view, 'anaconda_go_motion_parse_comments', False),
             'go_env': {
                 'GOROOT': go.GOROOT,
                 'GOPATH': go.GOPATH,
                 'CGO_ENABLED': go.CGO_ENABLED
             },
             'method':
             'enclosing',
             'handler':
             'anaGonda'
         }
         Worker().execute(
             Callback(on_success=self._on_success,
                      on_failure=self._on_failure,
                      on_timeout=self._on_timeout), **data)
     except Exception as err:
         print('anaconda_go: enclosing function error')
         print(err)
Esempio n. 8
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)
Esempio n. 9
0
    def _on_select(self, index: int) -> None:
        """Called when a package is selected from the quick panel
        """

        if index == -1:
            return

        package = self._packages[index]
        try:
            view = self.window.active_view()
            self.view = view
            data = {
                'vid':
                view.id(),
                'path':
                view.file_name(),
                'expr':
                package,
                'private':
                get_settings(view, 'anaconda_go_doc_private_symbols', False),
                'force':
                True,
                'offset':
                0,
                'buf':
                '',
                'go_env': {
                    'GOROOT': go.GOROOT,
                    'GOPATH': go.GOPATH,
                    'CGO_ENABLED': go.CGO_ENABLED,
                    'GO_VERSION': self.go_version
                },
                'method':
                'doc',
                'handler':
                'anaGonda'
            }
            Worker().execute(
                Callback(on_success=self.on_success,
                         on_failure=self._on_failure,
                         on_timeout=self._on_timeout), **data)
        except Exception as err:
            print('anaconda_go: go doc error')
            print(traceback.print_exc())
Esempio n. 10
0
    def run(self, package: bool = False, callstack: bool = False) -> None:
        if package is True:
            self.run_for_packages()
            return

        try:
            view = self.window.active_view()
            self.view = view
            row, col = view.rowcol(view.sel()[0].begin())
            code = view.substr(sublime.Region(0, view.size()))
            data = {
                'vid':
                view.id(),
                'path':
                view.file_name(),
                'expr':
                get_symbol(code, row, col),
                'private':
                get_settings(view, 'anaconda_go_doc_private_symbols', False),
                'force':
                get_settings(view, 'anaconda_go_force_go_doc_usage', False),
                'offset':
                view.text_point(*view.rowcol(view.sel()[0].begin())),
                'buf':
                self.modified_buffer(view),
                'go_env': {
                    'GOROOT': go.GOROOT,
                    'GOPATH': go.GOPATH,
                    'CGO_ENABLED': go.CGO_ENABLED,
                    'GO_VERSION': self.go_version
                },
                'method':
                'doc',
                'handler':
                'anaGonda'
            }
            Worker().execute(
                Callback(on_success=self.on_success,
                         on_failure=self._on_failure,
                         on_timeout=self._on_timeout), **data)
        except Exception as err:
            print('anaconda_go: go doc error')
            print(traceback.print_exc())
Esempio n. 11
0
    def run(self) -> None:
        try:
            view = self.window.active_view()
            self.view = view
            row, col = view.rowcol(view.sel()[0].begin())
            offset = view.text_point(row, col)

            code = view.substr(sublime.Region(0, view.size()))
            data = {
                'vid': view.id(),
                'code': code,
                'path': view.file_name(),
                'settings': {
                    'offset':
                    offset,
                    'expr':
                    get_symbol(code, row, col),
                    'modified_buffer':
                    self._modified_buffer(view, code),
                    'guru_usage':
                    get_settings(view, 'anaconda_go_guru_usage', 'always')
                },
                'go_env': {
                    'GOROOT': go.GOROOT,
                    'GOPATH': go.GOPATH,
                    'CGO_ENABLED': go.CGO_ENABLED
                },
                'method': 'goto',
                'handler': 'anaGonda'
            }
            Worker().execute(
                Callback(on_success=self._on_success,
                         on_failure=self._on_failure,
                         on_timeout=self._on_timeout), **data)
        except Exception as err:
            print('anaconda_go: goto error')
            print(traceback.print_exc())
Esempio n. 12
0
    def _exec(self, edit: sublime.Edit, receiver: str, iface: str) -> None:

        if iface is None or iface == '':
            return

        try:
            data = {
                'vid': self.view.id(),
                'receiver': receiver,
                'iface': iface,
                'go_env': {
                    'GOROOT': go.GOROOT,
                    'GOPATH': go.GOPATH,
                    'CGO_ENABLED': go.CGO_ENABLED
                },
                'method': 'impl',
                'handler': 'anaGonda'
            }
            Worker().execute(
                Callback(on_success=self.update_buffer,
                         on_failure=self.on_failure,
                         on_timeout=self.on_timeout), **data)
        except:
            print('anaconda_go error: {}'.format(traceback.format_exc()))