Mercurial > vim-gutentags
diff autoload/gutentags/ctags.vim @ 202:b50b6d0f82dd
Refactor for Vim8/Neovim job support.
- Refactor all modules' `generate` methods to use a vaguely generic job API
wrapper that works for both Vim8 and Neovim jobs.
- Make the `statusline` method use new `User` autocommands driven by the
job-started/ended callbacks.
- Remove all the lock-file-related stuff.
- Better error/warning messages.
- Move a few things around.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Sat, 31 Mar 2018 18:42:54 -0700 |
parents | f7a417234dea |
children | f2fd7d5835d9 |
line wrap: on
line diff
--- a/autoload/gutentags/ctags.vim Sat Mar 31 18:35:46 2018 -0700 +++ b/autoload/gutentags/ctags.vim Sat Mar 31 18:42:54 2018 -0700 @@ -66,7 +66,9 @@ endif endfunction -function! gutentags#ctags#generate(proj_dir, tags_file, write_mode) abort +function! gutentags#ctags#generate(proj_dir, tags_file, gen_opts) abort + let l:write_mode = a:gen_opts['write_mode'] + let l:tags_file_exists = filereadable(a:tags_file) let l:tags_file_relative = fnamemodify(a:tags_file, ':.') let l:tags_file_is_local = len(l:tags_file_relative) < len(a:tags_file) @@ -74,7 +76,7 @@ if l:tags_file_exists && g:gutentags_ctags_check_tagfile let l:first_lines = readfile(a:tags_file, '', 1) if len(l:first_lines) == 0 || stridx(l:first_lines[0], '!_TAG_') != 0 - call gutentags#throwerr( + call gutentags#throw( \"File ".a:tags_file." doesn't appear to be ". \"a ctags file. Please delete it and run ". \":GutentagsUpdate!.") @@ -101,16 +103,16 @@ endif " Build the command line. - let l:cmd = gutentags#get_execute_cmd() . s:runner_exe - let l:cmd .= ' -e "' . s:get_ctags_executable(a:proj_dir) . '"' - let l:cmd .= ' -t "' . l:actual_tags_file . '"' - let l:cmd .= ' -p "' . l:actual_proj_dir . '"' - if a:write_mode == 0 && l:tags_file_exists + let l:cmd = [s:runner_exe] + let l:cmd += ['-e', '"' . s:get_ctags_executable(a:proj_dir) . '"'] + let l:cmd += ['-t', '"' . l:actual_tags_file . '"'] + let l:cmd += ['-p', '"' . l:actual_proj_dir . '"'] + if l:write_mode == 0 && l:tags_file_exists let l:cur_file_path = expand('%:p') if empty(g:gutentags_cache_dir) && l:tags_file_is_local let l:cur_file_path = fnamemodify(l:cur_file_path, ':.') endif - let l:cmd .= ' -s "' . l:cur_file_path . '"' + let l:cmd += ['-s', '"' . l:cur_file_path . '"'] else let l:file_list_cmd = gutentags#get_project_file_list_cmd(l:actual_proj_dir) if !empty(l:file_list_cmd) @@ -119,71 +121,65 @@ let l:suffoptstr = l:suffopts[1] let l:file_list_cmd = l:suffopts[0] if l:suffoptstr == 'absolute' - let l:cmd .= ' -A' + let l:cmd += ['-A'] endif endif - let l:cmd .= ' -L ' . '"' . l:file_list_cmd. '"' + let l:cmd += ['-L', '"' . l:file_list_cmd. '"'] endif endif if empty(get(l:, 'file_list_cmd', '')) " Pass the Gutentags recursive options file before the project " options file, so that users can override --recursive. " Omit --recursive if this project uses a file list command. - let l:cmd .= ' -o "' . gutentags#get_res_file('ctags_recursive.options') . '"' + let l:cmd += ['-o', '"' . gutentags#get_res_file('ctags_recursive.options') . '"'] endif if !empty(g:gutentags_ctags_extra_args) - let l:cmd .= ' -O '.shellescape(join(g:gutentags_ctags_extra_args)) + let l:cmd += ['-O', shellescape(join(g:gutentags_ctags_extra_args))] endif if !empty(g:gutentags_ctags_post_process_cmd) - let l:cmd .= ' -P '.shellescape(g:gutentags_ctags_post_process_cmd) + let l:cmd += ['-P', shellescape(g:gutentags_ctags_post_process_cmd)] endif let l:proj_options_file = a:proj_dir . '/' . \g:gutentags_ctags_options_file if filereadable(l:proj_options_file) let l:proj_options_file = s:process_options_file( \a:proj_dir, l:proj_options_file) - let l:cmd .= ' -o "' . l:proj_options_file . '"' + let l:cmd += ['-o', '"' . l:proj_options_file . '"'] endif if g:gutentags_ctags_exclude_wildignore for ign in split(&wildignore, ',') - let l:cmd .= ' -x ' . shellescape(ign, 1) + let l:cmd += ['-x', shellescape(ign, 1)] endfor endif for exc in g:gutentags_ctags_exclude - let l:cmd .= ' -x ' . '"' . exc . '"' + let l:cmd += ['-x', '"' . exc . '"'] endfor if g:gutentags_pause_after_update - let l:cmd .= ' -c' + let l:cmd += ['-c'] endif if g:gutentags_trace - if has('win32') - let l:cmd .= ' -l "' . l:actual_tags_file . '.log"' - else - let l:cmd .= ' ' . printf(s:unix_redir, '"' . l:actual_tags_file . '.log"') - endif - else - if !has('win32') - let l:cmd .= ' ' . printf(s:unix_redir, '/dev/null') - endif + let l:cmd += ['-l', '"' . l:actual_tags_file . '.log"'] endif - let l:cmd .= gutentags#get_execute_cmd_suffix() + let l:cmd = gutentags#make_args(l:cmd) - call gutentags#trace("Running: " . l:cmd) + call gutentags#trace("Running: " . string(l:cmd)) call gutentags#trace("In: " . getcwd()) if !g:gutentags_fake - " Run the background process. - if !g:gutentags_trace - silent execute l:cmd - else - execute l:cmd - endif - - " Flag this tags file as being in progress - call gutentags#add_progress('ctags', a:tags_file) + let l:job_opts = gutentags#build_default_job_options('ctags') + let l:job = gutentags#start_job(l:cmd, l:job_opts) + call gutentags#add_job('ctags', a:tags_file, l:job) else call gutentags#trace("(fake... not actually running)") endif - call gutentags#trace("") +endfunction + +function! gutentags#ctags#on_job_exit(job, exit_val) abort + call gutentags#remove_job_by_data('ctags', a:job) + + if a:exit_val != 0 + call gutentags#warning("gutentags: ctags job failed, returned: ". + \string(a:exit_val)) + endif endfunction " }}}