Added a YCM configuration file.
- Author
- Vngngdn
- Date
- July 11, 2016, 5:58 p.m.
- Hash
- 82cf8f98b764c8e4306b0a3f2121a1a51abb2f79
- Parent
- bfce49c5c279d2f3b391ea06179e7e7699ab666b
- Modified file
- .ycm_extra_conf.py
.ycm_extra_conf.py ¶
128 additions and 0 deletions.
View changes Hide changes
+ |
1 |
|
+ |
2 |
import os |
+ |
3 |
import ycm_core |
+ |
4 |
|
+ |
5 |
# These are the compilation flags that will be used in case there's no |
+ |
6 |
# compilation database set (by default, one is not set). |
+ |
7 |
flags = [ |
+ |
8 |
'-Wall', |
+ |
9 |
'-Wextra', |
+ |
10 |
'-Werror', |
+ |
11 |
'-Wc++98-compat', |
+ |
12 |
'-Wno-long-long', |
+ |
13 |
'-Wno-variadic-macros', |
+ |
14 |
'-fexceptions', |
+ |
15 |
'-DNDEBUG', |
+ |
16 |
# I try to refrain from having to write C++, so c99 is good for me. |
+ |
17 |
'-std=c', |
+ |
18 |
'-x', |
+ |
19 |
'c', |
+ |
20 |
'-isystem', |
+ |
21 |
'../BoostParts', |
+ |
22 |
'-isystem', |
+ |
23 |
# This path will only work on OS X, but extra paths that don't exist are not |
+ |
24 |
# harmful |
+ |
25 |
'/System/Library/Frameworks/Python.framework/Headers', |
+ |
26 |
'-isystem', |
+ |
27 |
'../llvm/include', |
+ |
28 |
'-isystem', |
+ |
29 |
'../llvm/tools/clang/include', |
+ |
30 |
'-I', |
+ |
31 |
'.', |
+ |
32 |
'-I', |
+ |
33 |
'./ClangCompleter', |
+ |
34 |
'-isystem', |
+ |
35 |
'./tests/gmock/gtest', |
+ |
36 |
'-isystem', |
+ |
37 |
'./tests/gmock/gtest/include', |
+ |
38 |
'-isystem', |
+ |
39 |
'./tests/gmock', |
+ |
40 |
'-isystem', |
+ |
41 |
'./tests/gmock/include', |
+ |
42 |
] |
+ |
43 |
|
+ |
44 |
compilation_database_folder = '' |
+ |
45 |
|
+ |
46 |
if os.path.exists( compilation_database_folder ): |
+ |
47 |
database = ycm_core.CompilationDatabase( compilation_database_folder ) |
+ |
48 |
else: |
+ |
49 |
database = None |
+ |
50 |
|
+ |
51 |
SOURCE_EXTENSIONS = [ '.cpp', '.cxx', '.cc', '.c', '.m', '.mm' ] |
+ |
52 |
|
+ |
53 |
def DirectoryOfThisScript(): |
+ |
54 |
return os.path.dirname( os.path.abspath( __file__ ) ) |
+ |
55 |
|
+ |
56 |
|
+ |
57 |
def MakeRelativePathsInFlagsAbsolute( flags, working_directory ): |
+ |
58 |
if not working_directory: |
+ |
59 |
return list( flags ) |
+ |
60 |
new_flags = [] |
+ |
61 |
make_next_absolute = False |
+ |
62 |
path_flags = [ '-isystem', '-I', '-iquote', '--sysroot=' ] |
+ |
63 |
for flag in flags: |
+ |
64 |
new_flag = flag |
+ |
65 |
|
+ |
66 |
if make_next_absolute: |
+ |
67 |
make_next_absolute = False |
+ |
68 |
if not flag.startswith( '/' ): |
+ |
69 |
new_flag = os.path.join( working_directory, flag ) |
+ |
70 |
|
+ |
71 |
for path_flag in path_flags: |
+ |
72 |
if flag == path_flag: |
+ |
73 |
make_next_absolute = True |
+ |
74 |
break |
+ |
75 |
|
+ |
76 |
if flag.startswith( path_flag ): |
+ |
77 |
path = flag[ len( path_flag ): ] |
+ |
78 |
new_flag = path_flag + os.path.join( working_directory, path ) |
+ |
79 |
break |
+ |
80 |
|
+ |
81 |
if new_flag: |
+ |
82 |
new_flags.append( new_flag ) |
+ |
83 |
return new_flags |
+ |
84 |
|
+ |
85 |
|
+ |
86 |
def IsHeaderFile( filename ): |
+ |
87 |
extension = os.path.splitext( filename )[ 1 ] |
+ |
88 |
return extension in [ '.h', '.hxx', '.hpp', '.hh' ] |
+ |
89 |
|
+ |
90 |
|
+ |
91 |
def GetCompilationInfoForFile( filename ): |
+ |
92 |
# The compilation_commands.json file generated by CMake does not have entries |
+ |
93 |
# for header files. So we do our best by asking the db for flags for a |
+ |
94 |
# corresponding source file, if any. If one exists, the flags for that file |
+ |
95 |
# should be good enough. |
+ |
96 |
if IsHeaderFile( filename ): |
+ |
97 |
basename = os.path.splitext( filename )[ 0 ] |
+ |
98 |
for extension in SOURCE_EXTENSIONS: |
+ |
99 |
replacement_file = basename + extension |
+ |
100 |
if os.path.exists( replacement_file ): |
+ |
101 |
compilation_info = database.GetCompilationInfoForFile( |
+ |
102 |
replacement_file ) |
+ |
103 |
if compilation_info.compiler_flags_: |
+ |
104 |
return compilation_info |
+ |
105 |
return None |
+ |
106 |
return database.GetCompilationInfoForFile( filename ) |
+ |
107 |
|
+ |
108 |
|
+ |
109 |
def FlagsForFile( filename, **kwargs ): |
+ |
110 |
if database: |
+ |
111 |
# Bear in mind that compilation_info.compiler_flags_ does NOT return a |
+ |
112 |
# python list, but a "list-like" StringVec object |
+ |
113 |
compilation_info = GetCompilationInfoForFile( filename ) |
+ |
114 |
if not compilation_info: |
+ |
115 |
return None |
+ |
116 |
|
+ |
117 |
final_flags = MakeRelativePathsInFlagsAbsolute( |
+ |
118 |
compilation_info.compiler_flags_, |
+ |
119 |
compilation_info.compiler_working_dir_ ) |
+ |
120 |
else: |
+ |
121 |
relative_to = DirectoryOfThisScript() |
+ |
122 |
final_flags = MakeRelativePathsInFlagsAbsolute( flags, relative_to ) |
+ |
123 |
|
+ |
124 |
return { |
+ |
125 |
'flags': final_flags, |
+ |
126 |
'do_cache': True |
+ |
127 |
} |
+ |
128 |