Index: tools/vim/chromium.ycm_extra_conf.py |
diff --git a/tools/vim/chromium.ycm_extra_conf.py b/tools/vim/chromium.ycm_extra_conf.py |
index a2f74a2f1089221cbe96a0eea728b510e3655f94..945639423bb810545f9e7721e08f841cf1ca0ac2 100644 |
--- a/tools/vim/chromium.ycm_extra_conf.py |
+++ b/tools/vim/chromium.ycm_extra_conf.py |
@@ -63,6 +63,8 @@ _default_flags = [ |
'c++', |
] |
+_header_alternates = ('.cc', '.cpp', '.c', '.mm', '.m') |
+ |
_extension_flags = { |
'.m': ['-x', 'objective-c'], |
'.mm': ['-x', 'objective-c++'], |
@@ -117,35 +119,6 @@ def GetDefaultSourceFile(chrome_root, filename): |
return os.path.join(chrome_root, 'base', 'logging.cc') |
-def GetBuildableSourceFile(chrome_root, filename): |
- """Returns a buildable source file corresponding to |filename|. |
- |
- A buildable source file is one which is likely to be passed into clang as a |
- source file during the build. For .h files, returns the closest matching .cc, |
- .cpp or .c file. If no such file is found, returns the same as |
- GetDefaultSourceFile(). |
- |
- Args: |
- chrome_root: (String) Absolute path to the root of Chromium checkout. |
- filename: (String) Absolute path to the target source file. |
- |
- Returns: |
- (String) Absolute path to source file. |
- """ |
- if filename.endswith('.h'): |
- # Header files can't be built. Instead, try to match a header file to its |
- # corresponding source file. |
- alternates = ['.cc', '.cpp', '.c'] |
- for alt_extension in alternates: |
- alt_name = filename[:-2] + alt_extension |
- if os.path.exists(alt_name): |
- return alt_name |
- |
- return GetDefaultSourceFile(chrome_root, filename) |
- |
- return filename |
- |
- |
def GetNinjaBuildOutputsForSourceFile(out_dir, filename): |
"""Returns a list of build outputs for filename. |
@@ -326,8 +299,22 @@ def GetClangOptionsFromNinjaForFilename(chrome_root, filename): |
from ninja_output import GetNinjaOutputDirectory |
out_dir = GetNinjaOutputDirectory(chrome_root) |
- clang_line = GetClangCommandLineFromNinjaForSource( |
- out_dir, GetBuildableSourceFile(chrome_root, filename)) |
+ basename, extension = os.path.splitext(filename) |
+ if extension == '.h': |
+ candidates = [basename + ext for ext in _header_alternates] |
+ else: |
+ candidates = [filename] |
+ |
+ clang_line = None |
+ buildable_extension = extension |
+ for candidate in candidates: |
+ clang_line = GetClangCommandLineFromNinjaForSource(out_dir, candidate) |
+ if clang_line: |
+ buildable_extension = os.path.splitext(candidate)[1] |
+ break |
+ |
+ additional_flags += _extension_flags.get(buildable_extension, []) |
+ |
if not clang_line: |
# If ninja didn't know about filename or it's companion files, then try a |
# default build target. It is possible that the file is new, or build.ninja |
@@ -352,7 +339,6 @@ def FlagsForFile(filename): |
'flags': (List of Strings) Command line flags. |
'do_cache': (Boolean) True if the result should be cached. |
""" |
- ext = os.path.splitext(filename)[1] |
abs_filename = os.path.abspath(filename) |
chrome_root = FindChromeSrcFromFilename(abs_filename) |
clang_flags = GetClangOptionsFromNinjaForFilename(chrome_root, abs_filename) |
@@ -362,7 +348,7 @@ def FlagsForFile(filename): |
# determine the flags again. |
should_cache_flags_for_file = bool(clang_flags) |
- final_flags = _default_flags + _extension_flags.get(ext, []) + clang_flags |
+ final_flags = _default_flags + clang_flags |
return { |
'flags': final_flags, |