changeset 268:6b3ab48ea3c0

gtags support gutentags_file_list_cmd
author guangqing.chen <guangqing.chen@weride.ai>
date Tue, 06 Oct 2020 19:29:37 +0800
parents 6030953258fe
children e60f685c560d
files autoload/gutentags/gtags_cscope.vim plat/unix/update_gtags.sh
diffstat 2 files changed, 61 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/autoload/gutentags/gtags_cscope.vim	Thu May 12 09:20:21 2022 -0700
+++ b/autoload/gutentags/gtags_cscope.vim	Tue Oct 06 19:29:37 2020 +0800
@@ -31,6 +31,7 @@
 
 " 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 @@
 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: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:proj_options_file = a:proj_dir . '/' . g:gutentags_gtags_options_file
-
-    let l:cmd = ['"'.g:gutentags_gtags_executable.'"']
     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))
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/plat/unix/update_gtags.sh	Tue Oct 06 19:29:37 2020 +0800
@@ -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 <options>"
+    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."