diff options
Diffstat (limited to 'ycm_extra_mini-conf.py')
-rw-r--r-- | ycm_extra_mini-conf.py | 138 |
1 files changed, 138 insertions, 0 deletions
diff --git a/ycm_extra_mini-conf.py b/ycm_extra_mini-conf.py new file mode 100644 index 0000000..0583c73 --- /dev/null +++ b/ycm_extra_mini-conf.py | |||
@@ -0,0 +1,138 @@ | |||
1 | # Generated by YCM Generator at 2017-02-03 00:22:04.774052 | ||
2 | |||
3 | # This file is NOT licensed under the GPLv3, which is the license for the rest | ||
4 | # of YouCompleteMe. | ||
5 | # | ||
6 | # Here's the license text for this file: | ||
7 | # | ||
8 | # This is free and unencumbered software released into the public domain. | ||
9 | # | ||
10 | # Anyone is free to copy, modify, publish, use, compile, sell, or | ||
11 | # distribute this software, either in source code form or as a compiled | ||
12 | # binary, for any purpose, commercial or non-commercial, and by any | ||
13 | # means. | ||
14 | # | ||
15 | # In jurisdictions that recognize copyright laws, the author or authors | ||
16 | # of this software dedicate any and all copyright interest in the | ||
17 | # software to the public domain. We make this dedication for the benefit | ||
18 | # of the public at large and to the detriment of our heirs and | ||
19 | # successors. We intend this dedication to be an overt act of | ||
20 | # relinquishment in perpetuity of all present and future rights to this | ||
21 | # software under copyright law. | ||
22 | # | ||
23 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
24 | # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
25 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
26 | # IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR | ||
27 | # OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, | ||
28 | # ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | ||
29 | # OTHER DEALINGS IN THE SOFTWARE. | ||
30 | # | ||
31 | # For more information, please refer to <http://unlicense.org/> | ||
32 | |||
33 | import os | ||
34 | import ycm_core | ||
35 | |||
36 | flags = [ | ||
37 | '-x', | ||
38 | 'c', | ||
39 | '-Wall', | ||
40 | ] | ||
41 | |||
42 | |||
43 | # Set this to the absolute path to the folder (NOT the file!) containing the | ||
44 | # compile_commands.json file to use that instead of 'flags'. See here for | ||
45 | # more details: http://clang.llvm.org/docs/JSONCompilationDatabase.html | ||
46 | # | ||
47 | # You can get CMake to generate this file for you by adding: | ||
48 | # set( CMAKE_EXPORT_COMPILE_COMMANDS 1 ) | ||
49 | # to your CMakeLists.txt file. | ||
50 | # | ||
51 | # Most projects will NOT need to set this to anything; you can just change the | ||
52 | # 'flags' list of compilation flags. Notice that YCM itself uses that approach. | ||
53 | compilation_database_folder = '' | ||
54 | |||
55 | if os.path.exists( compilation_database_folder ): | ||
56 | database = ycm_core.CompilationDatabase( compilation_database_folder ) | ||
57 | else: | ||
58 | database = None | ||
59 | |||
60 | SOURCE_EXTENSIONS = [ '.cpp', '.cxx', '.cc', '.c', '.m', '.mm' ] | ||
61 | |||
62 | def DirectoryOfThisScript(): | ||
63 | return os.path.dirname( os.path.abspath( __file__ ) ) | ||
64 | |||
65 | |||
66 | def MakeRelativePathsInFlagsAbsolute( flags, working_directory ): | ||
67 | if not working_directory: | ||
68 | return list( flags ) | ||
69 | new_flags = [] | ||
70 | make_next_absolute = False | ||
71 | path_flags = [ '-isystem', '-I', '-iquote', '--sysroot=' ] | ||
72 | for flag in flags: | ||
73 | new_flag = flag | ||
74 | |||
75 | if make_next_absolute: | ||
76 | make_next_absolute = False | ||
77 | if not flag.startswith( '/' ): | ||
78 | new_flag = os.path.join( working_directory, flag ) | ||
79 | |||
80 | for path_flag in path_flags: | ||
81 | if flag == path_flag: | ||
82 | make_next_absolute = True | ||
83 | break | ||
84 | |||
85 | if flag.startswith( path_flag ): | ||
86 | path = flag[ len( path_flag ): ] | ||
87 | new_flag = path_flag + os.path.join( working_directory, path ) | ||
88 | break | ||
89 | |||
90 | if new_flag: | ||
91 | new_flags.append( new_flag ) | ||
92 | return new_flags | ||
93 | |||
94 | |||
95 | def IsHeaderFile( filename ): | ||
96 | extension = os.path.splitext( filename )[ 1 ] | ||
97 | return extension in [ '.h', '.hxx', '.hpp', '.hh' ] | ||
98 | |||
99 | |||
100 | def GetCompilationInfoForFile( filename ): | ||
101 | # The compilation_commands.json file generated by CMake does not have entries | ||
102 | # for header files. So we do our best by asking the db for flags for a | ||
103 | # corresponding source file, if any. If one exists, the flags for that file | ||
104 | # should be good enough. | ||
105 | if IsHeaderFile( filename ): | ||
106 | basename = os.path.splitext( filename )[ 0 ] | ||
107 | for extension in SOURCE_EXTENSIONS: | ||
108 | replacement_file = basename + extension | ||
109 | if os.path.exists( replacement_file ): | ||
110 | compilation_info = database.GetCompilationInfoForFile( | ||
111 | replacement_file ) | ||
112 | if compilation_info.compiler_flags_: | ||
113 | return compilation_info | ||
114 | return None | ||
115 | return database.GetCompilationInfoForFile( filename ) | ||
116 | |||
117 | |||
118 | def FlagsForFile( filename, **kwargs ): | ||
119 | if database: | ||
120 | # Bear in mind that compilation_info.compiler_flags_ does NOT return a | ||
121 | # python list, but a "list-like" StringVec object | ||
122 | compilation_info = GetCompilationInfoForFile( filename ) | ||
123 | if not compilation_info: | ||
124 | return None | ||
125 | |||
126 | final_flags = MakeRelativePathsInFlagsAbsolute( | ||
127 | compilation_info.compiler_flags_, | ||
128 | compilation_info.compiler_working_dir_ ) | ||
129 | |||
130 | else: | ||
131 | relative_to = DirectoryOfThisScript() | ||
132 | final_flags = MakeRelativePathsInFlagsAbsolute( flags, relative_to ) | ||
133 | |||
134 | return { | ||
135 | 'flags': final_flags, | ||
136 | 'do_cache': True | ||
137 | } | ||
138 | |||