vim: Add DB building menu

This commit is contained in:
Mathieu Maret 2020-12-19 23:53:14 +01:00
parent aae2869c59
commit 0149b1db11
2 changed files with 55 additions and 37 deletions

View File

@ -3,42 +3,7 @@ if has("cscope")
if exists("g:loaded_cscope_plus") || &cp if exists("g:loaded_cscope_plus") || &cp
finish finish
endif endif
let g:loaded_cscope_plus = 1.0
" cat Makefile | grep '\-I\/' | tr '[:space:]' '\n' | grep '\-I/' | sort -u | tr '\n' ' '
" build tags database with shift+F8 or alt+F8 to ignore /usr/include
" --c++-kinds=+p : Adds prototypes in the database for C/C++ files.
" --fields=+iaS : Adds inheritance (i), access (a) and function
" signatures (S) information.
" --extra=+q : Adds context to the tag name. Note: Without this
" option, the script cannot get class members.
command! CtagsBuild
\ :!echo 'building ctags database...' ;
\ ctags --fields=+iaS --extra=+q --totals -R --c++-kinds=+p &&
\ echo 'adding system headers...' ;
\ find -exec gcc -M '{}' \; 2>&- | tr '[:space:]' '\n' | grep '^/.*' | sort -u |
\ ctags --c-kinds=+px --c++-kinds=+px --fields=+iaS --extra=+q -aL-
command! CtagsKernelBuild
\ :!echo 'building ctags database in kernel mode...' ;
\ ctags --fields=+iaS --extra=+q --totals -R --c++-kinds=+p
command! CscopeBuild
\ :!echo 'building cscope database...' ;
\ cscope -bR
command! CscopeKernelBuild
\ :!echo 'building cscope database in kernel mode...' ;
\ cscope -bkR
command! CscopeFileBuild
\ :!echo 'building cscope database for all language';
\ find . -name '*.py' -o -name '*.java' -o -iname '*.[ch]' -o -name '[*.cpp]' -o -name '[*.hpp]' | grep -v 'moc_' > cscope.files
if has("cscope")
map <S-F8> :CtagsBuild<CR><CR>:CscopeBuild<CR><CR>:cscope reset<CR><CR>:cscope add cscope.out<CR><CR>
map <M-F8> :CtagsKernelBuild<CR><CR>:CscopeKernelBuild<CR><CR>:cscope reset<CR><CR>:cscope add cscope.out<CR><CR>
else
map <S-F8> :CtagsBuild<CR><CR>
map <M-F8> :CtagsKernelBuild<CR><CR>
endif
set tags+=./tags " in file directory set tags+=./tags " in file directory
set tags+=tags " in current directory set tags+=tags " in current directory
@ -117,4 +82,53 @@ if has("cscope")
"" map <M-F9> :call GetLocalCscopeDb(expand("%:p:h")) <CR><CR> "" map <M-F9> :call GetLocalCscopeDb(expand("%:p:h")) <CR><CR>
"" endif "" endif
" cat Makefile | grep '\-I\/' | tr '[:space:]' '\n' | grep '\-I/' | sort -u | tr '\n' ' '
" build tags database with shift+F8 or alt+F8 to ignore /usr/include
" --c++-kinds=+p : Adds prototypes in the database for C/C++ files.
" --fields=+iaS : Adds inheritance (i), access (a) and function
" signatures (S) information.
" --extras=+q : Adds context to the tag name. Note: Without this
" option, the script cannot get class members.
let g:build_cmd="make"
func! MenuCB(id, result)
if a:result == 1
silent exec "!echo '==Building ctags database==' && ctags --fields=+iaS --extras=+q --totals -R --c++-kinds=+p --exclude=.ccls-cache"
silent exec "!echo '==Adding system headers==' && find -exec gcc -M '{}' \\; 2>&- | tr '[:space:]' '\\n' | grep '^/.*' | sort -u | ctags --c-kinds=+px --c++-kinds=+px --fields=+iaS --extras=+q -aL-"
silent exec "!echo '==Building cscope database==' && cscope -bR"
silent "cscope reset"
silent "cscope add cscope.out"
exec 'redraw!'
elseif a:result == 2
silent exec "!echo '==Building ctags database==' && ctags --fields=+iaS --extras=+q --totals -R --c++-kinds=+p"
silent exec "!echo '==Building cscope database==' && cscope -bkR"
silent "cscope reset"
silent "cscope add cscope.out"
exec 'redraw!'
elseif a:result == 3
call AutotagsUpdate()
elseif a:result == 4
call AutotagsAdd()
elseif a:result == 5
execute "!" . g:build_cmd . " --dry-run --always-make | grep -wE 'gcc|g++|cc' | grep -w '\\-c' | jq -nR '[inputs|{directory:\".\", command:., file: match(\" [^ ]+$\").string[1:]}]' > compile_commands.json"
elseif a:result == 6 "https://github.com/rizsotto/Bear
execute "!bear --" g:build_cmd "--always-make"
elseif a:result == 7 "https://github.com/nickdiego/compiledb
execute "!compiledb -n" g:build_cmd
elseif a:result == 8 "https://github.com/rizsotto/scan-build
execute "!analyze-build"
endif endif
endfunc
command! ShowMenuCodeDb
\ :call popup_menu(['tag/csope', 'tag/cscope Kernel', 'Autotags update', 'Autotags add dependancy','simple compile_commands', 'bear', "compiledb", "analyse build"], #{
\ title: "Code database for ".g:build_cmd,
\ callback: 'MenuCB', highlight: 'Question', padding: [1,1,0,1]} )
endif
if v:version >= 800 " or 820?
map <S-F8> :ShowMenuCodeDb <CR>
else
map <S-F8> :call MenuCB(0, 1)<CR>
endif
map <M-F8> :call MenuCB(0, 2)<CR>

6
.vimrc
View File

@ -2,6 +2,7 @@
" SHORTCUTS " " SHORTCUTS "
""""""""""""" """""""""""""
" F1 help " F1 help
" S-F1 open vimrc
" F2 open file in a new tab " F2 open file in a new tab
" S-F2 Split and open file " S-F2 Split and open file
" F3 autotags Update " F3 autotags Update
@ -11,7 +12,7 @@
" F6 go to definition " F6 go to definition
" F7 go to calls " F7 go to calls
" F8 view tag list " F8 view tag list
" S-F8 build ctags/cscope databases " S-F8 Open DB building menu
" M-F8 build kernel ctags/cscope databases " M-F8 build kernel ctags/cscope databases
" F9 Open NerdTree " F9 Open NerdTree
" M-F9 Show diff line " M-F9 Show diff line
@ -593,6 +594,9 @@ nnoremap <silent> <leader>O :FZF!<CR>
if v:version >= 800 if v:version >= 800
" Async lint " Async lint
"Plugin 'w0rp/ale' "Plugin 'w0rp/ale'
let g:ale_fixers = {
\ '*': ['remove_trailing_lines', 'trim_whitespace'],
\}
Plugin 'autozimu/LanguageClient-neovim', { Plugin 'autozimu/LanguageClient-neovim', {
\ 'oninstall': 'bash install.sh', \ 'oninstall': 'bash install.sh',
\ } \ }