Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import ycm_core
- DIR_OF_THIS_SCRIPT = os.path.abspath( os.path.dirname( __file__ ) )
- SOURCE_EXTENSIONS = [ '.cpp', '.cxx', '.cc', '.c', '.m', '.mm' ]
- # 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.
- flags = [ '-x', 'c', '-Wall', '-Wextra', '-Werror' ]
- # 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 = 'DIR_OF_THIS_SCRIPT'
- if os.path.exists( compilation_database_folder ):
- database = ycm_core.CompilationDatabase( compilation_database_folder )
- else:
- database = None
- def IsHeaderFile( filename ):
- extension = os.path.splitext( filename )[ 1 ]
- return extension in [ '.h', '.hxx', '.hpp', '.hh' ]
- def FindCorrespondingSourceFile( filename ):
- if IsHeaderFile( filename ):
- basename = os.path.splitext( filename )[ 0 ]
- for extension in SOURCE_EXTENSIONS:
- replacement_file = basename + extension
- if os.path.exists( replacement_file ):
- return replacement_file
- return filename
- def Settings( **kwargs ):
- if kwargs[ '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' ] )
- if not database:
- filetype = os.path.splitext( filename )[ 1 ]
- # 可以识别要补全的文件是C还是CPP文件
- filetype_change_table = {'.cpp': 'c++', '.c': 'c'}
- filetype = filetype_change_table[filetype]
- ft_idx = flags.index('-x')
- flags[ft_idx + 1] = filetype
- return {
- 'flags': flags,
- 'include_paths_relative_to_dir': DIR_OF_THIS_SCRIPT,
- 'override_filename': filename
- }
- compilation_info = database.GetCompilationInfoForFile( filename )
- if not compilation_info.compiler_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_ )
- return {
- 'flags': final_flags,
- 'include_paths_relative_to_dir': compilation_info.compiler_working_dir_,
- 'override_filename': filename
- }
- elif kwargs[ 'language' ] == 'python':
- client_data = kwargs['client_data']
- return {
- 'interpreter_path': client_data['g:ycm_python_interpreter_path'],
- 'sys_path': client_data['g:ycm_python_sys_path']
- }
- elif kwargs["language"] == "vim":
- return {
- "ls": {
- "iskeyword": "@,48-57,_,192-255,-#",
- "vimruntime": "",
- "runtimepath": "",
- "diagnostic": {"enable": True},
- }
- }
- return {}
- def GetStandardLibraryIndexInSysPath( sys_path ):
- for path in sys_path:
- if os.path.isfile( os.path.join( path, 'os.py' ) ):
- return sys_path.index( path )
- raise RuntimeError( 'Could not find standard library path in Python path.' )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement