def ghcmod_get_type_of_cursor(self):
        view = self.view

        filename = str(view.file_name())
        row, col = view.rowcol(view.sel()[0].a)
        row1, col1 = row + 1, col + 1  # ghc-mod uses rows/cols starting with 1
        module_region = view.find(MODULE_RE_STR, 0)

        if module_region is None:
            sublime.status_message("SublimeHaskell: Could not determine module name!")
            return None

        # RE must match; there is only one group in the RE.
        module = MODULE_RE.match(view.substr(module_region)).group(1)

        ghcmod_args = ['type', filename, module, str(row1), str(col1)]
        out = call_ghcmod_and_wait(ghcmod_args, cwd=get_cabal_project_dir_of_view(view))

        if not out:
            sublime.status_message("ghc-mod %s returned nothing" % ' '.join(ghcmod_args))
            return None

        # ghc-mod type returns the type of the expression at at the given row/col.
        # It can return multiple lines, extending the expression scope by one level each.
        # The last line belongs to the toplevel expression.
        types = map(parse_ghc_mod_type_line, out.strip().split('\n'))
        result_type = types[0]['type']  # innermost expression's type

        if not result_type:
            sublime.error_message("ghc-mod type returned unexpected output")
            return None

        return result_type
Exemple #2
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()
    def on_query_completions(self, view, prefix, locations):
        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.

        cabal_dir = get_cabal_project_dir_of_view(view)
        if cabal_dir is not None:

            completions = self.get_special_completions(view, prefix, locations)

            if not completions:
                completions = self.inspector.get_completions(view.file_name())

            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
            return [ c for c in completions if NO_SPECIAL_CHARS_RE.match(c[0]) ]

        return []
Exemple #4
0
    def ghcmod_get_type_of_cursor(self):
        view = self.view

        filename = str(view.file_name())
        row, col = view.rowcol(view.sel()[0].a)
        row1, col1 = row + 1, col + 1  # ghc-mod uses rows/cols starting with 1
        module_region = view.find(MODULE_RE_STR, 0)

        if module_region is None:
            sublime.status_message(
                "SublimeHaskell: Could not determine module name!")
            return None

        # RE must match; there is only one group in the RE.
        module = MODULE_RE.match(view.substr(module_region)).group(1)

        ghcmod_args = ['type', filename, module, str(row1), str(col1)]
        out = call_ghcmod_and_wait(ghcmod_args,
                                   cwd=get_cabal_project_dir_of_view(view))

        if not out:
            sublime.status_message("ghc-mod %s returned nothing" %
                                   ' '.join(ghcmod_args))
            return None

        # ghc-mod type returns the type of the expression at at the given row/col.
        # It can return multiple lines, extending the expression scope by one level each.
        # The last line belongs to the toplevel expression.
        types = map(parse_ghc_mod_type_line, out.strip().split('\n'))
        result_type = types[0]['type']  # innermost expression's type

        if not result_type:
            sublime.error_message("ghc-mod type returned unexpected output")
            return None

        return result_type