Пример #1
0
 def wrapper(self, *args, **kwargs):
     if autocomplete.hsdev_connected():
         log('Invoking ghc-mod command \'{0}\' via hsdev'.format(cmdname), log_trace)
         return fn(self, *args, **kwargs)
     else:
         log('Invoking ghc-mod command \'{0}\' via ghc-mod'.format(cmdname), log_trace)
         self.view.window().run_command('sublime_haskell_ghc_mod_{0}'.format(cmdname))
Пример #2
0
def get_projects():
    if autocomplete.hsdev_connected():
        folders = sublime.active_window().folders()
        view_files = [
            v.file_name()
            for v in sublime.active_window().views()
            if (is_haskell_source(v) or is_cabal_source(v)) and v.file_name()
        ]

        def npath(p):
            return os.path.normcase(os.path.normpath(p))

        def childof(c, p):
            return npath(c).startswith(npath(p))

        return dict(
            (info["name"], info)
            for info in filter(
                lambda p: any([childof(p["path"], f) for f in folders])
                or any([childof(src, p["path"]) for src in view_files]),
                (autocomplete.hsdev_client.list_projects() or []),
            )
        )
    else:
        folder_files = [
            src
            for f in sublime.active_window().folders()
            for src in autocomplete.list_files_in_dir_recursively(f)
            if os.path.splitext(src)[1] in [".hs", ".cabal"]
        ]
        view_files = [
            v.file_name()
            for v in sublime.active_window().views()
            if (is_haskell_source(v) or is_cabal_source(v)) and v.file_name()
        ]
        src_files = list(map(lambda p: os.path.normcase(os.path.normpath(p)), folder_files + view_files))
        active_projects = []
        while src_files:
            src = src_files.pop()
            proj_dir, proj_name = get_cabal_project_dir_and_name_of_file(src)
            if proj_dir:
                active_projects.append((proj_name, proj_dir))
                src_files = [f for f in src_files if not f.startswith(proj_dir)]

        return dict((name, {"name": name, "path": path}) for name, path in active_projects)