changeset 73:130905a7fb9a

Merge pull-request #23 from GitHub.
author Ludovic Chabant <ludovic@chabant.com>
date Thu, 16 Jul 2015 21:55:28 -0700
parents 661a97eaf608 (current diff) 99b95da1bed7 (diff)
children cb1cf815052e
files
diffstat 3 files changed, 97 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/autoload/gutentags/cscope.vim	Thu Jul 16 21:43:06 2015 -0700
+++ b/autoload/gutentags/cscope.vim	Thu Jul 16 21:55:28 2015 -0700
@@ -39,6 +39,17 @@
     endif
 endfunction
 
+function! gutentags#cscope#command_terminated(job_id, data, event) abort
+    if a:data == 0
+        if index(s:added_dbs, self.db_file) < 0
+            call add(s:added_dbs, self.db_file)
+            execute 'cs add ' . fnameescape(s:db_file)
+        else
+            execute 'cs reset'
+        endif
+    endif
+endfunction
+
 function! gutentags#cscope#generate(proj_dir, tags_file, write_mode) abort
     let l:cmd = gutentags#get_execute_cmd() . s:runner_exe
     let l:cmd .= ' -e ' . g:gutentags_cscope_executable
@@ -50,10 +61,19 @@
     call gutentags#trace("Running: " . l:cmd)
     call gutentags#trace("In:      " . getcwd())
     if !g:gutentags_fake
-        if !g:gutentags_trace
-            silent execute l:cmd
+        if !(has('nvim') && exists('*jobwait'))
+            if !g:gutentags_trace
+                silent execute l:cmd
+            else
+                execute l:cmd
+            endif
         else
-            execute l:cmd
+            let job_dict = { 'db_file': a:tags_file, 'on_exit' : function('gutentags#cscope#command_terminated') }
+            let job_cmd = [ s:runner_exe,
+                        \ '-e', g:gutentags_cscope_executable,
+                        \ '-p', a:proj_dir,
+                        \ '-f', a:tags_file ]
+            let job_id = jobstart(job_cmd, job_dict)
         endif
 
         let l:full_scopedb_file = fnamemodify(a:tags_file, ':p')
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/plat/unix/update_scopedb.sh	Thu Jul 16 21:55:28 2015 -0700
@@ -0,0 +1,72 @@
+#!/bin/sh
+
+set -e
+
+PROG_NAME=$0
+CSCOPE_EXE=cscope
+DB_FILE=cscope.out
+PROJECT_ROOT=
+
+ShowUsage() {
+    echo "Usage:"
+    echo "    $PROG_NAME <options>"
+    echo ""
+    echo "    -e [exe=cscope]:      The cscope executable to run"
+    echo "    -f [file=cscope.out]: The path to the ctags file to update"
+    echo "    -p [dir=]:            The path to the project root"
+    echo ""
+}
+
+
+while getopts "h?e:f:p:" opt; do
+    case $opt in
+        h|\?)
+            ShowUsage
+            exit 0
+            ;;
+        e)
+            CSCOPE_EXE=$OPTARG
+            ;;
+        f)
+            DB_FILE=$OPTARG
+            ;;
+        p)
+            PROJECT_ROOT=$OPTARG
+            ;;
+    esac
+done
+
+shift $((OPTIND - 1))
+
+if [ "$1" != "" ]; then
+    echo "Invalid Argument: $1"
+    exit 1
+fi
+
+echo "Locking cscope DB file..."
+echo $$ > "$DB_FILE.lock"
+
+# Remove lock and temp file if script is stopped unexpectedly.
+trap "rm -f \"$DB_FILE.lock\" \"$DB_FILE.temp\"" 0 3 4 15
+
+PREVIOUS_DIR=$(pwd)
+if [ -d "$PROJECT_ROOT" ]; then
+    cd "$PROJECT_ROOT"
+fi
+
+echo "Running cscope"
+echo "$CSCOPE_EXE -R -b -k -f \"$DB_FILE.temp\""
+"$CSCOPE_EXE" -R -v -b -k -f "$DB_FILE.temp"
+
+if [ -d "$PROJECT_ROOT" ]; then
+    cd "$PREVIOUS_DIR"
+fi
+
+echo "Replacing cscope DB file"
+echo "mv -f \"$DB_FILE.temp\" \"$DB_FILE\""
+mv -f "$DB_FILE.temp" "$DB_FILE"
+
+echo "Unlocking cscope DB file..."
+rm -f "$DB_FILE.lock"
+
+echo "Done."
--- a/plat/win32/update_scopedb.cmd	Thu Jul 16 21:43:06 2015 -0700
+++ b/plat/win32/update_scopedb.cmd	Thu Jul 16 21:55:28 2015 -0700
@@ -6,7 +6,7 @@
 rem ==========================================
 
 set CSCOPE_EXE=cscope
-set DB_FILE=scope.out
+set DB_FILE=cscope.out
 
 :ParseArgs
 if [%1]==[] goto :DoneParseArgs
@@ -43,7 +43,7 @@
 echo locked > "%DB_FILE%.lock"
 
 echo Running cscope
-cscope -R -b -k -f "%DB_FILE%"
+"%CSCOPE_EXE%" -R -b -k -f "%DB_FILE%"
 if ERRORLEVEL 1 (
     echo ERROR: Cscope executable returned non-zero code.
 )