From 39dc3ee228bb7cc712d95b0130c233451381e3da Mon Sep 17 00:00:00 2001 From: "guangqing.chen" Date: Tue, 6 Oct 2020 19:29:37 +0800 Subject: [PATCH] gtags support gutentags_file_list_cmd --- autoload/gutentags/gtags_cscope.vim | 18 ++++++++--- plat/unix/update_gtags.sh | 48 +++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 5 deletions(-) create mode 100644 plat/unix/update_gtags.sh diff --git a/autoload/gutentags/gtags_cscope.vim b/autoload/gutentags/gtags_cscope.vim index 3e7aabb..6a72243 100644 --- a/autoload/gutentags/gtags_cscope.vim +++ b/autoload/gutentags/gtags_cscope.vim @@ -31,6 +31,7 @@ endif " Gutentags Module Interface {{{ +let s:runner_exe = gutentags#get_plat_file('update_gtags') let s:added_db_files = {} function! s:add_db(db_file) abort @@ -77,18 +78,25 @@ function! gutentags#gtags_cscope#init(project_root) abort endfunction function! gutentags#gtags_cscope#generate(proj_dir, tags_file, gen_opts) abort - " gtags doesn't honour GTAGSDBPATH and GTAGSROOT, so PWD and dbpath - " have to be set - let l:db_path = fnamemodify(a:tags_file, ':p:h') + let l:cmd = [s:runner_exe] + let l:cmd += ['-e', '"' . g:gutentags_gtags_executable . '"'] - let l:proj_options_file = a:proj_dir . '/' . g:gutentags_gtags_options_file + let l:file_list_cmd = gutentags#get_project_file_list_cmd(a:proj_dir) + if !empty(l:file_list_cmd) + let l:cmd += ['-L', '"' . l:file_list_cmd . '"'] + endif - let l:cmd = ['"'.g:gutentags_gtags_executable.'"'] + let l:proj_options_file = a:proj_dir . '/' . g:gutentags_gtags_options_file if filereadable(l:proj_options_file) let l:proj_options = readfile(l:proj_options_file) let l:cmd += l:proj_options endif + + " gtags doesn't honour GTAGSDBPATH and GTAGSROOT, so PWD and dbpath + " have to be set + let l:db_path = fnamemodify(a:tags_file, ':p:h') let l:cmd += ['--incremental', '"'.l:db_path.'"'] + let l:cmd = gutentags#make_args(l:cmd) call gutentags#trace("Running: " . string(l:cmd)) diff --git a/plat/unix/update_gtags.sh b/plat/unix/update_gtags.sh new file mode 100644 index 0000000..0d2d2ec --- /dev/null +++ b/plat/unix/update_gtags.sh @@ -0,0 +1,48 @@ +#!/usr/bin/env bash + +set -e + +PROG_NAME=$0 +GTAGS_EXE=gtags +FILE_LIST_CMD= + +ShowUsage() { + echo "Usage:" + echo " $PROG_NAME " + echo "" + echo " -e [exe=gtags]: The gtags executable to run." + echo " -L [cmd=]: The file list command to run." + echo "" +} + +while [[ $# -ne 0 ]]; do + case "$1" in + -h) + ShowUsage + exit 0 + ;; + -e) + GTAGS_EXE=$2 + shift 2 + ;; + -L) + FILE_LIST_CMD=$2 + shift 2 + ;; + *) + GTAGS_ARGS="$GTAGS_ARGS $1" + shift + ;; + esac +done + +if [ -n "$FILE_LIST_CMD" ]; then + CMD="$FILE_LIST_CMD | $GTAGS_EXE -f- $GTAGS_ARGS" +else + CMD="$GTAGS_EXE $GTAGS_ARGS" +fi + +echo "Running gtags:" +echo "$CMD" +eval "$CMD" +echo "Done."