Exemplo n.º 1
0
    def get_special_completions(self, view, prefix, locations):

        # Contents of the current line up to the cursor
        line_contents = get_line_contents(view, locations[0])

        # Autocompletion for LANGUAGE pragmas
        if get_setting('auto_complete_language_pragmas'):
            # TODO handle multiple selections
            match_language = LANGUAGE_RE.match(line_contents)
            if match_language:
                return [ (unicode(c),) * 2 for c in self.language_completions ]

        # Autocompletion for import statements
        if get_setting('auto_complete_imports'):
            match_import = IMPORT_RE.match(line_contents)
            if match_import:
                import_completions = [ (unicode(c),) * 2 for c in self.module_completions ]

                # Right after "import "? Propose "qualified" as well!
                qualified_match = IMPORT_QUALIFIED_POSSIBLE_RE.match(line_contents)
                if qualified_match:
                    qualified_prefix = qualified_match.group('qualifiedprefix')
                    if qualified_prefix == "" or "qualified".startswith(qualified_prefix):
                        import_completions.insert(0, (u"qualified", "qualified "))

                return import_completions

        return None
Exemplo n.º 2
0
    def on_modified(self, view):
        lint_check_fly = get_setting('lint_check_fly')
        auto_check_enabled = get_setting('enable_auto_check')
        auto_lint_enabled = get_setting('enable_auto_lint')

        if lint_check_fly and is_haskell_source(view) and view.file_name():
            self.fly_agent.fly(view)
Exemplo n.º 3
0
    def on_modified(self, view):
        lint_check_fly = get_setting('lint_check_fly')
        auto_check_enabled = get_setting('enable_auto_check')
        auto_lint_enabled = get_setting('enable_auto_lint')

        if lint_check_fly and is_haskell_source(view) and view.file_name():
            self.fly_agent.fly(view)
Exemplo n.º 4
0
 def on_query_context(self, view, key, operator, operand, match_all):
     if key == 'auto_completion_popup':
         return get_setting('auto_completion_popup')
     elif key == 'is_haskell_source':
         return is_haskell_source(view)
     else:
         return False
Exemplo n.º 5
0
    def on_post_save(self, view):
        auto_build_enabled = get_setting('enable_auto_build')
        auto_check_enabled = get_setting('enable_auto_check')
        auto_lint_enabled = get_setting('enable_auto_lint')
        cabal_project_dir, cabal_project_name = get_cabal_project_dir_and_name_of_view(view)

        # auto build enabled and file within a cabal project
        if auto_build_enabled and cabal_project_dir is not None:
            view.window().run_command('sublime_haskell_build_auto')
        # try to ghc-mod check
        elif auto_check_enabled and auto_lint_enabled:
            view.window().run_command('sublime_haskell_ghc_mod_check_and_lint')
        elif auto_check_enabled:
            view.window().run_command('sublime_haskell_ghc_mod_check')
        elif auto_lint_enabled:
            view.window().run_command('sublime_haskell_ghc_mod_lint')
Exemplo n.º 6
0
    def on_post_save(self, view):
        auto_build_enabled = get_setting('enable_auto_build')
        auto_check_enabled = get_setting('enable_auto_check')
        auto_lint_enabled = get_setting('enable_auto_lint')
        cabal_project_dir, cabal_project_name = get_cabal_project_dir_and_name_of_view(view)

        # auto build enabled and file within a cabal project
        if auto_build_enabled and cabal_project_dir is not None:
            view.window().run_command('sublime_haskell_build_auto')
        # try to ghc-mod check
        elif get_setting('enable_ghc_mod'):
            if auto_check_enabled and auto_lint_enabled:
                view.window().run_command('sublime_haskell_ghc_mod_check_and_lint')
            elif auto_check_enabled:
                view.window().run_command('sublime_haskell_ghc_mod_check')
            elif auto_lint_enabled:
                view.window().run_command('sublime_haskell_ghc_mod_lint')
