OLD | NEW |
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 # Autocompletion config for YouCompleteMe in Chromium. | 5 # Autocompletion config for YouCompleteMe in Chromium. |
6 # | 6 # |
7 # USAGE: | 7 # USAGE: |
8 # | 8 # |
9 # 1. Install YCM [https://github.com/Valloric/YouCompleteMe] | 9 # 1. Install YCM [https://github.com/Valloric/YouCompleteMe] |
10 # (Googlers should check out [go/ycm]) | 10 # (Googlers should check out [go/ycm]) |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 import sys | 56 import sys |
57 | 57 |
58 # Flags from YCM's default config. | 58 # Flags from YCM's default config. |
59 _default_flags = [ | 59 _default_flags = [ |
60 '-DUSE_CLANG_COMPLETER', | 60 '-DUSE_CLANG_COMPLETER', |
61 '-std=c++11', | 61 '-std=c++11', |
62 '-x', | 62 '-x', |
63 'c++', | 63 'c++', |
64 ] | 64 ] |
65 | 65 |
| 66 _extension_flags = { |
| 67 '.m': ['-x', 'objective-c'], |
| 68 '.mm': ['-x', 'objective-c++'], |
| 69 } |
66 | 70 |
67 def PathExists(*args): | 71 def PathExists(*args): |
68 return os.path.exists(os.path.join(*args)) | 72 return os.path.exists(os.path.join(*args)) |
69 | 73 |
70 | 74 |
71 def FindChromeSrcFromFilename(filename): | 75 def FindChromeSrcFromFilename(filename): |
72 """Searches for the root of the Chromium checkout. | 76 """Searches for the root of the Chromium checkout. |
73 | 77 |
74 Simply checks parent directories until it finds .gclient and src/. | 78 Simply checks parent directories until it finds .gclient and src/. |
75 | 79 |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
341 """This is the main entry point for YCM. Its interface is fixed. | 345 """This is the main entry point for YCM. Its interface is fixed. |
342 | 346 |
343 Args: | 347 Args: |
344 filename: (String) Path to source file being edited. | 348 filename: (String) Path to source file being edited. |
345 | 349 |
346 Returns: | 350 Returns: |
347 (Dictionary) | 351 (Dictionary) |
348 'flags': (List of Strings) Command line flags. | 352 'flags': (List of Strings) Command line flags. |
349 'do_cache': (Boolean) True if the result should be cached. | 353 'do_cache': (Boolean) True if the result should be cached. |
350 """ | 354 """ |
| 355 ext = os.path.splitext(filename)[1] |
351 abs_filename = os.path.abspath(filename) | 356 abs_filename = os.path.abspath(filename) |
352 chrome_root = FindChromeSrcFromFilename(abs_filename) | 357 chrome_root = FindChromeSrcFromFilename(abs_filename) |
353 clang_flags = GetClangOptionsFromNinjaForFilename(chrome_root, abs_filename) | 358 clang_flags = GetClangOptionsFromNinjaForFilename(chrome_root, abs_filename) |
354 | 359 |
355 # If clang_flags could not be determined, then assume that was due to a | 360 # If clang_flags could not be determined, then assume that was due to a |
356 # transient failure. Preventing YCM from caching the flags allows us to try to | 361 # transient failure. Preventing YCM from caching the flags allows us to try to |
357 # determine the flags again. | 362 # determine the flags again. |
358 should_cache_flags_for_file = bool(clang_flags) | 363 should_cache_flags_for_file = bool(clang_flags) |
359 | 364 |
360 final_flags = _default_flags + clang_flags | 365 final_flags = _default_flags + _extension_flags.get(ext, []) + clang_flags |
361 | 366 |
362 return { | 367 return { |
363 'flags': final_flags, | 368 'flags': final_flags, |
364 'do_cache': should_cache_flags_for_file | 369 'do_cache': should_cache_flags_for_file |
365 } | 370 } |
OLD | NEW |