Skip to content

Commit 2a3faf9

Browse files
committed
Added YCM settings
1 parent 779d7e8 commit 2a3faf9

File tree

2 files changed

+94
-1
lines changed

2 files changed

+94
-1
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ bin
2424
# Temporary files
2525
.tmp.html
2626

27-
# Vim highlight files
27+
# Vim files
2828
*.taghl
29+
.ycm_extra_conf.pyc
2930

3031
# Reference files
3132
reference

.ycm_extra_conf.py

+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
import os
2+
import ycm_core
3+
4+
flags = [
5+
'-Wall',
6+
'-Wextra',
7+
'-Werror',
8+
'-pedantic',
9+
'-std=c++11',
10+
'-x',
11+
'c++',
12+
]
13+
14+
compilation_database_folder = ''
15+
16+
if os.path.exists( compilation_database_folder ):
17+
database = ycm_core.CompilationDatabase( compilation_database_folder )
18+
else:
19+
database = None
20+
21+
SOURCE_EXTENSIONS = [ '.cpp', '.cxx', '.cc', '.c', '.m', '.mm' ]
22+
23+
def DirectoryOfThisScript():
24+
return os.path.dirname( os.path.abspath( __file__ ) )
25+
26+
27+
def MakeRelativePathsInFlagsAbsolute( flags, working_directory ):
28+
if not working_directory:
29+
return list( flags )
30+
new_flags = []
31+
make_next_absolute = False
32+
path_flags = [ '-isystem', '-I', '-iquote', '--sysroot=' ]
33+
for flag in flags:
34+
new_flag = flag
35+
36+
if make_next_absolute:
37+
make_next_absolute = False
38+
if not flag.startswith( '/' ):
39+
new_flag = os.path.join( working_directory, flag )
40+
41+
for path_flag in path_flags:
42+
if flag == path_flag:
43+
make_next_absolute = True
44+
break
45+
46+
if flag.startswith( path_flag ):
47+
path = flag[ len( path_flag ): ]
48+
new_flag = path_flag + os.path.join( working_directory, path )
49+
break
50+
51+
if new_flag:
52+
new_flags.append( new_flag )
53+
return new_flags
54+
55+
56+
def IsHeaderFile( filename ):
57+
extension = os.path.splitext( filename )[ 1 ]
58+
return extension in [ '.h', '.hxx', '.hpp', '.hh' ]
59+
60+
61+
def GetCompilationInfoForFile( filename ):
62+
if IsHeaderFile( filename ):
63+
basename = os.path.splitext( filename )[ 0 ]
64+
for extension in SOURCE_EXTENSIONS:
65+
replacement_file = basename + extension
66+
if os.path.exists( replacement_file ):
67+
compilation_info = database.GetCompilationInfoForFile(
68+
replacement_file )
69+
if compilation_info.compiler_flags_:
70+
return compilation_info
71+
return None
72+
return database.GetCompilationInfoForFile( filename )
73+
74+
75+
def FlagsForFile( filename, **kwargs ):
76+
if database:
77+
compilation_info = GetCompilationInfoForFile( filename )
78+
if not compilation_info:
79+
return None
80+
81+
final_flags = MakeRelativePathsInFlagsAbsolute(
82+
compilation_info.compiler_flags_,
83+
compilation_info.compiler_working_dir_ )
84+
85+
else:
86+
relative_to = DirectoryOfThisScript()
87+
final_flags = MakeRelativePathsInFlagsAbsolute( flags, relative_to )
88+
89+
return {
90+
'flags': final_flags,
91+
'do_cache': True
92+
}

0 commit comments

Comments
 (0)