From 0149b1db117e2594c829d61d8249de86659fe6c0 Mon Sep 17 00:00:00 2001 From: Mathieu Maret Date: Sat, 19 Dec 2020 23:53:14 +0100 Subject: [PATCH] vim: Add DB building menu --- .vim/plugin/cscope_plus.vim | 86 +++++++++++++++++++++---------------- .vimrc | 6 ++- 2 files changed, 55 insertions(+), 37 deletions(-) diff --git a/.vim/plugin/cscope_plus.vim b/.vim/plugin/cscope_plus.vim index f114006..273fb49 100644 --- a/.vim/plugin/cscope_plus.vim +++ b/.vim/plugin/cscope_plus.vim @@ -1,44 +1,9 @@ " if compiled with --enable-cscope if has("cscope") if exists("g:loaded_cscope_plus") || &cp - finish + finish 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 :CtagsBuild:CscopeBuild:cscope reset:cscope add cscope.out - map :CtagsKernelBuild:CscopeKernelBuild:cscope reset:cscope add cscope.out - else - map :CtagsBuild - map :CtagsKernelBuild - endif set tags+=./tags " in file directory set tags+=tags " in current directory @@ -117,4 +82,53 @@ if has("cscope") "" map :call GetLocalCscopeDb(expand("%:p:h")) "" 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 +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 :ShowMenuCodeDb +else + map :call MenuCB(0, 1) +endif +map :call MenuCB(0, 2) diff --git a/.vimrc b/.vimrc index fe02418..8874db6 100644 --- a/.vimrc +++ b/.vimrc @@ -2,6 +2,7 @@ " SHORTCUTS " """"""""""""" " F1 help +" S-F1 open vimrc " F2 open file in a new tab " S-F2 Split and open file " F3 autotags Update @@ -11,7 +12,7 @@ " F6 go to definition " F7 go to calls " F8 view tag list -" S-F8 build ctags/cscope databases +" S-F8 Open DB building menu " M-F8 build kernel ctags/cscope databases " F9 Open NerdTree " M-F9 Show diff line @@ -593,6 +594,9 @@ nnoremap O :FZF! if v:version >= 800 " Async lint "Plugin 'w0rp/ale' + let g:ale_fixers = { + \ '*': ['remove_trailing_lines', 'trim_whitespace'], + \} Plugin 'autozimu/LanguageClient-neovim', { \ 'oninstall': 'bash install.sh', \ }