Exemplo n.º 7
0
    def get_import_completions(self, view, prefix, locations):

        # Contents of the current line up to the cursor
        line_contents = get_line_contents(view, locations[0])

        # Autocompletion for LANGUAGE pragmas
        if get_setting('auto_complete_language_pragmas'):
            # TODO handle multiple selections
            match_language = LANGUAGE_RE.match(line_contents)
            if match_language:
                return [(unicode(c),) * 2 for c in self.language_completions]

        # Autocompletion for import statements
        if get_setting('auto_complete_imports'):
            match_import_list = IMPORT_SYMBOL_RE.search(line_contents)
            if match_import_list:
                module_name = match_import_list.group('module')
                import_list_completions = []
                with self.info_lock:
                    for file_info in self.info.values():
                        if file_info['moduleName'] == module_name:
                            for d in file_info['declarations']:
                                identifier = d['identifier']
                                import_list_completions.append((identifier[:MAX_COMPLETION_LENGTH], identifier))
                with self.std_info_lock:
                    if module_name in self.std_info:
                        for v in self.std_info[module_name]:
                            import_list_completions.append((v[:MAX_COMPLETION_LENGTH], v))

                return import_list_completions

            match_import = IMPORT_RE_PREFIX.match(line_contents)
            if match_import:
                (qualified, pref) = match_import.groups()
                import_completions = self.get_module_completions_for(pref)

                # Right after "import "? Propose "qualified" as well!
                qualified_match = IMPORT_QUALIFIED_POSSIBLE_RE.match(line_contents)
                if qualified_match:
                    qualified_prefix = qualified_match.group('qualifiedprefix')
                    if qualified_prefix == "" or "qualified".startswith(qualified_prefix):
                        import_completions.insert(0, (u"qualified", "qualified "))

                return list(set(import_completions))

        return None
Exemplo n.º 8
0
    def on_setting_changed(self):
        same = True
        for k, v in self.local_settings.items():
            r = get_setting(k)
            same = same and v == r
            self.local_settings[k] = r

        if not same:
            self.init_ghcmod_completions()
Exemplo n.º 9
0
    def __init__(self):
        # TODO: Start the InspectorAgent as a separate thread.
        self.inspector = InspectorAgent()
        self.inspector.start()

        self.language_completions = []

        if get_setting('enable_ghc_mod'):
            self.init_ghcmod_completions()
Exemplo n.º 10
0
 def on_post_save(self, view):
     # If the edited file was Haskell code within a cabal project, try to
     # compile it.
     cabal_project_dir = get_cabal_project_dir_of_view(view)
     if cabal_project_dir is not None:
         # On another thread, wait for the build to finish.
         sublime.status_message("Rebuilding Haskell...")
         add_to_path = get_setting("add_to_PATH", [])
         thread = Thread(target=wait_for_build_to_complete, args=(add_to_path, view, cabal_project_dir))
         thread.start()
Exemplo n.º 11
0
    def on_post_save(self, view):
        auto_build_enabled = get_setting('enable_auto_build')
        auto_check_enabled = get_setting('enable_auto_check')
        auto_lint_enabled = get_setting('enable_auto_lint')
        cabal_project_dir, cabal_project_name = get_cabal_project_dir_and_name_of_view(
            view)

        # don't flycheck
        self.fly_agent.nofly()

        # auto build enabled and file within a cabal project
        if auto_build_enabled and cabal_project_dir is not None:
            view.window().run_command('sublime_haskell_build_auto')
        elif auto_check_enabled and auto_lint_enabled:
            view.window().run_command('sublime_haskell_check_and_lint')
        elif auto_check_enabled:
            view.window().run_command('sublime_haskell_check')
        elif auto_lint_enabled:
            view.window().run_command('sublime_haskell_lint')
Exemplo n.º 12
0
def current_cabal_build():
    """Current cabal build command"""
    args = []
    if get_setting('use_cabal_dev'):
        args += ['cabal-dev']
    else:
        args += ['cabal']

    args += ['build']

    return attach_sandbox(args)
Exemplo n.º 13
0
def current_cabal_build():
    """Current cabal build command"""
    args = []
    if get_setting('use_cabal_dev'):
        args += ['cabal-dev']
    else:
        args += ['cabal']

    args += ['build']

    return attach_sandbox(args)
Exemplo n.º 14
0
    def on_post_save(self, view):
        auto_build_enabled = get_setting('enable_auto_build')
        auto_check_enabled = get_setting('enable_auto_check')
        auto_lint_enabled = get_setting('enable_auto_lint')
        cabal_project_dir, cabal_project_name = get_cabal_project_dir_and_name_of_view(view)

        # don't flycheck
        self.fly_agent.nofly()

        # auto build enabled and file within a cabal project
        if auto_build_enabled and cabal_project_dir is not None:
            view.window().run_command('sublime_haskell_build_auto')
        elif auto_check_enabled and auto_lint_enabled:
            view.window().run_command('sublime_haskell_check_and_lint')
            view.window().run_command('sublime_haskell_get_types')
        elif auto_check_enabled:
            view.window().run_command('sublime_haskell_check')
            view.window().run_command('sublime_haskell_get_types')
        elif auto_lint_enabled:
            view.window().run_command('sublime_haskell_lint')
