Vim/Plug-Ins
[EXAMPLE] YouCompleteMe - .ycm_extra_conf.py
scii
2016. 3. 3. 02:25
1 # This file is NOT licensed under the GPLv3, which is the license for the rest 2 # of YouCompleteMe. 3 # 4 # Here's the license text for this file: 5 # 6 # This is free and unencumbered software released into the public domain. 7 # 8 # Anyone is free to copy, modify, publish, use, compile, sell, or 9 # distribute this software, either in source code form or as a compiled 10 # binary, for any purpose, commercial or non-commercial, and by any 11 # means. 12 # 13 # In jurisdictions that recognize copyright laws, the author or authors 14 # of this software dedicate any and all copyright interest in the 15 # software to the public domain. We make this dedication for the benefit 16 # of the public at large and to the detriment of our heirs and 17 # successors. We intend this dedication to be an overt act of 18 # relinquishment in perpetuity of all present and future rights to this 19 # software under copyright law. 20 # 21 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 22 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 23 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 24 # IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 25 # OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 26 # ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 27 # OTHER DEALINGS IN THE SOFTWARE. 28 # 29 # For more information, please refer to <http://unlicense.org/> 30 import os 31 import ycm_core 32 # These are the compilation flags that will be used in case there's no 33 # compilation database set (by default, one is not set). 34 # CHANGE THIS LIST OF FLAGS. YES, THIS IS THE DROID YOU HAVE BEEN LOOKING FOR. 35 flags = [ 36 '-x', 'c++', 37 '-Wall', 38 '-Wextra', 39 '-fPIE', 40 '-D_REENTRANT', 41 '-std=c++1y', 42 '-stdlib=libc++', 43 '-ftemplate-depth=8192', 44 '-fconstexpr-depth=8192', 45 '-lc++abi', 46 '-isystem', '/usr/include/c++/v1', 47 '-isystem', '/usr/local/include', 48 '-isystem', '/usr/include/x86_64-linux-gnu', 49 '-isystem', '/usr/include', 50 '-I', '/usr/local/src/yeppp/1.0.0/library/headers', 51 '-I', '/usr/local/src/string_view/include/experimental', 52 '-I', '/usr/local/src/scoped_resource', 53 '-I', '/usr/local/include/hpx/external', 54 '-I', '/opt/qt/5.2.2/linux/mkspecs/linux-clang-libc++', 55 '-I', '/opt/qt/5.2.2/linux/include', 56 '-I', '/opt/qt/5.2.2/linux/include/QtBluetooth', 57 '-I', '/opt/qt/5.2.2/linux/include/QtCLucene', 58 '-I', '/opt/qt/5.2.2/linux/include/QtConcurrent', 59 '-I', '/opt/qt/5.2.2/linux/include/QtCore', 60 '-I', '/opt/qt/5.2.2/linux/include/QtDBus', 61 '-I', '/opt/qt/5.2.2/linux/include/QtDeclarative', 62 '-I', '/opt/qt/5.2.2/linux/include/QtDesigner', 63 '-I', '/opt/qt/5.2.2/linux/include/QtDesignerComponents', 64 '-I', '/opt/qt/5.2.2/linux/include/QtGui', 65 '-I', '/opt/qt/5.2.2/linux/include/QtHelp', 66 '-I', '/opt/qt/5.2.2/linux/include/QtMultimedia', 67 '-I', '/opt/qt/5.2.2/linux/include/QtMultimediaQuick_p', 68 '-I', '/opt/qt/5.2.2/linux/include/QtMultimediaWidgets', 69 '-I', '/opt/qt/5.2.2/linux/include/QtNetwork', 70 '-I', '/opt/qt/5.2.2/linux/include/QtNfc', 71 '-I', '/opt/qt/5.2.2/linux/include/QtOpenGL', 72 '-I', '/opt/qt/5.2.2/linux/include/QtOpenGLExtensions', 73 '-I', '/opt/qt/5.2.2/linux/include/QtPlatformSupport', 74 '-I', '/opt/qt/5.2.2/linux/include/QtPositioning', 75 '-I', '/opt/qt/5.2.2/linux/include/QtPrintSupport', 76 '-I', '/opt/qt/5.2.2/linux/include/QtQml', 77 '-I', '/opt/qt/5.2.2/linux/include/QtQuick', 78 '-I', '/opt/qt/5.2.2/linux/include/QtQuickParticles', 79 '-I', '/opt/qt/5.2.2/linux/include/QtQuickTest', 80 '-I', '/opt/qt/5.2.2/linux/include/QtScript', 81 '-I', '/opt/qt/5.2.2/linux/include/QtScriptTools', 82 '-I', '/opt/qt/5.2.2/linux/include/QtSensors', 83 '-I', '/opt/qt/5.2.2/linux/include/QtSerialPort', 84 '-I', '/opt/qt/5.2.2/linux/include/QtSql', 85 '-I', '/opt/qt/5.2.2/linux/include/QtSvg', 86 '-I', '/opt/qt/5.2.2/linux/include/QtTest', 87 '-I', '/opt/qt/5.2.2/linux/include/QtUiTools', 88 '-I', '/opt/qt/5.2.2/linux/include/QtWebKit', 89 '-I', '/opt/qt/5.2.2/linux/include/QtWebKitWidgets', 90 '-I', '/opt/qt/5.2.2/linux/include/QtWidgets', 91 '-I', '/opt/qt/5.2.2/linux/include/QtX11Extras', 92 '-I', '/opt/qt/5.2.2/linux/include/QtXml', 93 '-I', '/opt/qt/5.2.2/linux/include/QtXmlPatterns', 94 ] 95 # Set this to the absolute path to the folder (NOT the file!) containing the 96 # compile_commands.json file to use that instead of 'flags'. See here for 97 # more details: http://clang.llvm.org/docs/JSONCompilationDatabase.html 98 # 99 # Most projects will NOT need to set this to anything; you can just change the 100 # 'flags' list of compilation flags. Notice that YCM itself uses that approach. 101 compilation_database_folder = '' 102 if os.path.exists( compilation_database_folder ): 103 database = ycm_core.CompilationDatabase( compilation_database_folder ) 104 else: 105 database = None 106 SOURCE_EXTENSIONS = [ '.cpp', '.cxx', '.cc', '.c', '.m', '.mm' ] 107 def DirectoryOfThisScript(): 108 return os.path.dirname( os.path.abspath( __file__ ) ) 109 def MakeRelativePathsInFlagsAbsolute( flags, working_directory ): 110 if not working_directory: 111 return list( flags ) 112 new_flags = [] 113 make_next_absolute = False 114 path_flags = [ '-isystem', '-I', '-iquote', '--sysroot=' ] 115 for flag in flags: 116 new_flag = flag 117 if make_next_absolute: 118 make_next_absolute = False 119 if not flag.startswith( '/' ): 120 new_flag = os.path.join( working_directory, flag ) 121 for path_flag in path_flags: 122 if flag == path_flag: 123 make_next_absolute = True 124 break 125 if flag.startswith( path_flag ): 126 path = flag[ len( path_flag ): ] 127 new_flag = path_flag + os.path.join( working_directory, path ) 128 break 129 if new_flag: 130 new_flags.append( new_flag ) 131 return new_flags 132 def IsHeaderFile( filename ): 133 extension = os.path.splitext( filename )[ 1 ] 134 return extension in [ '.h', '.hxx', '.hpp', '.hh' ] 135 def GetCompilationInfoForFile( filename ): 136 # The compilation_commands.json file generated by CMake does not have entries 137 # for header files. So we do our best by asking the db for flags for a 138 # corresponding source file, if any. If one exists, the flags for that file 139 # should be good enough. 140 if IsHeaderFile( filename ): 141 basename = os.path.splitext( filename )[ 0 ] 142 for extension in SOURCE_EXTENSIONS: 143 replacement_file = basename + extension 144 if os.path.exists( replacement_file ): 145 compilation_info = database.GetCompilationInfoForFile( 146 replacement_file ) 147 if compilation_info.compiler_flags_: 148 return compilation_info 149 return None 150 return database.GetCompilationInfoForFile( filename ) 151 def FlagsForFile( filename, **kwargs ): 152 if database: 153 # Bear in mind that compilation_info.compiler_flags_ does NOT return a 154 # python list, but a "list-like" StringVec object 155 compilation_info = GetCompilationInfoForFile( filename ) 156 if not compilation_info: 157 return None 158 final_flags = MakeRelativePathsInFlagsAbsolute( 159 compilation_info.compiler_flags_, 160 compilation_info.compiler_working_dir_ ) 161 else: 162 relative_to = DirectoryOfThisScript() 163 final_flags = MakeRelativePathsInFlagsAbsolute( flags, relative_to ) 164 return { 165 'flags': final_flags, 166 'do_cache': True 167 }