Пример #1
0
    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
Пример #2
0
    def on_query_completions(self, view, _prefix, locations):
        if not HAS_SUBLIME_REPL or not Common.is_haskell_repl(view):
            return []

        repl = sublimerepl.manager.repl_view(view)

        line_contents = Common.get_line_contents(view, locations[0])
        command = COMMAND_RE.match(line_contents)
        if command:
            return self.repl_commands_completions()

        imp = IMPORT_RE.match(line_contents)
        if imp:
            mod = imp.group('module')
            repl_id = KNOWN_REPLS.get_repl_view(repl.external_id)
            cwd = repl_id.path if repl_id else None

            return (autocomplete.AUTO_COMPLETER.get_module_completions_for(
                mod, current_dir=cwd), sublime.INHIBIT_WORD_COMPLETIONS
                    | sublime.INHIBIT_EXPLICIT_COMPLETIONS)

        # ????
        completions = []

        if Settings.PLUGIN.inhibit_completions and len(completions) != 0:
            return (completions, sublime.INHIBIT_WORD_COMPLETIONS
                    | sublime.INHIBIT_EXPLICIT_COMPLETIONS)
        return completions
Пример #3
0
 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'))
Пример #4
0
 def is_visible(self):
     return Common.is_haskell_source(self.view) or Common.is_haskell_repl(self.view)
Пример #5
0
 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)
Пример #6
0
 def is_enabled(self):
     return (self.view.settings().get('package') is not None) or \
            Common.is_haskell_source(self.view) or \
            Common.is_haskell_repl(self.view)