def run(self, _edit, **_kwargs): qsymbol = Common.get_qualified_symbol_at_region(self.view, self.view.sel()[0]) if Common.view_is_haskell_symbol_info(self.view): # Go to within symbol info window loc = self.view.settings().get('location') if loc: self.view.window().open_file(loc, sublime.ENCODED_POSITION) else: Common.sublime_status_message('Source location of {0} not found'.format(qsymbol.name)) else: backend = BackendManager.active_backend() whois_name = qsymbol.qualified_name() full_name = qsymbol.full_name() current_file_name = self.view.file_name() candidates = [] module_candidates = [] if not qsymbol.is_module(): candidates = [decl for decl in backend.whois(whois_name, current_file_name) if decl.by_source()] if candidates: if candidates[0].has_source_location(): self.view.window().open_file(candidates[0].get_source_location(), sublime.ENCODED_POSITION) else: cands = candidates[:] candidates = [] for cand in cands: for i in cand.imported: candidates = [sym for sym in backend.symbol(lookup=cand.name, search_type='exact', source=True) if sym.module.name == i.module] if candidates and candidates[0].has_source_location(): self.view.window().open_file(candidates[0].get_source_location(), sublime.ENCODED_POSITION) return else: candidates = backend.symbol(lookup=qsymbol.name, search_type='exact', source=True) else: module_candidates = [m for m in backend.list_modules(source=True, module=full_name) if m.name == full_name] if not candidates and not module_candidates: Common.sublime_status_message('Declaration {0} not found'.format(qsymbol.name)) else: candidates_len = len(candidates) if candidates is not None else 0 module_candidates_len = len(module_candidates) if module_candidates is not None else 0 if candidates_len + module_candidates_len == 1: if candidates_len == 1: self.view.window().open_file(candidates[0].get_source_location(), sublime.ENCODED_POSITION) elif module_candidates_len == 1: self.view.window().open_file(module_candidates[0].location.filename) return else: # many candidates self.select_candidates = [([c.brief(use_unicode=False), c.get_source_location()], True) for c in candidates] self.select_candidates += [([m.name, m.location.filename], False) for m in module_candidates] just_names = [c[0] for c in self.select_candidates] self.view.window().show_quick_panel(just_names, self.on_done, 0, 0, self.on_highlighted)
def run(self, _edit, **_kwargs): if Common.view_is_haskell_symbol_info(self.view): pack = self.view.settings().get('package') mod = self.view.settings().get('module') if pack and mod: webbrowser.open('http://hackage.haskell.org/package/{0}/docs/{1}.html'.format(pack, mod.replace('.', '-'))) else: project_name = Common.locate_cabal_project_from_view(self.view)[1] qsymbol = Common.get_qualified_symbol_at_region(self.view, self.view.sel()[0]) modules = [] if qsymbol.is_module(): # module scope = self.view.file_name() if scope: modules = [m for m in BackendManager.active_backend().scope_modules(project_name, scope, lookup=qsymbol.module, search_type='exact') if m.by_cabal()] else: modules = [m for m in BackendManager.active_backend().list_modules(symdb=m.location.db) if m.name == qsymbol.module and m.by_cabal()] else: # symbol scope = self.view.file_name() if scope: decls = BackendManager.active_backend().whois(qsymbol.qualified_name(), file=scope) or \ BackendManager.active_backend().lookup(qsymbol.full_name(), file=scope) or \ BackendManager.active_backend().symbol(lookup=qsymbol.full_name(), search_type='exact') if not decls: Common.sublime_status_message('Module for symbol {0} not found'.format(qsymbol.full_name())) return modules = [decl.defined_module() for decl in decls] if not modules: Common.sublime_status_message('Module {0} not found'.format(qsymbol.module)) elif len(modules) == 1: pkg_id = modules[0].location.package.package_id() pkg_name = modules[0].name.replace('.', '-') webbrowser.open('http://hackage.haskell.org/package/{0}/docs/{1}.html'.format(pkg_id, pkg_name)) else: self.candidates = modules[:] mod_strings = [[m.name, m.location.package.package_id()] for m in self.candidates] self.view.window().show_quick_panel(mod_strings, self.on_done)
def is_enabled(self): return Common.view_is_haskell_source(self.view) or Common.view_is_haskell_repl(self.view) or \ (Common.view_is_haskell_symbol_info(self.view) and self.view.settings().get('location'))
def is_visible(self): return Common.view_is_haskell_symbol_info(self.view) or \ Common.view_is_haskell_source(self.view) or \ Common.view_is_haskell_repl(self.view)
def is_visible(self): return Common.view_is_haskell_symbol_info(self.view)
def context_haskell_symbol_info(self, view, _key, _operator, _operand, _matchall): return Common.view_is_haskell_symbol_info(view)