Skip to content

Commit b31eb0b

Browse files
author
Sebastian Lauwers
committed
Add good default YouCompleteMe configuration file
1 parent d1d194f commit b31eb0b

File tree

2 files changed

+134
-0
lines changed

2 files changed

+134
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,6 @@ Static library*/
8585
/debian/debhelper.log
8686
/debian/librealm.debhelper.lo
8787
/debian/librealm-dev.debhelper.log
88+
89+
# Ignore python compiled files
90+
*.pyc

.ycm_extra_conf.py

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

0 commit comments

Comments
 (0)