forked from leka/LekaOS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.ycm_extra_conf.py
106 lines (84 loc) · 3.48 KB
/
.ycm_extra_conf.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
from distutils.sysconfig import get_python_inc
import platform
import os.path as p
import subprocess
DIR_OF_THIS_SCRIPT = p.abspath( p.dirname( __file__ ) )
SOURCE_EXTENSIONS = [ '.cpp', '.c' ]
database = None
# These are the compilation flags that will be used in case there's no
# compilation database set (by default, one is not set).
# CHANGE THIS LIST OF FLAGS. YES, THIS IS THE DROID YOU HAVE BEEN LOOKING FOR.
system_flags = [
# '-nostdinc++',
# '-nostdinc',
# '-nobuiltininc'
]
flags = [
'-isystem/usr/local/Cellar/arm-gcc-bin/9-2020-q2-update/arm-none-eabi/include',
# '-isystem/usr/local/Cellar/arm-gcc-bin/9-2020-q2-update/arm-none-eabi/include/c++/9.3.1'
# '-isystem/usr/local/Cellar/arm-gcc-bin/9-2020-q2-update/arm-none-eabi/include/c++/9.3.1/arm-none-eabi/bits'
]
# Set this to the absolute path to the folder (NOT the file!) containing the
# compile_commands.json file to use that instead of 'flags'. See here for
# more details: http://clang.llvm.org/docs/JSONCompilationDatabase.html
#
# You can get CMake to generate this file for you by adding:
# set( CMAKE_EXPORT_COMPILE_COMMANDS 1 )
# to your CMakeLists.txt file.
#
# Most projects will NOT need to set this to anything; you can just change the
# 'flags' list of compilation flags. Notice that YCM itself uses that approach.
compilation_database_folder = '/Users/ladislas/dev/leka/LekaOS/build'
def IsHeaderFile( filename ):
extension = p.splitext( filename )[ 1 ]
return extension in [ '.h' ]
def FindCorrespondingSourceFile( filename ):
if IsHeaderFile( filename ):
basename = p.splitext( filename )[ 0 ]
for extension in SOURCE_EXTENSIONS:
replacement_file = basename + extension
if p.exists( replacement_file ):
return replacement_file
return filename
def Settings( **kwargs ):
# Do NOT import ycm_core at module scope.
import ycm_core
global database
if database is None and p.exists( compilation_database_folder ):
database = ycm_core.CompilationDatabase( compilation_database_folder )
print("db found")
print(database)
language = kwargs[ 'language' ]
if language == 'cfamily':
# If the file is a header, try to find the corresponding source file and
# retrieve its flags from the compilation database if using one. This is
# necessary since compilation databases don't have entries for header files.
# In addition, use this source file as the translation unit. This makes it
# possible to jump from a declaration in the header file to its definition
# in the corresponding source file.
filename = FindCorrespondingSourceFile( kwargs[ 'filename' ] )
print(f"filename {filename}")
if not database:
print("not database :(")
return {
'flags': flags,
'include_paths_relative_to_dir': DIR_OF_THIS_SCRIPT,
'override_filename': filename
}
compilation_info = database.GetCompilationInfoForFile( filename )
print(f"compilation info: {compilation_info}")
if not compilation_info.compiler_flags_:
print("no flags :(")
return {}
# Bear in mind that compilation_info.compiler_flags_ does NOT return a
# python list, but a "list-like" StringVec object.
final_flags = list( compilation_info.compiler_flags_ )
print(final_flags)
return_value = {
'flags': system_flags + final_flags + flags,
'include_paths_relative_to_dir': compilation_info.compiler_working_dir_,
'override_filename': filename
}
# print(return_value)
return return_value
return {}