예제 #1
0
    def _ResponseForInclude(self, request_data):
        """Returns response for include file location if cursor is on the
    include statement, None otherwise.
    Throws RuntimeError if cursor is on include statement and corresponding
    include file not found."""
        current_line = request_data['line_value']
        include_file_name, quoted_include = GetFullIncludeValue(current_line)
        if not include_file_name:
            return None

        flags = self._FlagsForRequest(request_data)
        current_file_path = request_data['filepath']
        quoted_include_paths, include_paths = UserIncludePaths(
            flags, current_file_path)
        if quoted_include:
            include_file_path = _GetAbsolutePath(include_file_name,
                                                 quoted_include_paths)
            if include_file_path:
                return responses.BuildGoToResponse(include_file_path,
                                                   line_num=1,
                                                   column_num=1)

        include_file_path = _GetAbsolutePath(include_file_name, include_paths)
        if include_file_path:
            return responses.BuildGoToResponse(include_file_path,
                                               line_num=1,
                                               column_num=1)
        raise RuntimeError('Include file not found.')
예제 #2
0
    def GetIncludePaths(self, request_data):
        column_codepoint = request_data['column_codepoint'] - 1
        current_line = request_data['line_value']
        line = current_line[:column_codepoint]
        path_dir, quoted_include, start_codepoint = (
            GetIncompleteIncludeValue(line))
        if start_codepoint is None:
            return None

        request_data['start_codepoint'] = start_codepoint

        # We do what GCC does for <> versus "":
        # http://gcc.gnu.org/onlinedocs/cpp/Include-Syntax.html
        flags = self._FlagsForRequest(request_data)
        filepath = request_data['filepath']
        quoted_include_paths, include_paths = UserIncludePaths(flags, filepath)
        if quoted_include:
            include_paths.extend(quoted_include_paths)

        paths = []
        for include_path in include_paths:
            unicode_path = ToUnicode(os.path.join(include_path, path_dir))
            try:
                # We need to pass a unicode string to get unicode strings out of
                # listdir.
                relative_paths = os.listdir(unicode_path)
            except Exception:
                self._logger.exception('Error while listing %s folder.',
                                       unicode_path)
                relative_paths = []

            paths.extend(
                os.path.join(include_path, path_dir, relative_path)
                for relative_path in relative_paths)
        return paths
예제 #3
0
  def _ResponseForInclude( self, request_data ):
    """Returns response for include file location if cursor is on the
    include statement, None otherwise.
    Throws RuntimeError if cursor is on include statement and corresponding
    include file not found."""
    current_line = request_data[ 'line_value' ]
    include_file_name, quoted_include = GetFullIncludeValue( current_line )
    if not include_file_name:
      return None

    flags, current_file_path = self._FlagsForRequest( request_data )
    ( quoted_include_paths,
      include_paths,
      framework_paths ) = UserIncludePaths( flags, current_file_path )

    include_file_path = None
    if quoted_include:
      include_file_path = _GetAbsolutePath( include_file_name,
                                            quoted_include_paths )

    if not include_file_path:
      include_file_path = _GetAbsolutePath( include_file_name, include_paths )

    if not include_file_path and framework_paths:
      head, tail = PathLeftSplit( include_file_name )
      include_file_name = os.path.join( head + '.framework', 'Headers', tail )
      include_file_path = _GetAbsolutePath( include_file_name, framework_paths )

    if include_file_path:
      return responses.BuildGoToResponse( include_file_path,
                                          line_num = 1,
                                          column_num = 1 )

    raise RuntimeError( 'Include file not found.' )
예제 #4
0
    def GetIncludePaths(self, request_data):
        column_codepoint = request_data['column_codepoint'] - 1
        current_line = request_data['line_value']
        line = current_line[:column_codepoint]
        path_dir, quoted_include, start_codepoint = (
            GetIncompleteIncludeValue(line))
        if start_codepoint is None:
            return None

        request_data['start_codepoint'] = start_codepoint

        # We do what GCC does for <> versus "":
        # http://gcc.gnu.org/onlinedocs/cpp/Include-Syntax.html
        flags, filepath = self._FlagsForRequest(request_data)
        (quoted_include_paths, include_paths,
         framework_paths) = UserIncludePaths(flags, filepath)
        if quoted_include:
            include_paths.extend(quoted_include_paths)

        includes = IncludeList()

        for include_path in include_paths:
            unicode_path = ToUnicode(os.path.join(include_path, path_dir))
            includes.AddIncludes(self._include_cache.GetIncludes(unicode_path))

        if framework_paths:
            if path_dir:
                head, tail = PathLeftSplit(path_dir)
                path_dir = os.path.join(head + '.framework', 'Headers', tail)
            for framework_path in framework_paths:
                unicode_path = ToUnicode(os.path.join(framework_path,
                                                      path_dir))
                includes.AddIncludes(
                    self._include_cache.GetIncludes(unicode_path,
                                                    is_framework=not path_dir))

        return includes.GetIncludes()