Пример #1
0
    def inspect_project(self, cabal_dir):
        (project_name, _) = Common.get_cabal_in_dir(cabal_dir)

        with Common.status_message_process('Inspecting project {0}'.format(project_name), priority=1) as smgr:
            self.client_back.scan(projects=[cabal_dir],
                                  on_notify=ScanStatus(smgr),
                                  wait=True,
                                  docs=Settings.PLUGIN.enable_hdocs)
Пример #2
0
    def inspect_project(self, cabal_dir):
        (project_name, _) = Common.get_cabal_in_dir(cabal_dir)

        with Common.status_message_process('Inspecting project {0}'.format(project_name), priority=1) as smgr:
            self.backend.scan(projects=[cabal_dir],
                              on_notify=ScanStatus(smgr),
                              wait_complete=True,
                              timeout=None,
                              docs=Settings.PLUGIN.enable_hdocs)
            smgr.result_ok()
Пример #3
0
    def inspect_project(self, cabal_dir):
        (project_name, _) = Common.get_cabal_in_dir(cabal_dir)

        with Common.status_message_process(
                'Inspecting project {0}'.format(project_name),
                priority=1) as smgr:
            self.backend.scan(projects=[cabal_dir],
                              on_notify=ScanStatus(smgr),
                              wait_complete=True,
                              timeout=None,
                              docs=Settings.PLUGIN.enable_hdocs)
            smgr.result_ok()
Пример #4
0
def get_source_dir(filename):
    """
    Get root of hs-source-dirs for filename in project
    """
    if not filename:
        return os.path.expanduser('~')
        # return os.getcwd()

    cabal_dir, _ = Common.get_cabal_project_dir_and_name_of_file(filename)
    if not cabal_dir:
        return os.path.dirname(filename)

    _, cabal_file = Common.get_cabal_in_dir(cabal_dir)
    exit_code, out, _ = ProcHelper.run_process(['hsinspect', cabal_file])

    if exit_code == 0:
        info = json.loads(out)

        dirs = ["."]

        if 'error' not in info and 'description' in info:
            # collect all hs-source-dirs
            descr = info['description']
            if descr['library']:
                dirs.extend(descr['library']['info']['source-dirs'])
            for i in descr['executables']:
                dirs.extend(i['info']['source-dirs'])
            for test in descr['tests']:
                dirs.extend(test['info']['source-dirs'])

        paths = [os.path.abspath(os.path.join(cabal_dir, d)) for d in dirs]
        paths.sort(key=lambda p: -len(p))

        for path in paths:
            if filename.startswith(path):
                return path

    return os.path.dirname(filename)