Exemplo n.º 1
0
def _FindProjectDir(starting_dir):
    project_path = starting_dir
    project_type = None

    for folder in utils.PathsToAllParentFolders(starting_dir):
        for project_file, tail in _MakeProjectFilesForPath(folder):
            if os.path.isfile(project_file):
                project_path = folder
                project_type = tail
                break
        if project_type:
            break

    if project_type:
        # We've found a project marker file (like build.gradle). Search parent
        # directories for that same project type file and find the topmost one as
        # the project root.
        LOGGER.debug(
            'Found %s style project in %s. Searching for '
            'project root:', project_type, project_path)

        for folder in utils.PathsToAllParentFolders(
                os.path.join(project_path, '..')):
            if os.path.isfile(os.path.join(folder, project_type)):
                LOGGER.debug('  %s is a parent project dir', folder)
                project_path = folder
            else:
                break
        LOGGER.debug('  Project root is %s', project_path)

    return project_path
Exemplo n.º 2
0
 def test_PathsToAllParentFolders_WindowsPath(self):
     assert_that(
         utils.PathsToAllParentFolders(r'C:\\foo\\goo\\zoo\\test.c'),
         contains_exactly(os.path.normpath(r'C:\\foo\\goo\\zoo'),
                          os.path.normpath(r'C:\\foo\\goo'),
                          os.path.normpath(r'C:\\foo'),
                          os.path.normpath(r'C:\\')))
Exemplo n.º 3
0
def _FindProjectDir(starting_dir):
    for path in utils.PathsToAllParentFolders(starting_dir):
        for project_file in _MakeProjectFilesForPath(path):
            if os.path.isfile(project_file):
                return path

    return starting_dir
Exemplo n.º 4
0
def PathsToAllParentFolders_Basic_test():
    eq_([
        os.path.normpath('/home/user/projects'),
        os.path.normpath('/home/user'),
        os.path.normpath('/home'),
        os.path.normpath('/')
    ], list(utils.PathsToAllParentFolders('/home/user/projects/test.c')))
Exemplo n.º 5
0
def PathsToAllParentFolders_IsDirectory_test(*args):
    eq_([
        os.path.normpath('/home/user/projects'),
        os.path.normpath('/home/user'),
        os.path.normpath('/home'),
        os.path.normpath('/')
    ], list(utils.PathsToAllParentFolders('/home/user/projects')))
Exemplo n.º 6
0
def PathsToAllParentFolders_WindowsPath_test():
    eq_([
        os.path.normpath(r'C:\\foo\\goo\\zoo'),
        os.path.normpath(r'C:\\foo\\goo'),
        os.path.normpath(r'C:\\foo'),
        os.path.normpath(r'C:\\')
    ], list(utils.PathsToAllParentFolders(r'C:\\foo\\goo\\zoo\\test.c')))
Exemplo n.º 7
0
def PathsToAllParentFolders_IsDirectory_test( *args ):
  assert_that( utils.PathsToAllParentFolders( '/home/user/projects' ),
    contains_exactly(
      os.path.normpath( '/home/user/projects' ),
      os.path.normpath( '/home/user' ),
      os.path.normpath( '/home' ),
      os.path.normpath( '/' )
    )
  )
Exemplo n.º 8
0
 def test_PathsToAllParentFolders_Basic(self):
     assert_that(
         utils.PathsToAllParentFolders('/home/user/projects/test.c'),
         contains_exactly(
             os.path.normpath('/home/user/projects'),
             os.path.normpath('/home/user'),
             os.path.normpath('/home'),
             os.path.normpath('/'),
         ))
Exemplo n.º 9
0
 def GetProjectDirectory(self, request_data, extra_conf_dir):
     # Without LSP workspaces support, RLS relies on the rootUri to detect a
     # project.
     # TODO: add support for LSP workspaces to allow users to change project
     # without having to restart RLS.
     for folder in utils.PathsToAllParentFolders(request_data['filepath']):
         if os.path.isfile(os.path.join(folder, 'Cargo.toml')):
             return folder
     return super(RustCompleter,
                  self).GetProjectDirectory(request_data, extra_conf_dir)
