From 5a2eb4a2aa7bdc46ccc0f3560347875177ddb53b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Fl=C3=BCckiger?= Date: Wed, 26 Oct 2022 08:19:31 +0000 Subject: [PATCH] [ycm] Fix YouCompleteMe config MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The .ycm_extra_conf.py is out of date with the current build settings and ycm versions. In particular, ycm expects a `Settings` function, a couple of more flags need to be passed and some includes are marked -isystem now. Also, we can use the C++ standard from the ninja files instead of hard-coding it. Change-Id: Ibaed29eb341346a86b6b736f95c97b41957f62de Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3980257 Reviewed-by: Clemens Backes Reviewed-by: Michael Achenbach Auto-Submit: Olivier Flückiger Commit-Queue: Michael Achenbach Cr-Commit-Position: refs/heads/main@{#84013} --- .ycm_extra_conf.py | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/.ycm_extra_conf.py b/.ycm_extra_conf.py index 6d79c46245..793beda795 100644 --- a/.ycm_extra_conf.py +++ b/.ycm_extra_conf.py @@ -42,7 +42,6 @@ import sys # Flags from YCM's default config. flags = [ '-DUSE_CLANG_COMPLETER', -'-std=gnu++14', '-x', 'c++', ] @@ -143,25 +142,27 @@ def GetClangCommandFromNinjaForFilename(v8_root, filename): # Parse flags that are important for YCM's purposes. for flag in clang_line.split(' '): if flag.startswith('-I'): - # Relative paths need to be resolved, because they're relative to the - # output dir, not the source. - if flag[2] == '/': - v8_flags.append(flag) - else: - abs_path = os.path.normpath(os.path.join(out_dir, flag[2:])) - v8_flags.append('-I' + abs_path) - elif flag.startswith('-std'): + v8_flags.append(MakeIncludePathAbsolute(flag, "-I", out_dir)) + elif flag.startswith('-isystem'): + v8_flags.append(MakeIncludePathAbsolute(flag, "-isystem", out_dir)) + elif flag.startswith('-std') or flag.startswith( + '-pthread') or flag.startswith('-no'): v8_flags.append(flag) - elif flag.startswith('-') and flag[1] in 'DWFfmO': - if flag == '-Wno-deprecated-register' or flag == '-Wno-header-guard': - # These flags causes libclang (3.3) to crash. Remove it until things - # are fixed. - continue + elif flag.startswith('-') and flag[1] in 'DWFfmgOX': v8_flags.append(flag) - return v8_flags +def MakeIncludePathAbsolute(flag, prefix, out_dir): + # Relative paths need to be resolved, because they're relative to the + # output dir, not the source. + if flag[len(prefix)] == '/': + return flag + else: + abs_path = os.path.normpath(os.path.join(out_dir, flag[len(prefix):])) + return prefix + abs_path + + def FlagsForFile(filename): """This is the main entry point for YCM. Its interface is fixed. @@ -180,3 +181,9 @@ def FlagsForFile(filename): 'flags': final_flags, 'do_cache': True } + + +def Settings(**kwargs): + if kwargs['language'] == 'cfamily': + return FlagsForFile(kwargs['filename']) + return {}