Exemplo n.º 15
0
    def run(self):
        use_cabal_dev = get_setting('use_cabal_dev')
        sandbox = get_setting('cabal_dev_sandbox')
        sandboxes = get_setting('cabal_dev_sandbox_list')

        sandboxes.append(sandbox)
        sandboxes = list(set(sandboxes))
        set_setting('cabal_dev_sandbox_list', sandboxes)

        # No candboxes
        if len(sandboxes) == 0:
            sublime.status_message('SublimeHaskell: There is nothing to switch to')
            set_setting('use_cabal_dev', False)
            save_settings()
            return

        # One sandbox, just switch
        if len(sandboxes) == 1:
            set_setting('use_cabal_dev', not use_cabal_dev)
            if use_cabal_dev:
                now_using = 'Cabal'
            else:
                now_using = 'Cabal-Dev'
            sublime.status_message('SublimeHaskell: Switched to ' + now_using)
            save_settings()
            return

        # Many sandboxes, show list
        self.sorted_sands = sandboxes
        # Move previously used sandbox (or cabal) on top
        self.sorted_sands.remove(sandbox)
        if use_cabal_dev:
            self.sorted_sands.insert(0, sandbox)
            self.sorted_sands.insert(0, "<Cabal>")
        else:
            self.sorted_sands.insert(0, "<Cabal>")
            self.sorted_sands.insert(0, sandbox)

        self.window.show_quick_panel(self.sorted_sands, self.on_done)
Exemplo n.º 16
0
    def init_ghcmod_completions(self):

        if not get_setting('enable_ghc_mod'):
            return

        sublime.status_message('SublimeHaskell: Updating ghc_mod completions...')

        # Init LANGUAGE completions
        autocompletion.language_completions = call_ghcmod_and_wait(['lang']).splitlines()

        # Init import module completion
        autocompletion.module_completions = set(call_ghcmod_and_wait(['list']).splitlines())

        sublime.status_message('SublimeHaskell: Updating ghc_mod completions ' + u" \u2714")
Exemplo n.º 17
0
    def run(self):
        current_project_dir, current_project_name = get_cabal_project_dir_and_name_of_view(self.window.active_view())
        if current_project_name and current_project_dir:
            build_mode = get_setting('auto_build_mode')

            build_command = {
               'normal': 'build',
               'normal-then-warnings': 'build_then_warnings',
               'typecheck': 'typecheck',
               'typecheck-then-warnings': 'typecheck_then_warnings',
            }.get(build_mode)

            if not build_command:
                output_error(self.window, "SublimeHaskell: invalid auto_build_mode '%s'" % build_mode)

            run_build(self.window.active_view(), current_project_name, current_project_dir, build_command, None)
Exemplo n.º 18
0
    def __init__(self):
        autocompletion.language_completions = []
        autocompletion.module_completions = set()

        self.local_settings = {
            'enable_ghc_mod': None,
            'use_cabal_dev': None,
            'cabal_dev_sandbox': None,
        }

        for s in self.local_settings.keys():
            self.local_settings[s] = get_setting(s)

        self.init_ghcmod_completions()

        # Subscribe to settings changes to update data
        get_settings().add_on_change('enable_ghc_mod', lambda: self.on_setting_changed())
Exemplo n.º 19
0
    def __init__(self):
        # TODO: Start the InspectorAgent as a separate thread.
        self.inspector = InspectorAgent()
        self.inspector.start()

        autocompletion.language_completions = []
        autocompletion.module_completions = []

        self.local_settings = {
            'enable_ghc_mod' : None,
            'use_cabal_dev' : None,
            'cabal_dev_sandbox' : None }

        for s in self.local_settings.keys():
            self.local_settings[s] = get_setting(s)

        self.init_ghcmod_completions()

        # Subscribe to settings changes to update data
        get_settings().add_on_change('enable_ghc_mod', lambda: self.on_setting_changed())
Exemplo n.º 20
0
    def on_query_completions(self, view, prefix, locations):
        if not is_haskell_source(view):
            return []

        begin_time = time.clock()
        # Only suggest symbols if the current file is part of a Cabal project.
        # TODO: Only suggest symbols from within this project.

        completions = autocompletion.get_import_completions(view, prefix, locations)

        if not completions:
            completions = autocompletion.get_completions(view, prefix, locations)

        end_time = time.clock()
        log('time to get completions: {0} seconds'.format(end_time - begin_time))
        # Don't put completions with special characters (?, !, ==, etc.)
        # into completion because that wipes all default Sublime completions:
        # See http://www.sublimetext.com/forum/viewtopic.php?t=8659
        # TODO: work around this
        comp = [c for c in completions if NO_SPECIAL_CHARS_RE.match(c[0])]
        if get_setting('inhibit_completions'):
            return (comp, sublime.INHIBIT_WORD_COMPLETIONS | sublime.INHIBIT_EXPLICIT_COMPLETIONS)
        return comp