Mercurial > vim-gutentags
annotate autoload/gutentags/cscope.vim @ 198:5fb056a9eefb
Don't change the current working directory more often than needed.
Ctags/Cscope modules do this in their `generate` method when Gutentags already
set the current directory to the project directory ahead of time.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Thu, 27 Jul 2017 22:38:02 -0700 |
parents | cac059bce038 |
children | f7a417234dea |
rev | line source |
---|---|
44
1a853b37eddf
Add some mostly-working Cscope module (for Windows).
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
1 " Cscope module for Gutentags |
1a853b37eddf
Add some mostly-working Cscope module (for Windows).
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
2 |
1a853b37eddf
Add some mostly-working Cscope module (for Windows).
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
3 if !has('cscope') |
1a853b37eddf
Add some mostly-working Cscope module (for Windows).
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
4 throw "Can't enable the cscope module for Gutentags, this Vim has ". |
1a853b37eddf
Add some mostly-working Cscope module (for Windows).
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
5 \"no support for cscope files." |
1a853b37eddf
Add some mostly-working Cscope module (for Windows).
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
6 endif |
1a853b37eddf
Add some mostly-working Cscope module (for Windows).
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
7 |
1a853b37eddf
Add some mostly-working Cscope module (for Windows).
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
8 " Global Options {{{ |
1a853b37eddf
Add some mostly-working Cscope module (for Windows).
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
9 |
1a853b37eddf
Add some mostly-working Cscope module (for Windows).
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
10 if !exists('g:gutentags_cscope_executable') |
1a853b37eddf
Add some mostly-working Cscope module (for Windows).
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
11 let g:gutentags_cscope_executable = 'cscope' |
1a853b37eddf
Add some mostly-working Cscope module (for Windows).
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
12 endif |
1a853b37eddf
Add some mostly-working Cscope module (for Windows).
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
13 |
1a853b37eddf
Add some mostly-working Cscope module (for Windows).
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
14 if !exists('g:gutentags_scopefile') |
1a853b37eddf
Add some mostly-working Cscope module (for Windows).
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
15 let g:gutentags_scopefile = 'cscope.out' |
1a853b37eddf
Add some mostly-working Cscope module (for Windows).
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
16 endif |
1a853b37eddf
Add some mostly-working Cscope module (for Windows).
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
17 |
1a853b37eddf
Add some mostly-working Cscope module (for Windows).
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
18 if !exists('g:gutentags_auto_add_cscope') |
1a853b37eddf
Add some mostly-working Cscope module (for Windows).
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
19 let g:gutentags_auto_add_cscope = 1 |
1a853b37eddf
Add some mostly-working Cscope module (for Windows).
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
20 endif |
1a853b37eddf
Add some mostly-working Cscope module (for Windows).
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
21 |
1a853b37eddf
Add some mostly-working Cscope module (for Windows).
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
22 " }}} |
1a853b37eddf
Add some mostly-working Cscope module (for Windows).
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
23 |
1a853b37eddf
Add some mostly-working Cscope module (for Windows).
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
24 " Gutentags Module Interface {{{ |
1a853b37eddf
Add some mostly-working Cscope module (for Windows).
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
25 |
1a853b37eddf
Add some mostly-working Cscope module (for Windows).
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
26 let s:runner_exe = gutentags#get_plat_file('update_scopedb') |
196
cac059bce038
Log instead of echoing to stdout
Chayoung You <yousbe@gmail.com>
parents:
195
diff
changeset
|
27 let s:unix_redir = (&shellredir =~# '%s') ? &shellredir : &shellredir . ' %s' |
44
1a853b37eddf
Add some mostly-working Cscope module (for Windows).
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
28 let s:added_dbs = [] |
1a853b37eddf
Add some mostly-working Cscope module (for Windows).
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
29 |
1a853b37eddf
Add some mostly-working Cscope module (for Windows).
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
30 function! gutentags#cscope#init(project_root) abort |
1a853b37eddf
Add some mostly-working Cscope module (for Windows).
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
31 let l:dbfile_path = gutentags#get_cachefile( |
1a853b37eddf
Add some mostly-working Cscope module (for Windows).
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
32 \a:project_root, g:gutentags_scopefile) |
1a853b37eddf
Add some mostly-working Cscope module (for Windows).
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
33 let b:gutentags_files['cscope'] = l:dbfile_path |
1a853b37eddf
Add some mostly-working Cscope module (for Windows).
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
34 |
1a853b37eddf
Add some mostly-working Cscope module (for Windows).
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
35 if g:gutentags_auto_add_cscope && filereadable(l:dbfile_path) |
1a853b37eddf
Add some mostly-working Cscope module (for Windows).
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
36 if index(s:added_dbs, l:dbfile_path) < 0 |
1a853b37eddf
Add some mostly-working Cscope module (for Windows).
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
37 call add(s:added_dbs, l:dbfile_path) |
195
fd863d1bcfb9
Suppress warning from cscope add
Chayoung You <yousbe@gmail.com>
parents:
194
diff
changeset
|
38 silent! execute 'cs add ' . fnameescape(l:dbfile_path) |
44
1a853b37eddf
Add some mostly-working Cscope module (for Windows).
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
39 endif |
1a853b37eddf
Add some mostly-working Cscope module (for Windows).
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
40 endif |
1a853b37eddf
Add some mostly-working Cscope module (for Windows).
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
41 endfunction |
1a853b37eddf
Add some mostly-working Cscope module (for Windows).
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
42 |
72
99b95da1bed7
Add Neovim support for cscope
Jonathan Buschmann <jonthn@pinacea.com>
parents:
44
diff
changeset
|
43 function! gutentags#cscope#command_terminated(job_id, data, event) abort |
99b95da1bed7
Add Neovim support for cscope
Jonathan Buschmann <jonthn@pinacea.com>
parents:
44
diff
changeset
|
44 if a:data == 0 |
99b95da1bed7
Add Neovim support for cscope
Jonathan Buschmann <jonthn@pinacea.com>
parents:
44
diff
changeset
|
45 if index(s:added_dbs, self.db_file) < 0 |
99b95da1bed7
Add Neovim support for cscope
Jonathan Buschmann <jonthn@pinacea.com>
parents:
44
diff
changeset
|
46 call add(s:added_dbs, self.db_file) |
195
fd863d1bcfb9
Suppress warning from cscope add
Chayoung You <yousbe@gmail.com>
parents:
194
diff
changeset
|
47 silent! execute 'cs add ' . fnameescape(s:db_file) |
72
99b95da1bed7
Add Neovim support for cscope
Jonathan Buschmann <jonthn@pinacea.com>
parents:
44
diff
changeset
|
48 else |
99b95da1bed7
Add Neovim support for cscope
Jonathan Buschmann <jonthn@pinacea.com>
parents:
44
diff
changeset
|
49 execute 'cs reset' |
99b95da1bed7
Add Neovim support for cscope
Jonathan Buschmann <jonthn@pinacea.com>
parents:
44
diff
changeset
|
50 endif |
99b95da1bed7
Add Neovim support for cscope
Jonathan Buschmann <jonthn@pinacea.com>
parents:
44
diff
changeset
|
51 endif |
99b95da1bed7
Add Neovim support for cscope
Jonathan Buschmann <jonthn@pinacea.com>
parents:
44
diff
changeset
|
52 endfunction |
99b95da1bed7
Add Neovim support for cscope
Jonathan Buschmann <jonthn@pinacea.com>
parents:
44
diff
changeset
|
53 |
44
1a853b37eddf
Add some mostly-working Cscope module (for Windows).
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
54 function! gutentags#cscope#generate(proj_dir, tags_file, write_mode) abort |
1a853b37eddf
Add some mostly-working Cscope module (for Windows).
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
55 let l:cmd = gutentags#get_execute_cmd() . s:runner_exe |
1a853b37eddf
Add some mostly-working Cscope module (for Windows).
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
56 let l:cmd .= ' -e ' . g:gutentags_cscope_executable |
1a853b37eddf
Add some mostly-working Cscope module (for Windows).
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
57 let l:cmd .= ' -p ' . a:proj_dir |
1a853b37eddf
Add some mostly-working Cscope module (for Windows).
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
58 let l:cmd .= ' -f ' . a:tags_file |
136
286e5b3095d0
Allow restricting tag generation to files listed by custom commands
Stephen Kent <smkent@smkent.net>
parents:
72
diff
changeset
|
59 let l:file_list_cmd = |
194
4689b770e4fa
Fix generation for Homebrew cscope
Chayoung You <yousbe@gmail.com>
parents:
179
diff
changeset
|
60 \ gutentags#get_project_file_list_cmd(a:proj_dir) |
136
286e5b3095d0
Allow restricting tag generation to files listed by custom commands
Stephen Kent <smkent@smkent.net>
parents:
72
diff
changeset
|
61 if !empty(l:file_list_cmd) |
286e5b3095d0
Allow restricting tag generation to files listed by custom commands
Stephen Kent <smkent@smkent.net>
parents:
72
diff
changeset
|
62 let l:cmd .= ' -L "' . l:file_list_cmd . '"' |
286e5b3095d0
Allow restricting tag generation to files listed by custom commands
Stephen Kent <smkent@smkent.net>
parents:
72
diff
changeset
|
63 endif |
196
cac059bce038
Log instead of echoing to stdout
Chayoung You <yousbe@gmail.com>
parents:
195
diff
changeset
|
64 if g:gutentags_trace |
cac059bce038
Log instead of echoing to stdout
Chayoung You <yousbe@gmail.com>
parents:
195
diff
changeset
|
65 if has('win32') |
cac059bce038
Log instead of echoing to stdout
Chayoung You <yousbe@gmail.com>
parents:
195
diff
changeset
|
66 let l:cmd .= ' -l "' . a:tags_file . '.log"' |
cac059bce038
Log instead of echoing to stdout
Chayoung You <yousbe@gmail.com>
parents:
195
diff
changeset
|
67 else |
cac059bce038
Log instead of echoing to stdout
Chayoung You <yousbe@gmail.com>
parents:
195
diff
changeset
|
68 let l:cmd .= ' ' . printf(s:unix_redir, '"' . a:tags_file . '.log"') |
cac059bce038
Log instead of echoing to stdout
Chayoung You <yousbe@gmail.com>
parents:
195
diff
changeset
|
69 endif |
cac059bce038
Log instead of echoing to stdout
Chayoung You <yousbe@gmail.com>
parents:
195
diff
changeset
|
70 else |
cac059bce038
Log instead of echoing to stdout
Chayoung You <yousbe@gmail.com>
parents:
195
diff
changeset
|
71 if !has('win32') |
cac059bce038
Log instead of echoing to stdout
Chayoung You <yousbe@gmail.com>
parents:
195
diff
changeset
|
72 let l:cmd .= ' ' . printf(s:unix_redir, '/dev/null') |
cac059bce038
Log instead of echoing to stdout
Chayoung You <yousbe@gmail.com>
parents:
195
diff
changeset
|
73 endif |
cac059bce038
Log instead of echoing to stdout
Chayoung You <yousbe@gmail.com>
parents:
195
diff
changeset
|
74 endif |
44
1a853b37eddf
Add some mostly-working Cscope module (for Windows).
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
75 let l:cmd .= ' ' |
1a853b37eddf
Add some mostly-working Cscope module (for Windows).
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
76 let l:cmd .= gutentags#get_execute_cmd_suffix() |
1a853b37eddf
Add some mostly-working Cscope module (for Windows).
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
77 |
1a853b37eddf
Add some mostly-working Cscope module (for Windows).
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
78 call gutentags#trace("Running: " . l:cmd) |
179 | 79 call gutentags#trace("In: " . getcwd()) |
44
1a853b37eddf
Add some mostly-working Cscope module (for Windows).
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
80 if !g:gutentags_fake |
72
99b95da1bed7
Add Neovim support for cscope
Jonathan Buschmann <jonthn@pinacea.com>
parents:
44
diff
changeset
|
81 if !(has('nvim') && exists('*jobwait')) |
99b95da1bed7
Add Neovim support for cscope
Jonathan Buschmann <jonthn@pinacea.com>
parents:
44
diff
changeset
|
82 if !g:gutentags_trace |
99b95da1bed7
Add Neovim support for cscope
Jonathan Buschmann <jonthn@pinacea.com>
parents:
44
diff
changeset
|
83 silent execute l:cmd |
99b95da1bed7
Add Neovim support for cscope
Jonathan Buschmann <jonthn@pinacea.com>
parents:
44
diff
changeset
|
84 else |
99b95da1bed7
Add Neovim support for cscope
Jonathan Buschmann <jonthn@pinacea.com>
parents:
44
diff
changeset
|
85 execute l:cmd |
99b95da1bed7
Add Neovim support for cscope
Jonathan Buschmann <jonthn@pinacea.com>
parents:
44
diff
changeset
|
86 endif |
44
1a853b37eddf
Add some mostly-working Cscope module (for Windows).
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
87 else |
72
99b95da1bed7
Add Neovim support for cscope
Jonathan Buschmann <jonthn@pinacea.com>
parents:
44
diff
changeset
|
88 let job_dict = { 'db_file': a:tags_file, 'on_exit' : function('gutentags#cscope#command_terminated') } |
99b95da1bed7
Add Neovim support for cscope
Jonathan Buschmann <jonthn@pinacea.com>
parents:
44
diff
changeset
|
89 let job_cmd = [ s:runner_exe, |
99b95da1bed7
Add Neovim support for cscope
Jonathan Buschmann <jonthn@pinacea.com>
parents:
44
diff
changeset
|
90 \ '-e', g:gutentags_cscope_executable, |
99b95da1bed7
Add Neovim support for cscope
Jonathan Buschmann <jonthn@pinacea.com>
parents:
44
diff
changeset
|
91 \ '-p', a:proj_dir, |
99b95da1bed7
Add Neovim support for cscope
Jonathan Buschmann <jonthn@pinacea.com>
parents:
44
diff
changeset
|
92 \ '-f', a:tags_file ] |
99b95da1bed7
Add Neovim support for cscope
Jonathan Buschmann <jonthn@pinacea.com>
parents:
44
diff
changeset
|
93 let job_id = jobstart(job_cmd, job_dict) |
44
1a853b37eddf
Add some mostly-working Cscope module (for Windows).
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
94 endif |
1a853b37eddf
Add some mostly-working Cscope module (for Windows).
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
95 |
1a853b37eddf
Add some mostly-working Cscope module (for Windows).
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
96 let l:full_scopedb_file = fnamemodify(a:tags_file, ':p') |
1a853b37eddf
Add some mostly-working Cscope module (for Windows).
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
97 call gutentags#add_progress('cscope', l:full_scopedb_file) |
1a853b37eddf
Add some mostly-working Cscope module (for Windows).
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
98 else |
1a853b37eddf
Add some mostly-working Cscope module (for Windows).
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
99 call gutentags#trace("(fake... not actually running)") |
1a853b37eddf
Add some mostly-working Cscope module (for Windows).
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
100 endif |
1a853b37eddf
Add some mostly-working Cscope module (for Windows).
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
101 call gutentags#trace("") |
1a853b37eddf
Add some mostly-working Cscope module (for Windows).
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
102 endfunction |
1a853b37eddf
Add some mostly-working Cscope module (for Windows).
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
103 |
1a853b37eddf
Add some mostly-working Cscope module (for Windows).
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
104 " }}} |
1a853b37eddf
Add some mostly-working Cscope module (for Windows).
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
105 |