From fd8cffda09799e736c0b146a55807cf4a58c3412 Mon Sep 17 00:00:00 2001 From: wsdjeg Date: Tue, 5 Apr 2022 12:19:26 +0800 Subject: [PATCH] feat(ctags): use `-G` option when generate tags ref: https://github.com/SpaceVim/SpaceVim/issues/4619 --- bundle/gtags.vim/autoload/ctags.vim | 31 ++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/bundle/gtags.vim/autoload/ctags.vim b/bundle/gtags.vim/autoload/ctags.vim index 466c137c2..96f717520 100644 --- a/bundle/gtags.vim/autoload/ctags.vim +++ b/bundle/gtags.vim/autoload/ctags.vim @@ -24,12 +24,41 @@ let s:FILE = SpaceVim#api#import('file') let g:loaded_ctags = 1 -function! ctags#update() abort +let s:is_u_ctags = 0 +let s:version_checked = 0 +function! s:version_std_out(id, data, event) abort + for line in a:data + if line =~# 'Universal Ctags' + let s:is_u_ctags = 1 + break + endif + endfor +endfunction + +function! s:version_exit(id, data, event) abort + if a:data ==# 0 + let s:version_checked = 1 + call ctags#update() + endif +endfunction + + +function! ctags#update(...) abort + if !s:version_checked + call s:JOB.start(['ctags', '--version'], { + \ 'on_stdout': funcref('s:version_std_out'), + \ 'on_exit': funcref('s:version_exit'), + \ }) + return + endif let project_root = getcwd() call s:LOGGER.info('update ctags database for ' . project_root) let dir = s:FILE.unify_path(g:tags_cache_dir) \ . s:FILE.path_to_fname(project_root) let cmd = ['ctags'] + if s:is_u_ctags + let cmd += ['-G'] + endif if !isdirectory(dir) call mkdir(dir, 'p') endif