summaryrefslogtreecommitdiffstats
path: root/.ycm_extra_conf.py
diff options
context:
space:
mode:
authorDave Reisner <dreisner@archlinux.org>2014-11-16 16:51:30 -0500
committerDave Reisner <dreisner@archlinux.org>2014-11-16 16:54:30 -0500
commitc16a1cea13c70e9c40a8db82d561e71bd04f404f (patch)
tree1adf263ea9a8b1d7b2f84d0e858571a4888606f2 /.ycm_extra_conf.py
parent13145a3957ac029fc5e3f538f676c0075255822d (diff)
downloadexpac-c16a1cea13c70e9c40a8db82d561e71bd04f404f.tar.xz
Reorg a bit, introduce a control struct
Diffstat (limited to '.ycm_extra_conf.py')
-rw-r--r--.ycm_extra_conf.py85
1 files changed, 85 insertions, 0 deletions
diff --git a/.ycm_extra_conf.py b/.ycm_extra_conf.py
new file mode 100644
index 0000000..6ba1cca
--- /dev/null
+++ b/.ycm_extra_conf.py
@@ -0,0 +1,85 @@
+import os
+import ycm_core
+from clang_helpers import PrepareClangFlags
+
+# 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
+# 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 = ''
+
+# These are the compilation flags that will be used in case there's no
+# compilation database set.
+flags = [
+'-Wall',
+'-Wextra',
+'-Werror',
+'-Wno-long-long',
+'-Wno-variadic-macros',
+'-fexceptions',
+'-DNDEBUG',
+'-D_GNU_SOURCE',
+'-DUSE_CLANG_COMPLETER',
+'-std=c99',
+'-DVERSION="1"',
+]
+
+if compilation_database_folder:
+ database = ycm_core.CompilationDatabase( compilation_database_folder )
+else:
+ database = None
+
+
+def DirectoryOfThisScript():
+ return os.path.dirname( os.path.abspath( __file__ ) )
+
+
+def MakeRelativePathsInFlagsAbsolute( flags, working_directory ):
+ if not working_directory:
+ return flags
+ new_flags = []
+ make_next_absolute = False
+ path_flags = [ '-isystem', '-I', '-iquote', '--sysroot=' ]
+ for flag in flags:
+ new_flag = flag
+
+ if make_next_absolute:
+ make_next_absolute = False
+ if not flag.startswith( '/' ):
+ new_flag = os.path.join( working_directory, flag )
+
+ for path_flag in path_flags:
+ if flag == path_flag:
+ make_next_absolute = True
+ break
+
+ if flag.startswith( path_flag ):
+ path = flag[ len( path_flag ): ]
+ new_flag = path_flag + os.path.join( working_directory, path )
+ break
+
+ if new_flag:
+ new_flags.append( new_flag )
+ return new_flags
+
+
+def FlagsForFile( filename ):
+ if database:
+ # Bear in mind that compilation_info.compiler_flags_ does NOT return a
+ # python list, but a "list-like" StringVec object
+ compilation_info = database.GetCompilationInfoForFile( filename )
+ final_flags = PrepareClangFlags(
+ MakeRelativePathsInFlagsAbsolute(
+ compilation_info.compiler_flags_,
+ compilation_info.compiler_working_dir_ ),
+ filename )
+
+ else:
+ relative_to = DirectoryOfThisScript()
+ final_flags = MakeRelativePathsInFlagsAbsolute( flags, relative_to )
+
+ return {
+ 'flags': final_flags,
+ 'do_cache': True
+ }