Exemple #1
0
 def assoc_to_project(self, view, filename):
     ## Update file -> project tracking
     project_dir, project_name = Common.locate_cabal_project(filename)
     if project_dir is not None and project_name is not None:
         self.backend_mgr.add_project_file(filename, project_name,
                                           project_dir)
     BackendCmds.cabal_project_status(view, self.backend_mgr)
def get_source_dir(filename):
    '''Get root of hs-source-dirs for filename in project.
    '''
    if not filename:
        return os.path.expanduser('~')

    cabal_dir, cabal_proj = Common.locate_cabal_project(filename)
    if not cabal_dir:
        # No cabal file -> Punt and assume the source directory for the file and project is the same as the file.
        return os.path.dirname(filename)
    else:
        proj_info = CabalReader.CabalProjectReader(cabal_dir, cabal_proj)
        cabal_info = proj_info.cabal_info
        dirs = ['.']

        executables = cabal_info.get('executable', {})
        dirs.extend([sdir.strip()
                     for exe in executables
                     for sdirs in executables[exe].get('hs-source-dirs', [])
                     for sdir in sdirs.split(',')])
        dirs.extend([sdir.strip()
                     for sdirs in cabal_info.get('library', {}).get('hs-source-dirs', [])
                     for sdir in sdirs.split(',')])

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

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

    return os.path.dirname(filename)
def assoc_to_project(view, backend_mgr, filename):
    ## Update file -> project tracking
    project_dir, project_name = Common.locate_cabal_project(filename)
    if Settings.COMPONENT_DEBUG.event_viewer:
        print('EventCommon.assoc_to_project project_name {1} project_dir {0}'.format(project_dir, project_name))
    if project_dir and project_name:
        backend_mgr.add_project_file(filename, project_name, project_dir)
    BackendCmds.cabal_project_status(view, backend_mgr)
Exemple #4
0
def assoc_to_project(view, backend_mgr, filename):
    ## Update file -> project tracking
    project_dir, project_name = Common.locate_cabal_project(filename)
    if Settings.COMPONENT_DEBUG.event_viewer:
        print('EventCommon.assoc_to_project project_name {1} project_dir {0}'.format(project_dir, project_name))
    if project_dir and project_name:
        backend_mgr.add_project_file(filename, project_name, project_dir)
    BackendCmds.cabal_project_status(view, backend_mgr)
Exemple #5
0
 def mark_cabal(self):
     '''Scam all open window views, adding actual cabal files  or those indirectly identified by the Haskell sources
     to the list of cabal files to inspect.
     '''
     with self.cabal_to_load as cand_cabals:
         cand_cabals = []
         for window in sublime.windows():
             for view in window.views():
                 fname = view.file_name()
                 if fname is not None:
                     if fname.endswith('.cabal'):
                         cand_cabals.append(os.path.dirname(fname))
                     elif fname.endswith('.hs'):
                         proj_dir = Common.locate_cabal_project(fname)[0]
                         if proj_dir is not None:
                             cand_cabals.append(proj_dir)
         # Make the list of cabal files unique
         cand_cabals[:] = list(set(cand_cabals))
 def mark_cabal(self):
     '''Scam all open window views, adding actual cabal files  or those indirectly identified by the Haskell sources
     to the list of cabal files to inspect.
     '''
     with self.cabal_to_load as cand_cabals:
         cand_cabals = []
         for window in sublime.windows():
             for view in window.views():
                 fname = view.file_name()
                 if fname is not None:
                     if fname.endswith('.cabal'):
                         cand_cabals.append(os.path.dirname(fname))
                     elif fname.endswith('.hs'):
                         proj_dir = Common.locate_cabal_project(fname)[0]
                         if proj_dir is not None:
                             cand_cabals.append(proj_dir)
         # Make the list of cabal files unique
         cand_cabals[:] = list(set(cand_cabals))
Exemple #7
0
def get_source_dir(filename):
    '''Get root of hs-source-dirs for filename in project.
    '''
    if not filename:
        return os.path.expanduser('~')

    cabal_dir, cabal_proj = Common.locate_cabal_project(filename)
    if not cabal_dir:
        # No cabal file -> Punt and assume the source directory for the file and project is the same as the file.
        return os.path.dirname(filename)
    else:
        proj_info = CabalReader.CabalProjectReader(cabal_dir, cabal_proj)
        cabal_info = proj_info.cabal_info
        dirs = ['.']

        executables = cabal_info.get('executable', {})
        dirs.extend([
            sdir.strip() for exe in executables
            for sdirs in executables[exe].get('hs-source-dirs', [])
            for sdir in sdirs.split(',')
        ])
        dirs.extend([
            sdir.strip() for sdirs in cabal_info.get('library', {}).get(
                'hs-source-dirs', []) for sdir in sdirs.split(',')
        ])

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

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

    return os.path.dirname(filename)