Bug 1522140 - Make .ycm_extra_conf.py handle headers better. r=Ehsan

Files with .h extension are built with the c compiler by default, which makes
the diagnostics useless. If we know this is a cpp file, hint it so that it
builds it with the right mode.

Differential Revision: https://phabricator.services.mozilla.com/D17372

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Emilio Cobos Álvarez 2019-01-23 17:17:18 +00:00
parent ad87a838f7
commit 1dcbdcf59e

View File

@ -24,6 +24,16 @@ mach_module = imp.load_module('_mach', open(path), path, ('', 'r', imp.PY_SOURCE
sys.dont_write_bytecode = old_bytecode
def _is_likely_cpp_header(filename):
if not filename.endswith('.h'):
return False
if filename.endswith('Inlines.h') or filename.endswith('-inl.h'):
return True
cpp_file = filename[:-1] + 'cpp'
return os.path.exists(cpp_file)
def FlagsForFile(filename):
mach = mach_module.get_mach()
out = StringIO()
@ -41,6 +51,9 @@ def FlagsForFile(filename):
# https://github.com/Valloric/YouCompleteMe/issues/1490
final_flags = [x for x in flag_list if not x.startswith('-march=armv')]
if _is_likely_cpp_header(filename):
final_flags += ["-x", "c++"]
return {
'flags': final_flags,
'do_cache': True