diff options
author | Tuowen Zhao <ztuowen@gmail.com> | 2020-01-21 12:18:56 -0700 |
---|---|---|
committer | Tuowen Zhao <ztuowen@gmail.com> | 2020-01-21 12:18:56 -0700 |
commit | 4d7f3144bafc7239b12768773b3776b6167e840a (patch) | |
tree | 209272ebaf3d65930263608dd2617b3de7333e4f | |
parent | bc73cb6be2d962723c0747fbd017f39e9c75675b (diff) | |
download | vim-4d7f3144bafc7239b12768773b3776b6167e840a.tar.gz vim-4d7f3144bafc7239b12768773b3776b6167e840a.tar.bz2 vim-4d7f3144bafc7239b12768773b3776b6167e840a.zip |
Fix completion database
-rw-r--r-- | config/ycm.vim | 4 | ||||
-rw-r--r-- | misc/ycm_conf.py | 54 | ||||
-rw-r--r-- | vimrc | 1 |
3 files changed, 58 insertions, 1 deletions
diff --git a/config/ycm.vim b/config/ycm.vim new file mode 100644 index 0000000..ca476c6 --- /dev/null +++ b/config/ycm.vim @@ -0,0 +1,4 @@ +let g:ycm_use_clangd = 0 +let $VIMHOME=expand('<sfile>:p:h:h') +let g:ycm_global_ycm_extra_conf = expand('<sfile>:p:h:h').'/misc/ycm_conf.py' +let g:ycm_confirm_extra_conf = 1 diff --git a/misc/ycm_conf.py b/misc/ycm_conf.py new file mode 100644 index 0000000..fe46ed2 --- /dev/null +++ b/misc/ycm_conf.py @@ -0,0 +1,54 @@ +import platform +import os + +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 = [ +'-Wall', +'-Wextra', +'-Werror', +'-Wno-long-long', +'-Wno-variadic-macros', +'-fexceptions', +'-DNDEBUG', +# THIS IS IMPORTANT! Without the '-x' flag, Clang won't know which language to +# use when compiling headers. So it will guess. Badly. So C++ headers will be +# compiled as C headers. You don't want that so ALWAYS specify the '-x' flag. +# For a C project, you would set this to 'c' instead of 'c++'. +'-x', +'c++', +] + +# Clang automatically sets the '-std=' flag to 'c++14' for MSVC 2015 or later, +# which is required for compiling the standard library, and to 'c++11' for older +# versions. +if platform.system() != 'Windows': + flags.append( '-std=c++14' ) + +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': + filename = FindCorrespondingSourceFile( kwargs[ 'filename' ] ) + return { + 'flags': flags, + 'include_paths_relative_to_dir': DIR_OF_THIS_SCRIPT, + 'override_filename': filename + } + return {} @@ -1,5 +1,4 @@ let g:airline_powerline_fonts=1 -let g:ycm_use_clangd = 0 set laststatus=2 " set UTF-8 encoding |