c++11 Youcompleteme
c++11 Youcompleteme
py
Last active 2 months ago • Report abuse
c++11 youcompleteme
.ycm_extra_conf.py
1 import os
2 import ycm_core
3 from clang_helpers import PrepareClangFlags
4
5 # Set this to the absolute path to the folder (NOT the file!) containing the
6 # compile_commands.json file to use that instead of 'flags'. See here for
7 # more details: http://clang.llvm.org/docs/JSONCompilationDatabase.html
8 # Most projects will NOT need to set this to anything; you can just change the
9 # 'flags' list of compilation flags. Notice that YCM itself uses that approach.
10 compilation_database_folder = ''
11
12 # These are the compilation flags that will be used in case there's no
13 # compilation database set.
14 flags = [
15 '-Wall',
16 '-std=c++11',
17 '-stdlib=libc++',
18 '-x',
19 'c++',
20 '-I',
21 '.',
22 '-isystem',
23 '/usr/lib/c++/v1'
24 ]
25
26 if compilation_database_folder:
27 database = ycm_core.CompilationDatabase(compilation_database_folder)
28 else:
29 database = None
30
31
32 def DirectoryOfThisScript():
33 return os.path.dirname(os.path.abspath(__file__))
34
35
36 def MakeRelativePathsInFlagsAbsolute(flags, working_directory):
37 if not working_directory:
38 return flags
39 new_flags = []
40 make_next_absolute = False
41 path_flags = ['-isystem', '-I', '-iquote', '--sysroot=']
42 for flag in flags:
43 new_flag = flag
44
45 if make_next_absolute:
46 make_next_absolute = False
47 if not flag.startswith('/'):
48 new_flag = os.path.join(working_directory, flag)
49
50 for path_flag in path_flags:
51 if flag == path_flag:
52 make_next_absolute = True
53 break
54
55 if flag.startswith(path_flag):
56 path = flag[len(path_flag):]
57 new_flag = path_flag + os.path.join(working_directory, path)
58 break
59
60 if new_flag:
61 new_flags.append(new_flag)
62 return new_flags
63
64
65 def FlagsForFile(filename):
66 if database:
67 # Bear in mind that compilation_info.compiler_flags_ does NOT return a
68 # python list, but a "list-like" StringVec object
69 compilation_info = database.GetCompilationInfoForFile(filename)
70 final_flags = PrepareClangFlags(
71 MakeRelativePathsInFlagsAbsolute(
72 compilation_info.compiler_flags_,
73 compilation_info.compiler_working_dir_),
74 filename)
75 else:
76 relative_to = DirectoryOfThisScript()
77 final_flags = MakeRelativePathsInFlagsAbsolute(flags, relative_to)
78
79 return {
80 'flags': final_flags,
81 'do_cache': True}
mark
mark
mark
mark
mark
buhuipao commented on Apr 10
https://jonasdevlieghere.com/a-better-youcompleteme-config/