annotate autoload/gutentags/pycscope.vim @ 269:e60f685c560d

pycscope
author Oliver Harley <oliver.r.harley@gmail.com>
date Mon, 04 Feb 2019 10:08:25 +0100
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
269
e60f685c560d pycscope
Oliver Harley <oliver.r.harley@gmail.com>
parents:
diff changeset
1 " Pycscope module for Gutentags
e60f685c560d pycscope
Oliver Harley <oliver.r.harley@gmail.com>
parents:
diff changeset
2
e60f685c560d pycscope
Oliver Harley <oliver.r.harley@gmail.com>
parents:
diff changeset
3 if !has('cscope')
e60f685c560d pycscope
Oliver Harley <oliver.r.harley@gmail.com>
parents:
diff changeset
4 throw "Can't enable the pycscope module for Gutentags, this Vim has ".
e60f685c560d pycscope
Oliver Harley <oliver.r.harley@gmail.com>
parents:
diff changeset
5 \"no support for cscope files."
e60f685c560d pycscope
Oliver Harley <oliver.r.harley@gmail.com>
parents:
diff changeset
6 endif
e60f685c560d pycscope
Oliver Harley <oliver.r.harley@gmail.com>
parents:
diff changeset
7
e60f685c560d pycscope
Oliver Harley <oliver.r.harley@gmail.com>
parents:
diff changeset
8 " Global Options {{{
e60f685c560d pycscope
Oliver Harley <oliver.r.harley@gmail.com>
parents:
diff changeset
9
e60f685c560d pycscope
Oliver Harley <oliver.r.harley@gmail.com>
parents:
diff changeset
10 if !exists('g:gutentags_pycscope_executable')
e60f685c560d pycscope
Oliver Harley <oliver.r.harley@gmail.com>
parents:
diff changeset
11 let g:gutentags_pycscope_executable = 'pycscope'
e60f685c560d pycscope
Oliver Harley <oliver.r.harley@gmail.com>
parents:
diff changeset
12 endif
e60f685c560d pycscope
Oliver Harley <oliver.r.harley@gmail.com>
parents:
diff changeset
13
e60f685c560d pycscope
Oliver Harley <oliver.r.harley@gmail.com>
parents:
diff changeset
14 if !exists('g:gutentags_pyscopefile')
e60f685c560d pycscope
Oliver Harley <oliver.r.harley@gmail.com>
parents:
diff changeset
15 let g:gutentags_pyscopefile = 'pycscope.out'
e60f685c560d pycscope
Oliver Harley <oliver.r.harley@gmail.com>
parents:
diff changeset
16 endif
e60f685c560d pycscope
Oliver Harley <oliver.r.harley@gmail.com>
parents:
diff changeset
17
e60f685c560d pycscope
Oliver Harley <oliver.r.harley@gmail.com>
parents:
diff changeset
18 if !exists('g:gutentags_auto_add_pycscope')
e60f685c560d pycscope
Oliver Harley <oliver.r.harley@gmail.com>
parents:
diff changeset
19 let g:gutentags_auto_add_pycscope = 1
e60f685c560d pycscope
Oliver Harley <oliver.r.harley@gmail.com>
parents:
diff changeset
20 endif
e60f685c560d pycscope
Oliver Harley <oliver.r.harley@gmail.com>
parents:
diff changeset
21
e60f685c560d pycscope
Oliver Harley <oliver.r.harley@gmail.com>
parents:
diff changeset
22 " }}}
e60f685c560d pycscope
Oliver Harley <oliver.r.harley@gmail.com>
parents:
diff changeset
23
e60f685c560d pycscope
Oliver Harley <oliver.r.harley@gmail.com>
parents:
diff changeset
24 " Gutentags Module Interface {{{
e60f685c560d pycscope
Oliver Harley <oliver.r.harley@gmail.com>
parents:
diff changeset
25
e60f685c560d pycscope
Oliver Harley <oliver.r.harley@gmail.com>
parents:
diff changeset
26 let s:runner_exe = gutentags#get_plat_file('update_pyscopedb')
e60f685c560d pycscope
Oliver Harley <oliver.r.harley@gmail.com>
parents:
diff changeset
27 let s:unix_redir = (&shellredir =~# '%s') ? &shellredir : &shellredir . ' %s'
e60f685c560d pycscope
Oliver Harley <oliver.r.harley@gmail.com>
parents:
diff changeset
28 let s:added_dbs = []
e60f685c560d pycscope
Oliver Harley <oliver.r.harley@gmail.com>
parents:
diff changeset
29
e60f685c560d pycscope
Oliver Harley <oliver.r.harley@gmail.com>
parents:
diff changeset
30 function! gutentags#pycscope#init(project_root) abort
e60f685c560d pycscope
Oliver Harley <oliver.r.harley@gmail.com>
parents:
diff changeset
31 let l:dbfile_path = gutentags#get_cachefile(
e60f685c560d pycscope
Oliver Harley <oliver.r.harley@gmail.com>
parents:
diff changeset
32 \a:project_root, g:gutentags_pyscopefile)
e60f685c560d pycscope
Oliver Harley <oliver.r.harley@gmail.com>
parents:
diff changeset
33 let b:gutentags_files['pycscope'] = l:dbfile_path
e60f685c560d pycscope
Oliver Harley <oliver.r.harley@gmail.com>
parents:
diff changeset
34
e60f685c560d pycscope
Oliver Harley <oliver.r.harley@gmail.com>
parents:
diff changeset
35 if g:gutentags_auto_add_pycscope && filereadable(l:dbfile_path)
e60f685c560d pycscope
Oliver Harley <oliver.r.harley@gmail.com>
parents:
diff changeset
36 if index(s:added_dbs, l:dbfile_path) < 0
e60f685c560d pycscope
Oliver Harley <oliver.r.harley@gmail.com>
parents:
diff changeset
37 call add(s:added_dbs, l:dbfile_path)
e60f685c560d pycscope
Oliver Harley <oliver.r.harley@gmail.com>
parents:
diff changeset
38 silent! execute 'cs add ' . fnameescape(l:dbfile_path)
e60f685c560d pycscope
Oliver Harley <oliver.r.harley@gmail.com>
parents:
diff changeset
39 endif
e60f685c560d pycscope
Oliver Harley <oliver.r.harley@gmail.com>
parents:
diff changeset
40 endif
e60f685c560d pycscope
Oliver Harley <oliver.r.harley@gmail.com>
parents:
diff changeset
41 endfunction
e60f685c560d pycscope
Oliver Harley <oliver.r.harley@gmail.com>
parents:
diff changeset
42
e60f685c560d pycscope
Oliver Harley <oliver.r.harley@gmail.com>
parents:
diff changeset
43 function! gutentags#pycscope#generate(proj_dir, tags_file, gen_opts) abort
e60f685c560d pycscope
Oliver Harley <oliver.r.harley@gmail.com>
parents:
diff changeset
44 let l:cmd = [s:runner_exe]
e60f685c560d pycscope
Oliver Harley <oliver.r.harley@gmail.com>
parents:
diff changeset
45 let l:cmd += ['-e', g:gutentags_pycscope_executable]
e60f685c560d pycscope
Oliver Harley <oliver.r.harley@gmail.com>
parents:
diff changeset
46 let l:cmd += ['-p', a:proj_dir]
e60f685c560d pycscope
Oliver Harley <oliver.r.harley@gmail.com>
parents:
diff changeset
47 let l:cmd += ['-f', a:tags_file]
e60f685c560d pycscope
Oliver Harley <oliver.r.harley@gmail.com>
parents:
diff changeset
48 let l:file_list_cmd =
e60f685c560d pycscope
Oliver Harley <oliver.r.harley@gmail.com>
parents:
diff changeset
49 \ gutentags#get_project_file_list_cmd(a:proj_dir)
e60f685c560d pycscope
Oliver Harley <oliver.r.harley@gmail.com>
parents:
diff changeset
50 if !empty(l:file_list_cmd)
e60f685c560d pycscope
Oliver Harley <oliver.r.harley@gmail.com>
parents:
diff changeset
51 let l:cmd += ['-L', '"' . l:file_list_cmd . '"']
e60f685c560d pycscope
Oliver Harley <oliver.r.harley@gmail.com>
parents:
diff changeset
52 endif
e60f685c560d pycscope
Oliver Harley <oliver.r.harley@gmail.com>
parents:
diff changeset
53 let l:cmd = gutentags#make_args(l:cmd)
e60f685c560d pycscope
Oliver Harley <oliver.r.harley@gmail.com>
parents:
diff changeset
54
e60f685c560d pycscope
Oliver Harley <oliver.r.harley@gmail.com>
parents:
diff changeset
55 call gutentags#trace("Running: " . string(l:cmd))
e60f685c560d pycscope
Oliver Harley <oliver.r.harley@gmail.com>
parents:
diff changeset
56 call gutentags#trace("In: " . getcwd())
e60f685c560d pycscope
Oliver Harley <oliver.r.harley@gmail.com>
parents:
diff changeset
57 if !g:gutentags_fake
e60f685c560d pycscope
Oliver Harley <oliver.r.harley@gmail.com>
parents:
diff changeset
58 let l:job_opts = gutentags#build_default_job_options('pycscope')
e60f685c560d pycscope
Oliver Harley <oliver.r.harley@gmail.com>
parents:
diff changeset
59 let l:job = gutentags#start_job(l:cmd, l:job_opts)
e60f685c560d pycscope
Oliver Harley <oliver.r.harley@gmail.com>
parents:
diff changeset
60 call gutentags#add_job('pycscope', a:tags_file, l:job)
e60f685c560d pycscope
Oliver Harley <oliver.r.harley@gmail.com>
parents:
diff changeset
61 else
e60f685c560d pycscope
Oliver Harley <oliver.r.harley@gmail.com>
parents:
diff changeset
62 call gutentags#trace("(fake... not actually running)")
e60f685c560d pycscope
Oliver Harley <oliver.r.harley@gmail.com>
parents:
diff changeset
63 endif
e60f685c560d pycscope
Oliver Harley <oliver.r.harley@gmail.com>
parents:
diff changeset
64 endfunction
e60f685c560d pycscope
Oliver Harley <oliver.r.harley@gmail.com>
parents:
diff changeset
65
e60f685c560d pycscope
Oliver Harley <oliver.r.harley@gmail.com>
parents:
diff changeset
66 function! gutentags#pycscope#on_job_exit(job, exit_val) abort
e60f685c560d pycscope
Oliver Harley <oliver.r.harley@gmail.com>
parents:
diff changeset
67 let l:job_idx = gutentags#find_job_index_by_data('pycscope', a:job)
e60f685c560d pycscope
Oliver Harley <oliver.r.harley@gmail.com>
parents:
diff changeset
68 let l:dbfile_path = gutentags#get_job_tags_file('pycscope', l:job_idx)
e60f685c560d pycscope
Oliver Harley <oliver.r.harley@gmail.com>
parents:
diff changeset
69 call gutentags#remove_job('pycscope', l:job_idx)
e60f685c560d pycscope
Oliver Harley <oliver.r.harley@gmail.com>
parents:
diff changeset
70
e60f685c560d pycscope
Oliver Harley <oliver.r.harley@gmail.com>
parents:
diff changeset
71 if a:exit_val == 0
e60f685c560d pycscope
Oliver Harley <oliver.r.harley@gmail.com>
parents:
diff changeset
72 if index(s:added_dbs, l:dbfile_path) < 0
e60f685c560d pycscope
Oliver Harley <oliver.r.harley@gmail.com>
parents:
diff changeset
73 call add(s:added_dbs, l:dbfile_path)
e60f685c560d pycscope
Oliver Harley <oliver.r.harley@gmail.com>
parents:
diff changeset
74 silent! execute 'cs add ' . fnameescape(l:dbfile_path)
e60f685c560d pycscope
Oliver Harley <oliver.r.harley@gmail.com>
parents:
diff changeset
75 else
e60f685c560d pycscope
Oliver Harley <oliver.r.harley@gmail.com>
parents:
diff changeset
76 silent! execute 'cs reset'
e60f685c560d pycscope
Oliver Harley <oliver.r.harley@gmail.com>
parents:
diff changeset
77 endif
e60f685c560d pycscope
Oliver Harley <oliver.r.harley@gmail.com>
parents:
diff changeset
78 else
e60f685c560d pycscope
Oliver Harley <oliver.r.harley@gmail.com>
parents:
diff changeset
79 call gutentags#warning(
e60f685c560d pycscope
Oliver Harley <oliver.r.harley@gmail.com>
parents:
diff changeset
80 \"gutentags: pycscope job failed, returned: ".
e60f685c560d pycscope
Oliver Harley <oliver.r.harley@gmail.com>
parents:
diff changeset
81 \string(a:exit_val))
e60f685c560d pycscope
Oliver Harley <oliver.r.harley@gmail.com>
parents:
diff changeset
82 endif
e60f685c560d pycscope
Oliver Harley <oliver.r.harley@gmail.com>
parents:
diff changeset
83 endfunction
e60f685c560d pycscope
Oliver Harley <oliver.r.harley@gmail.com>
parents:
diff changeset
84
e60f685c560d pycscope
Oliver Harley <oliver.r.harley@gmail.com>
parents:
diff changeset
85 " }}}
e60f685c560d pycscope
Oliver Harley <oliver.r.harley@gmail.com>
parents:
diff changeset
86