mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-03-13 02:05:40 +08:00
fix gtags completion and list project files (#4209)
* fix gtags completion and list project files * gtags: use cgetexpr instead of cexpr! if there's multiple results * gtags: set $GTAGSDBPATH for completion
This commit is contained in:
parent
9f6faa4011
commit
bbac004900
@ -26,7 +26,7 @@ function! SpaceVim#layers#gtags#config() abort
|
|||||||
let g:_spacevim_mappings_space.m.g = {'name' : '+gtags'}
|
let g:_spacevim_mappings_space.m.g = {'name' : '+gtags'}
|
||||||
call SpaceVim#mapping#space#def('nnoremap', ['m', 'g', 'c'], 'GtagsGenerate!', 'create-a-gtags-database', 1)
|
call SpaceVim#mapping#space#def('nnoremap', ['m', 'g', 'c'], 'GtagsGenerate!', 'create-a-gtags-database', 1)
|
||||||
call SpaceVim#mapping#space#def('nnoremap', ['m', 'g', 'u'], 'GtagsGenerate', 'update-tag-database', 1)
|
call SpaceVim#mapping#space#def('nnoremap', ['m', 'g', 'u'], 'GtagsGenerate', 'update-tag-database', 1)
|
||||||
call SpaceVim#mapping#space#def('nnoremap', ['m', 'g', 'p'], 'Gtags -p', 'list-all-file-in-GTAGS', 1)
|
call SpaceVim#mapping#space#def('nnoremap', ['m', 'g', 'p'], 'Gtags -P', 'list-all-file-in-GTAGS', 1)
|
||||||
call SpaceVim#mapping#space#def('nnoremap', ['m', 'g', 'd'], 'exe "Gtags -d " . expand("<cword>")', 'find-definitions', 1)
|
call SpaceVim#mapping#space#def('nnoremap', ['m', 'g', 'd'], 'exe "Gtags -d " . expand("<cword>")', 'find-definitions', 1)
|
||||||
call SpaceVim#mapping#space#def('nnoremap', ['m', 'g', 'r'], 'exe "Gtags -r " . expand("<cword>")', 'find-references', 1)
|
call SpaceVim#mapping#space#def('nnoremap', ['m', 'g', 'r'], 'exe "Gtags -r " . expand("<cword>")', 'find-references', 1)
|
||||||
call SpaceVim#mapping#space#def('nnoremap', ['m', 'g', 's'], 'exe "Gtags -s " . expand("<cword>")', 'find-cursor-symbol', 1)
|
call SpaceVim#mapping#space#def('nnoremap', ['m', 'g', 's'], 'exe "Gtags -s " . expand("<cword>")', 'find-cursor-symbol', 1)
|
||||||
|
@ -212,6 +212,34 @@ function! s:TrimOption(option) abort
|
|||||||
return l:option
|
return l:option
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! s:ExecGlobal(cmd) abort
|
||||||
|
let l:restore_gtagsroot = 0
|
||||||
|
if empty($GTAGSROOT)
|
||||||
|
let $GTAGSROOT = SpaceVim#plugins#projectmanager#current_root()
|
||||||
|
let l:restore_gtagsroot = 1
|
||||||
|
endif
|
||||||
|
|
||||||
|
let l:restore_gtagsdbpath = 0
|
||||||
|
if empty($GTAGSDBPATH)
|
||||||
|
let $GTAGSDBPATH = s:FILE.unify_path(g:tags_cache_dir) . s:FILE.path_to_fname($GTAGSROOT)
|
||||||
|
let l:restore_gtagsdbpath = 1
|
||||||
|
endif
|
||||||
|
|
||||||
|
let l:result = system(a:cmd)
|
||||||
|
|
||||||
|
" restore $GTAGSROOT and $GTAGSDBPATH to make it possible to switch
|
||||||
|
" between multiple projects or parent/child projects
|
||||||
|
if l:restore_gtagsroot
|
||||||
|
let $GTAGSROOT = ''
|
||||||
|
endif
|
||||||
|
|
||||||
|
if l:restore_gtagsdbpath
|
||||||
|
let $GTAGSDBPATH = ''
|
||||||
|
endif
|
||||||
|
|
||||||
|
return l:result
|
||||||
|
endfunction
|
||||||
|
|
||||||
"
|
"
|
||||||
" Execute global and load the result into quickfix window.
|
" Execute global and load the result into quickfix window.
|
||||||
"
|
"
|
||||||
@ -242,31 +270,8 @@ function! s:ExecLoad(option, long_option, pattern) abort
|
|||||||
let l:cmd = g:gtags_global_command . ' ' . l:option . 'e ' . g:Gtags_Shell_Quote_Char . a:pattern . g:Gtags_Shell_Quote_Char
|
let l:cmd = g:gtags_global_command . ' ' . l:option . 'e ' . g:Gtags_Shell_Quote_Char . a:pattern . g:Gtags_Shell_Quote_Char
|
||||||
endif
|
endif
|
||||||
|
|
||||||
let l:restore_gtagsroot = 0
|
let l:result = s:ExecGlobal(l:cmd)
|
||||||
if empty($GTAGSROOT)
|
|
||||||
let $GTAGSROOT = SpaceVim#plugins#projectmanager#current_root()
|
|
||||||
let l:restore_gtagsroot = 1
|
|
||||||
endif
|
|
||||||
|
|
||||||
let l:restore_gtagsdbpath = 0
|
|
||||||
if empty($GTAGSDBPATH)
|
|
||||||
let $GTAGSDBPATH = s:FILE.unify_path(g:tags_cache_dir) . s:FILE.path_to_fname($GTAGSROOT)
|
|
||||||
let l:restore_gtagsdbpath = 1
|
|
||||||
endif
|
|
||||||
|
|
||||||
let l:result = system(l:cmd)
|
|
||||||
|
|
||||||
" restore $GTAGSROOT and $GTAGSDBPATH to make it possible to switch
|
|
||||||
" between multiple projects or parent/child projects
|
|
||||||
if l:restore_gtagsroot
|
|
||||||
let $GTAGSROOT = ''
|
|
||||||
endif
|
|
||||||
|
|
||||||
if l:restore_gtagsdbpath
|
|
||||||
let $GTAGSDBPATH = ''
|
|
||||||
endif
|
|
||||||
|
|
||||||
e
|
|
||||||
if v:shell_error != 0
|
if v:shell_error != 0
|
||||||
if v:shell_error == 2
|
if v:shell_error == 2
|
||||||
call s:Error('invalid arguments. (gtags.vim requires GLOBAL 5.7 or later)')
|
call s:Error('invalid arguments. (gtags.vim requires GLOBAL 5.7 or later)')
|
||||||
@ -303,7 +308,11 @@ function! s:ExecLoad(option, long_option, pattern) abort
|
|||||||
" Parse the output of 'global -x or -t' and show in the quickfix window.
|
" Parse the output of 'global -x or -t' and show in the quickfix window.
|
||||||
let l:efm_org = &efm
|
let l:efm_org = &efm
|
||||||
let &efm = g:Gtags_Efm
|
let &efm = g:Gtags_Efm
|
||||||
cexpr! l:result
|
if l:result =~# '\n.'
|
||||||
|
cgetexpr l:result
|
||||||
|
else
|
||||||
|
cexpr! l:result
|
||||||
|
endif
|
||||||
let &efm = l:efm_org
|
let &efm = l:efm_org
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
@ -357,7 +366,7 @@ function! gtags#global(line) abort
|
|||||||
if l:option =~# 'f'
|
if l:option =~# 'f'
|
||||||
let l:line = input('Gtags for file: ', expand('%'), 'file')
|
let l:line = input('Gtags for file: ', expand('%'), 'file')
|
||||||
else
|
else
|
||||||
let l:line = input('Gtags for pattern: ', expand('<cword>'), 'custom,GtagsCandidateCore')
|
let l:line = input('Gtags for pattern: ', expand('<cword>'), 'custom,gtags#complete')
|
||||||
endif
|
endif
|
||||||
let l:pattern = s:Extract(l:line, 'pattern')
|
let l:pattern = s:Extract(l:line, 'pattern')
|
||||||
if l:pattern ==# ''
|
if l:pattern ==# ''
|
||||||
@ -429,7 +438,7 @@ function! s:GtagsCandidateCore(lead, ...) abort
|
|||||||
endif
|
endif
|
||||||
return glob(l:pattern)
|
return glob(l:pattern)
|
||||||
else
|
else
|
||||||
let l:cands = system(g:gtags_global_command . ' ' . '-c' . s:option . ' ' . a:lead)
|
let l:cands = s:ExecGlobal(g:gtags_global_command . ' ' . '-c' . s:option . ' ' . a:lead)
|
||||||
if v:shell_error == 0
|
if v:shell_error == 0
|
||||||
return l:cands
|
return l:cands
|
||||||
endif
|
endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user