2013-03-01 17:28:56 +01:00
|
|
|
" if compiled with --enable-cscope
|
|
|
|
if has("cscope")
|
|
|
|
if exists("g:loaded_cscope_plus") || &cp
|
2020-12-19 23:53:14 +01:00
|
|
|
finish
|
2013-03-01 17:28:56 +01:00
|
|
|
endif
|
|
|
|
|
2020-12-19 23:53:14 +01:00
|
|
|
|
2015-07-09 13:39:09 +02:00
|
|
|
set tags+=./tags " in file directory
|
|
|
|
set tags+=tags " in current directory
|
|
|
|
"for when programming in build dir
|
|
|
|
set tags+=../tags
|
|
|
|
|
2013-03-01 17:28:56 +01:00
|
|
|
function! GetLocalCscopeDb(pathname)
|
|
|
|
if !isdirectory(a:pathname) || a:pathname == $HOME || a:pathname == '/'
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
let s:cscopefile = a:pathname."/cscope.out"
|
|
|
|
if filereadable(s:cscopefile)
|
|
|
|
echo "Add cscope db for ".a:pathname
|
|
|
|
execute "cscope add ".s:cscopefile." ".a:pathname
|
|
|
|
endif
|
|
|
|
unlet s:cscopefile
|
|
|
|
call GetLocalCscopeDb(fnamemodify(a:pathname, ":h"))
|
|
|
|
endfunction
|
|
|
|
command! LoadLocalCscopeDb :call GetLocalCscopeDb(expand("%:p:h"))
|
|
|
|
|
|
|
|
function! GetCscopeDb(pathname)
|
|
|
|
if !isdirectory(a:pathname) || a:pathname == $HOME || a:pathname == '/'
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
|
|
|
let l:has_link = 0
|
|
|
|
let l:tag_found = 0
|
|
|
|
if resolve(a:pathname) != a:pathname
|
|
|
|
let l:has_link = 1
|
|
|
|
endif
|
|
|
|
|
|
|
|
let s:cscopefile = $HOME."/.vim/cscope/".substitute(a:pathname, '/', '_', 'g').".cscope"
|
|
|
|
if filereadable(s:cscopefile)
|
|
|
|
execute "cscope add ".s:cscopefile
|
|
|
|
let l:tag_found = 1
|
|
|
|
endif
|
|
|
|
|
|
|
|
if l:tag_found == 0 && l:has_link == 1
|
|
|
|
let s:cscopefile = $HOME."/.vim/cscope/".substitute(resolve(a:pathname), '/', '_', 'g').".cscope"
|
|
|
|
if filereadable(s:cscopefile)
|
|
|
|
execute "cscope add ".s:cscopefile
|
|
|
|
let l:tag_found = 1
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
|
|
|
unlet s:cscopefile
|
|
|
|
|
|
|
|
call GetCscopeDb(fnamemodify(a:pathname, ":h"))
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! GenerateCscopeDb()
|
|
|
|
let path = input('Create cscope db for: ', getcwd(), 'dir')
|
|
|
|
|
|
|
|
echohl WarningMsg
|
|
|
|
echo "Please wait, generating cscope db..."
|
|
|
|
|
|
|
|
let file = tempname()
|
|
|
|
let cscopefile = $HOME."/.vim/cscope/".substitute(path, '/', '_', 'g').".cscope"
|
|
|
|
call system("cd ".path."; find . -name '*.c' -or -name '*.h' > ".file."; cscope -b -i ".file." -f ".cscopefile)
|
|
|
|
call delete(file)
|
|
|
|
|
|
|
|
redraw
|
|
|
|
echo "Please wait, generating cscope db... Done"
|
|
|
|
echohl None
|
|
|
|
|
|
|
|
call GetCscopeDb(path)
|
|
|
|
endfunction
|
|
|
|
command! GenerateCscopeDb :call GenerateCscopeDb()
|
2021-05-30 22:32:02 +02:00
|
|
|
endif
|
2015-01-14 14:30:51 +01:00
|
|
|
" Let autotags find all cscodepeDb
|
|
|
|
" LoadLocalCscopeDb
|
|
|
|
|
2014-04-08 14:26:26 +02:00
|
|
|
"" if has("cscope")
|
|
|
|
"" map <F9> :call GetCscopeDb(expand("%:p:h")) <CR><CR>
|
|
|
|
"" map <S-F9> :call GenerateCscopeDb() <CR><CR>
|
|
|
|
"" map <M-F9> :call GetLocalCscopeDb(expand("%:p:h")) <CR><CR>
|
|
|
|
"" endif
|
2013-03-01 17:28:56 +01:00
|
|
|
|
2020-12-19 23:53:14 +01:00
|
|
|
" 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.
|
2021-10-14 14:25:57 +02:00
|
|
|
" --extra=+q : Adds context to the tag name. Note: Without this
|
2020-12-19 23:53:14 +01:00
|
|
|
" option, the script cannot get class members.
|
|
|
|
let g:build_cmd="make"
|
|
|
|
func! MenuCB(id, result)
|
|
|
|
if a:result == 1
|
2021-10-14 14:25:57 +02:00
|
|
|
silent exec "!echo '==Building ctags database==' && ctags --fields=+iaS --extra=+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 --extra=+q -aL-"
|
2020-12-19 23:53:14 +01:00
|
|
|
silent exec "!echo '==Building cscope database==' && cscope -bR"
|
|
|
|
silent "cscope reset"
|
|
|
|
silent "cscope add cscope.out"
|
|
|
|
exec 'redraw!'
|
|
|
|
elseif a:result == 2
|
2021-10-14 14:25:57 +02:00
|
|
|
silent exec "!echo '==Building ctags database==' && ctags --fields=+iaS --extra=+q --totals -R --c++-kinds=+p"
|
2020-12-19 23:53:14 +01:00
|
|
|
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
|
2022-03-09 10:13:02 +01:00
|
|
|
execute "!" . g:build_cmd . " --dry-run --always-make | grep -wE 'gcc|g++|cc|clang|clang++' | grep -w '\\-c' | jq -nR '[inputs|{directory:\".\", command:., file: match(\" [^ ]+$\").string[1:]}]' > compile_commands.json"
|
2020-12-19 23:53:14 +01:00
|
|
|
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"
|
2022-07-31 00:19:27 +02:00
|
|
|
elseif a:result == 9
|
|
|
|
execute "!make clean > /dev/null && make -nw | python ~/.vim/plugin/cdg.py "
|
|
|
|
elseif a:result == 10
|
|
|
|
echo "Add -DCMAKE_EXPORT_COMPILE_COMMANDS=ON to cmake. On modify build option with ccmake"
|
2020-12-19 23:53:14 +01:00
|
|
|
endif
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
command! ShowMenuCodeDb
|
2022-07-31 00:19:27 +02:00
|
|
|
\ :call popup_menu(['tag/csope', 'tag/cscope Kernel', 'Autotags update', 'Autotags add dependancy','simple compile_commands', 'bear', "compiledb", "analyse build", "rebuild with make parsing", "cmake option"], #{
|
2020-12-19 23:53:14 +01:00
|
|
|
\ title: "Code database for ".g:build_cmd,
|
|
|
|
\ callback: 'MenuCB', highlight: 'Question', padding: [1,1,0,1]} )
|
|
|
|
|
|
|
|
|
|
|
|
if v:version >= 800 " or 820?
|
2021-05-30 22:32:02 +02:00
|
|
|
noremap <S-F8> :ShowMenuCodeDb <CR>
|
2020-12-19 23:53:14 +01:00
|
|
|
else
|
2021-05-30 22:32:02 +02:00
|
|
|
noremap <S-F8> :call MenuCB(0, 1)<CR>
|
2013-03-01 17:28:56 +01:00
|
|
|
endif
|
2020-12-19 23:53:14 +01:00
|
|
|
map <M-F8> :call MenuCB(0, 2)<CR>
|