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.' )
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()