def run(self, _edit): qsymbol = Common.get_qualified_symbol_at_region(self.view, self.view.sel()[0]) if Common.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.show_status_message('Source location of {0} not found'.format(qsymbol.name), False) 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.show_status_message('Declaration {0} not found'.format(qsymbol.name), False) 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 on_query_context(self, view, key, _operator, _operand, _matchall): if Settings.COMPONENT_DEBUG.event_viewer: print('{0} key = {1}.'.format( type(self).__name__ + '.on_query_context', key)) retval = None if key == 'haskell_autofix': retval = view.settings().get('autofix') elif key == 'auto_completion_popup': retval = Settings.PLUGIN.auto_completion_popup elif key == 'haskell_source': retval = Common.is_haskell_source(view) elif key == 'haskell_source_or_repl': retval = Common.is_haskell_source(view) or Common.is_haskell_repl( view) elif key == 'haskell_repl': retval = Common.is_haskell_repl(view) elif key == 'haskell_symbol_info': retval = Common.is_haskell_symbol_info(view) elif key == 'cabal_source': retval = Common.is_cabal_source(view) elif key == 'scanned_source': retval = self.is_scanned_source(view) elif key == 'in_project': retval = self.is_in_project(view) elif key == "is_module_completion" or key == "is_import_completion": # Completion context is the only branch here where a backend is needed. retval = False with self.backend_mgr: project_dir, project_name = Common.locate_cabal_project_from_view( view) region = view.sel()[0] if region.a == region.b: word_region = view.word(region) preline = Common.get_line_contents_before_region( view, word_region) preline += self.COMPLETION_CHARS[key] qsymbol = Common.get_qualified_symbol(preline) if qsymbol.module: mod_completions = self.autocompleter.get_current_module_completions( project_name, project_dir) if qsymbol.is_import_list: retval = qsymbol.module in mod_completions else: retval = [ m for m in mod_completions if m.startswith(qsymbol.module) ] != [] return retval
def run(self, _edit): if Common.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.show_status_message('Module for symbol {0} not found'.format(qsymbol.full_name())) return modules = [decl.defined_module() for decl in decls] if len(modules) == 0: Common.show_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.is_haskell_source(self.view) or Common.is_haskell_repl(self.view) or \ (Common.is_haskell_symbol_info(self.view) and self.view.settings().get('location'))
def is_visible(self): return Common.is_haskell_symbol_info(self.view) or \ Common.is_haskell_source(self.view) or \ Common.is_haskell_repl(self.view)
def is_visible(self): return Common.is_haskell_symbol_info(self.view)