Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(18)

Side by Side Diff: tools/vim/chromium.ycm_extra_conf.py

Issue 2039923002: Fix the .ycm_extra_conf.py and SublimeText documentation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 155
156 Returns: 156 Returns:
157 (List of Strings) List of target names. Will return [] if |filename| doesn't 157 (List of Strings) List of target names. Will return [] if |filename| doesn't
158 yield any .o or .obj outputs. 158 yield any .o or .obj outputs.
159 """ 159 """
160 # Ninja needs the path to the source file relative to the output build 160 # Ninja needs the path to the source file relative to the output build
161 # directory. 161 # directory.
162 rel_filename = os.path.relpath(os.path.realpath(filename), out_dir) 162 rel_filename = os.path.relpath(os.path.realpath(filename), out_dir)
163 163
164 p = subprocess.Popen(['ninja', '-C', out_dir, '-t', 'query', rel_filename], 164 p = subprocess.Popen(['ninja', '-C', out_dir, '-t', 'query', rel_filename],
165 stdout=subprocess.PIPE, stderr=subprocess.STDOUT) 165 stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
166 universal_newlines=True)
166 stdout, _ = p.communicate() 167 stdout, _ = p.communicate()
167 if p.returncode: 168 if p.returncode != 0:
168 return [] 169 return []
169 170
170 # The output looks like: 171 # The output looks like:
171 # ../../relative/path/to/source.cc: 172 # ../../relative/path/to/source.cc:
172 # outputs: 173 # outputs:
173 # obj/reative/path/to/target.source.o 174 # obj/reative/path/to/target.source.o
174 # obj/some/other/target2.source.o 175 # obj/some/other/target2.source.o
175 # another/target.txt 176 # another/target.txt
176 # 177 #
177 outputs_text = stdout.partition('\n outputs:\n')[2] 178 outputs_text = stdout.partition('\n outputs:\n')[2]
(...skipping 11 matching lines...) Expand all
189 Args: 190 Args:
190 out_dir: (String) Absolute path to ninja build output directory. 191 out_dir: (String) Absolute path to ninja build output directory.
191 build_target: (String) A build target understood by ninja 192 build_target: (String) A build target understood by ninja
192 193
193 Returns: 194 Returns:
194 (String or None) Clang command line or None if a Clang command line couldn't 195 (String or None) Clang command line or None if a Clang command line couldn't
195 be determined. 196 be determined.
196 """ 197 """
197 p = subprocess.Popen(['ninja', '-v', '-C', out_dir, 198 p = subprocess.Popen(['ninja', '-v', '-C', out_dir,
198 '-t', 'commands', build_target], 199 '-t', 'commands', build_target],
199 stdout=subprocess.PIPE) 200 stdout=subprocess.PIPE, universal_newlines=True)
200 stdout, stderr = p.communicate() 201 stdout, stderr = p.communicate()
201 if p.returncode: 202 if p.returncode != 0:
202 return None 203 return None
203 204
204 # Ninja will return multiple build steps for all dependencies up to 205 # Ninja will return multiple build steps for all dependencies up to
205 # |build_target|. The build step we want is the last Clang invocation, which 206 # |build_target|. The build step we want is the last Clang invocation, which
206 # is expected to be the one that outputs |build_target|. 207 # is expected to be the one that outputs |build_target|.
207 for line in reversed(stdout.split('\n')): 208 for line in reversed(stdout.split('\n')):
208 if 'clang' in line: 209 if 'clang' in line:
209 return line 210 return line
210 return None 211 return None
211 212
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 clang_line = GetClangCommandLineFromNinjaForSource( 325 clang_line = GetClangCommandLineFromNinjaForSource(
325 out_dir, GetBuildableSourceFile(chrome_root, filename)) 326 out_dir, GetBuildableSourceFile(chrome_root, filename))
326 if not clang_line: 327 if not clang_line:
327 # If ninja didn't know about filename or it's companion files, then try a 328 # If ninja didn't know about filename or it's companion files, then try a
328 # default build target. It is possible that the file is new, or build.ninja 329 # default build target. It is possible that the file is new, or build.ninja
329 # is stale. 330 # is stale.
330 clang_line = GetClangCommandLineFromNinjaForSource( 331 clang_line = GetClangCommandLineFromNinjaForSource(
331 out_dir, GetDefaultSourceFile(chrome_root, filename)) 332 out_dir, GetDefaultSourceFile(chrome_root, filename))
332 333
333 if not clang_line: 334 if not clang_line:
334 return (additional_flags, []) 335 return additional_flags
335 336
336 return GetClangOptionsFromCommandLine(clang_line, out_dir, additional_flags) 337 return GetClangOptionsFromCommandLine(clang_line, out_dir, additional_flags)
337 338
338 339
339 def FlagsForFile(filename): 340 def FlagsForFile(filename):
340 """This is the main entry point for YCM. Its interface is fixed. 341 """This is the main entry point for YCM. Its interface is fixed.
341 342
342 Args: 343 Args:
343 filename: (String) Path to source file being edited. 344 filename: (String) Path to source file being edited.
344 345
(...skipping 10 matching lines...) Expand all
355 # transient failure. Preventing YCM from caching the flags allows us to try to 356 # transient failure. Preventing YCM from caching the flags allows us to try to
356 # determine the flags again. 357 # determine the flags again.
357 should_cache_flags_for_file = bool(clang_flags) 358 should_cache_flags_for_file = bool(clang_flags)
358 359
359 final_flags = _default_flags + clang_flags 360 final_flags = _default_flags + clang_flags
360 361
361 return { 362 return {
362 'flags': final_flags, 363 'flags': final_flags,
363 'do_cache': should_cache_flags_for_file 364 'do_cache': should_cache_flags_for_file
364 } 365 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698