changeset 239:ac9adbec887b

Add `g:gutentags_cscope_build_inverted_index` option
author Chayoung You <yousbe@gmail.com>
date Wed, 19 Dec 2018 20:49:22 +0900
parents 2b6af9ef5666
children 157853e84d27
files autoload/gutentags/cscope.vim doc/gutentags.txt plat/unix/update_scopedb.sh plat/win32/update_scopedb.cmd
diffstat 4 files changed, 40 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/autoload/gutentags/cscope.vim	Wed Dec 19 20:48:34 2018 +0900
+++ b/autoload/gutentags/cscope.vim	Wed Dec 19 20:49:22 2018 +0900
@@ -19,6 +19,10 @@
     let g:gutentags_auto_add_cscope = 1
 endif
 
+if !exists('g:gutentags_cscope_build_inverted_index')
+    let g:gutentags_cscope_build_inverted_index = 0
+endif
+
 " }}}
 
 " Gutentags Module Interface {{{
@@ -50,6 +54,9 @@
     if !empty(l:file_list_cmd)
         let l:cmd += ['-L', '"' . l:file_list_cmd . '"']
     endif
+    if g:gutentags_cscope_build_inverted_index
+        let l:cmd += ['-I']
+    endif
     let l:cmd = gutentags#make_args(l:cmd)
 
     call gutentags#trace("Running: " . string(l:cmd))
--- a/doc/gutentags.txt	Wed Dec 19 20:48:34 2018 +0900
+++ b/doc/gutentags.txt	Wed Dec 19 20:49:22 2018 +0900
@@ -643,6 +643,12 @@
                         (see |:cscope|).
                         Defaults to 1.
 
+                                                *gutentags_cscope_build_inverted_index*
+g:gutentags_cscope_build_inverted_index
+                        If set to 1, Gutentags will make `cscope` build an
+                        inverted index.
+                        Defaults to 0.
+
 
 The following settings are valid for the `gtags_cscope` module.
 
--- a/plat/unix/update_scopedb.sh	Wed Dec 19 20:48:34 2018 +0900
+++ b/plat/unix/update_scopedb.sh	Wed Dec 19 20:49:22 2018 +0900
@@ -8,6 +8,7 @@
 DB_FILE=cscope.out
 PROJECT_ROOT=
 FILE_LIST_CMD=
+BUILD_INVERTED_INDEX=0
 
 ShowUsage() {
     echo "Usage:"
@@ -17,11 +18,12 @@
     echo "    -f [file=cscope.out]: The path to the ctags file to update"
     echo "    -p [dir=]:            The path to the project root"
     echo "    -L [cmd=]:            The file list command to run"
+    echo "    -I:                   Builds an inverted index"
     echo ""
 }
 
 
-while getopts "h?e:f:p:L:" opt; do
+while getopts "h?e:f:p:L:I" opt; do
     case $opt in
         h|\?)
             ShowUsage
@@ -39,6 +41,9 @@
         L)
             FILE_LIST_CMD=$OPTARG
             ;;
+        I)
+            BUILD_INVERTED_INDEX=1
+            ;;
     esac
 done
 
@@ -53,7 +58,14 @@
 echo $$ > "$DB_FILE.lock"
 
 # Remove lock and temp file if script is stopped unexpectedly.
-trap 'rm -f "$DB_FILE.lock" "$DB_FILE.files" "$DB_FILE.temp"' INT QUIT TERM EXIT
+CleanUp() {
+    rm -f "$DB_FILE.lock" "$DB_FILE.files" "$DB_FILE.temp"
+    if [ "$BUILD_INVERTED_INDEX" -eq 1 ]; then
+        rm -f "$DB_FILE.temp.in" "$DB_FILE.temp.po"
+    fi
+}
+
+trap CleanUp INT QUIT TERM EXIT
 
 PREVIOUS_DIR=$(pwd)
 if [ -d "$PROJECT_ROOT" ]; then
@@ -74,6 +86,10 @@
 fi
 CSCOPE_ARGS="${CSCOPE_ARGS} -i ${DB_FILE}.files"
 
+if [ "$BUILD_INVERTED_INDEX" -eq 1 ]; then
+    CSCOPE_ARGS="$CSCOPE_ARGS -q"
+fi
+
 echo "Running cscope"
 echo "$CSCOPE_EXE $CSCOPE_ARGS -b -k -f \"$DB_FILE.temp\""
 "$CSCOPE_EXE" $CSCOPE_ARGS -v -b -k -f "$DB_FILE.temp"
@@ -83,6 +99,12 @@
 fi
 
 echo "Replacing cscope DB file"
+if [ "$BUILD_INVERTED_INDEX" -eq 1 ]; then
+    echo "mv -f \"$DB_FILE.temp.in\" \"$DB_FILE.in\""
+    mv -f "$DB_FILE.temp.in" "$DB_FILE.in"
+    echo "mv -f \"$DB_FILE.temp.po\" \"$DB_FILE.po\""
+    mv -f "$DB_FILE.temp.po" "$DB_FILE.po"
+fi
 echo "mv -f \"$DB_FILE.temp\" \"$DB_FILE\""
 mv -f "$DB_FILE.temp" "$DB_FILE"
 
--- a/plat/win32/update_scopedb.cmd	Wed Dec 19 20:48:34 2018 +0900
+++ b/plat/win32/update_scopedb.cmd	Wed Dec 19 20:49:22 2018 +0900
@@ -36,8 +36,6 @@
 if [%1]==[-l] (
     set LOG_FILE=%~2
     shift
-    goto :LoopParseArgs
-)
 echo Invalid Argument: %1
 goto :Usage
 
@@ -70,6 +68,9 @@
     for /F "usebackq delims=" %%F in (`dir /S /B /A-D .`) do @echo "%%F">%DB_FILE%.files
 )
 set CSCOPE_ARGS=%CSCOPE_ARGS% -i %DB_FILE%.files
+if ["%BUILD_INVERTED_INDEX%"]==["1"] (
+    set CSCOPE_ARGS=%CSCOPE_ARGS% -q
+)
 "%CSCOPE_EXE%" %CSCOPE_ARGS% -b -k -f "%DB_FILE%"
 if ERRORLEVEL 1 (
     echo ERROR: Cscope executable returned non-zero code. >> %LOG_FILE%