Exemplo n.º 10
0
def FindCompilationDatabasePath(wd):
    # Find all the ancestor directories of the supplied directory
    for folder in utils.PathsToAllParentFolders(wd):
        # Guess not. Let's see if a compile_commands.json file already exists...
        compile_commands = os.path.join(folder, 'compile_commands.json')
        if os.path.exists(compile_commands):
            return compile_commands

        # Doesn't exist. Check the next ancestor

    # Nothing was found. No compilation flags are available.
    return None
Exemplo n.º 11
0
def Settings(**kwargs):
    """Custom settings per language.

    Golang: default YCM Golang completer detects project root by go.mod file.
    With such configuration gopls can consume all free memory on huge
    repositories. To avoid such situations, project root should be detected by
    extended list of files defined in GOLANG_ROOT_FILES (order is important).
    """
    if kwargs['language'] == 'go':
        filename = kwargs['filename']
        for folder in utils.PathsToAllParentFolders(filename):
            for root_file in GOLANG_ROOT_FILES:
                if os.path.isfile(os.path.join(folder, root_file)):
                    return {'project_directory': folder}
Exemplo n.º 12
0
def _FindProjectDir(starting_dir):
    project_path = starting_dir
    _logger.info("fatman: %s", project_path)
    project_type = None

    for folder in utils.PathsToAllParentFolders(starting_dir):
        for project_file, tail in _MakeProjectFilesForPath(folder):
            if os.path.isfile(project_file):
                project_path = folder
                project_type = tail
                break
        if project_type:
            break

    _logger.debug('  Project root is {0}'.format(project_path))
    return project_path
Exemplo n.º 13
0
def FindTernProjectFile(starting_directory):
    for folder in utils.PathsToAllParentFolders(starting_directory):
        tern_project = os.path.join(folder, '.tern-project')
        if os.path.exists(tern_project):
            return tern_project

    # As described here: http://ternjs.net/doc/manual.html#server a global
    # .tern-config file is also supported for the Tern server. This can provide
    # meaningful defaults (for libs, and possibly also for require paths), so
    # don't warn if we find one. The point is that if the user has a .tern-config
    # set up, then she has deliberately done so and a ycmd warning is unlikely
    # to be anything other than annoying.
    tern_config = os.path.expanduser('~/.tern-config')
    if GlobalConfigExists(tern_config):
        return tern_config

    return None
Exemplo n.º 14
0
def FindCompilationDatabase(wd):
    # Find all the ancestor directories of the supplied directory
    for folder in utils.PathsToAllParentFolders(wd):
        # Did we already cache a datbase for this path?
        if folder in compilation_database_dir_map:
            # Yep. Return that.
            return compilation_database_dir_map[folder]

        # Guess not. Let's see if a compile_commands.json file already exists...
        compile_commands = os.path.join(folder, 'compile_commands.json')
        if os.path.exists(compile_commands):
            # Yes, it exists. Create a database and cache it in our map.
            database = ycm_core.CompilationDatabase(folder)
            compilation_database_dir_map[folder] = database
            return database

        # Doesn't exist. Check the next ancestor

    # Nothing was found. No compilation flags are available.
    return None
Exemplo n.º 15
0
def FindTernProjectFile(starting_directory):
    """Finds the path to either a Tern project file or the user's global Tern
  configuration file. If found, a tuple is returned containing the path and a
  boolean indicating if the path is to a .tern-project file. If not found,
  returns (None, False)."""
    for folder in utils.PathsToAllParentFolders(starting_directory):
        tern_project = os.path.join(folder, '.tern-project')
        if os.path.exists(tern_project):
            return (tern_project, True)

    # As described here: http://ternjs.net/doc/manual.html#server a global
    # .tern-config file is also supported for the Tern server. This can provide
    # meaningful defaults (for libs, and possibly also for require paths), so
    # don't warn if we find one. The point is that if the user has a .tern-config
    # set up, then she has deliberately done so and a ycmd warning is unlikely
    # to be anything other than annoying.
    tern_config = os.path.expanduser('~/.tern-config')
    if GlobalConfigExists(tern_config):
        return (tern_config, False)

    return (None, False)
Exemplo n.º 16
0
def PathsToAllParentFolders_FileAtRoot_test():
    eq_([os.path.normpath('/')],
        list(utils.PathsToAllParentFolders('/test.c')))
Exemplo n.º 17
0
 def test_PathsToAllParentFolders_FileAtRoot(self):
     assert_that(utils.PathsToAllParentFolders('/test.c'),
                 contains_exactly(os.path.normpath('/')))