@@ -0,0 +1,48 @@
Loading
1 +
"=============================================================================
2 +
" ctags.vim --- ctags generator
3 +
" Copyright (c) 2016-2019 Wang Shidong & Contributors
4 +
" Author: Wang Shidong < wsdjeg@outlook.com >
5 +
" URL: https://spacevim.org
6 +
" License: GPLv3
7 +
"=============================================================================
8 +
9 +
scriptencoding utf-8
10 +
11 +
let s:LOGGER =SpaceVim#logger#derive('ctags')
12 +
13 +
if !executable('ctags')
14 +
  call s:LOGGER.warn('ctags is not executable, you need to install ctags')
15 +
  finish
16 +
endif
17 +
18 +
if exists('g:loaded_ctags')
19 +
  finish
20 +
endif
21 +
22 +
let s:JOB = SpaceVim#api#import('job')
23 +
let s:FILE = SpaceVim#api#import('file')
24 +
25 +
let g:loaded_ctags = 1
26 +
27 +
function! ctags#update() abort
28 +
  let project_root = getcwd()
29 +
  call s:LOGGER.info('update ctags database for ' . project_root)
30 +
  let dir = s:FILE.unify_path(g:tags_cache_dir) 
31 +
        \ . s:FILE.path_to_fname(project_root)
32 +
  let cmd = ['ctags']
33 +
  if !isdirectory(dir)
34 +
    call mkdir(dir, 'p')
35 +
  endif
36 +
  if isdirectory(dir)
37 +
    let cmd += ['-R', '-o', dir . '/tags', project_root]
38 +
    call s:JOB.start(cmd, {'on_exit' : funcref('s:on_update_exit')})
39 +
  endif
40 +
endfunction
41 +
42 +
function! s:on_update_exit(...) abort
43 +
  if str2nr(a:2) > 0
44 +
    call s:LOGGER.warn('failed to update gtags, exit data: ' . a:2)
45 +
  else
46 +
    call s:LOGGER.info('ctags database updated successfully')
47 +
  endif
48 +
endfunction

@@ -0,0 +1,149 @@
Loading
1 +
""
2 +
" @section Introduction, intro
3 +
" The gtags.vim plug-in script integrates the GNU GLOBAL source code tag
4 +
" system with Vim. About the details, see http://www.gnu.org/software/global/.
5 +
6 +
scriptencoding utf-8
7 +
8 +
let g:gtags_gtagslabel = ''
9 +
10 +
if !exists('g:gtags_auto_update')
11 +
    let g:gtags_auto_update = 1
12 +
endif
13 +
14 +
15 +
if !exists('g:gtags_silent')
16 +
    let g:gtags_silent = 1
17 +
endif
18 +
19 +
20 +
""
21 +
" General form of Gtags command is as follows:
22 +
" >
23 +
"     :Gtags [option] pattern
24 +
"
25 +
" To go to func, you can say
26 +
" >
27 +
"     :Gtags func
28 +
"
29 +
" Input completion is available. If you forgot function name but recall
30 +
" only some characters of the head, please input them and press <TAB> key.
31 +
" >
32 +
"     :Gtags fu<TAB>
33 +
"     :Gtags func                     " Vim will append 'nc'.
34 +
"
35 +
" If you omitted argument, vim ask it like this:
36 +
" >
37 +
"     Gtags for pattern: <current token>
38 +
"
39 +
" Vim execute `global -x main', parse the output, list located
40 +
" objects in quickfix window and load the first entry.  The quickfix
41 +
" windows is like this:
42 +
" >
43 +
"     gozilla/gozilla.c|200| main(int argc, char **argv)
44 +
"     gtags-cscope/gtags-cscope.c|124| main(int argc, char **argv)
45 +
"     gtags-parser/asm_scan.c|2056| int main()
46 +
"     gtags-parser/gctags.c|157| main(int argc, char **argv)
47 +
"     gtags-parser/php.c|2116| int main()
48 +
"     gtags/gtags.c|152| main(int argc, char **argv)
49 +
"     [Quickfix List]
50 +
"
51 +
" You can go to any entry using quickfix command.
52 +
"
53 +
" :cn
54 +
"     go to the next entry.
55 +
"
56 +
" :cp
57 +
"     go to the previous entry.
58 +
"
59 +
" :cc{N}
60 +
"     go to the {N}th entry.
61 +
"
62 +
" :cl
63 +
"     list all entries.
64 +
"
65 +
" You can see the help of quickfix like this:
66 +
" >
67 +
"     :h quickfix
68 +
"
69 +
" You can use POSIX regular expression too. It requires more execution time though.
70 +
" >
71 +
"     :Gtags ^[sg]et_
72 +
"
73 +
" It will match to both of 'set_value' and 'get_value'.
74 +
"
75 +
" To go to the referenced point of func, add -r option.
76 +
" >
77 +
"     :Gtags -r func
78 +
"
79 +
" To go to any symbols which are not defined in GTAGS, try this.
80 +
" >
81 +
"     :Gtags -s func
82 +
"
83 +
" To go to any string other than symbol, try this.
84 +
" >
85 +
"     :Gtags -g ^[sg]et_
86 +
"
87 +
" This command accomplishes the same function as grep(1) but is more convenient
88 +
" because it retrieves the entire directory structure.
89 +
"
90 +
" To get list of objects in a file 'main.c', use -f command.
91 +
" >
92 +
"     :Gtags -f main.c
93 +
"
94 +
" If you are editing `main.c' itself, you can use '%' instead.
95 +
" >
96 +
"     :Gtags -f %
97 +
"
98 +
" You can browse project files whose path includes specified pattern.
99 +
" For example:
100 +
" >
101 +
"     :Gtags -P /vm/                  <- all files under 'vm' directory.
102 +
"     :Gtags -P \.h$                  <- all include files.
103 +
"     :Gtags -P init                  <- all paths includes 'init'
104 +
"
105 +
" If you omitted the argument and input only <ENTER> key to the prompt,
106 +
" vim shows list of all files in your project.
107 +
"
108 +
" You can use all options of `global(1)` except for the -c, -p, -u and
109 +
" all long name options. They are sent to `global(1)` as is.
110 +
" For example, if you want to ignore case distinctions in pattern.
111 +
" >
112 +
"     :Gtags -gi paTtern
113 +
"
114 +
" It will match to both of `PATTERN` and `pattern`.
115 +
"
116 +
" If you want to search a pattern which starts with a hyphen like '-C'
117 +
" then you can use the -e option like `grep(1)`.
118 +
" >
119 +
"     :Gtags -ge -C
120 +
"
121 +
" By default, Gtags command search only in source files. If you want to
122 +
" search in both source files and text files, or only in text files then
123 +
" >
124 +
"     :Gtags -go pattern              # both source and text
125 +
"     :Gtags -gO pattern              # only text file
126 +
"
127 +
" See `global(1)` for other options.
128 +
command! -nargs=* -complete=custom,gtags#complete Gtags call gtags#global(<q-args>)
129 +
130 +
""
131 +
" The GtagsCursor command brings you to the definition or reference of
132 +
" the current token.
133 +
" >
134 +
"     :GtagsCursor
135 +
" <
136 +
command! -nargs=0 GtagsCursor call gtags#cursor()
137 +
138 +
""
139 +
" Use GtagsRemind command to jump to the previous position from where you
140 +
" invoked `:Gtags`.
141 +
" >
142 +
"   ":GtagsRemind
143 +
" <
144 +
command! -nargs=0 GtagsRemind call gtags#remind()
145 +
146 +
""
147 +
" Update gtags for current file, with a {bang}, will update the project's
148 +
" gtags database.
149 +
command! -nargs=0 -bang GtagsGenerate call gtags#update(<bang>1)

@@ -6,9 +6,19 @@
Loading
6 6
" License: GPLv3
7 7
"=============================================================================
8 8
9 +
if exists('s:gtagslabel')
10 +
  finish
11 +
endif
12 +
13 +
let s:FILE = SpaceVim#api#import('file')
14 +
15 +
let s:gtagslabel = ''
16 +
let s:auto_update = 1
17 +
let g:tags_cache_dir = '~/.cache/SpaceVim/tags/'
18 +
9 19
function! SpaceVim#layers#gtags#plugins() abort
10 20
  return [
11 -
        \ ['SpaceVim/gtags.vim', {'merged' : 0}],
21 +
        \ [g:_spacevim_root_dir . 'bundle/gtags.vim', { 'merged' : 0}]
12 22
        \ ]
13 23
endfunction
14 24
@@ -23,37 +33,28 @@
Loading
23 33
  call SpaceVim#mapping#space#def('nnoremap', ['m', 'g', 'g'], 'exe "Gtags -g " . expand("<cword>")', 'find-cursor-string', 1)
24 34
  call SpaceVim#mapping#space#def('nnoremap', ['m', 'g', 'f'], 'Gtags -f %', 'list of objects', 1)
25 35
  let g:gtags_gtagslabel = s:gtagslabel
26 -
  augroup spacevim_layer_tags
27 -
    autocmd!
28 -
    autocmd BufEnter *
29 -
          \   if empty(&buftype) && &filetype != 'help'
30 -
          \|      nnoremap <silent><buffer> <Leader>] :call MyTagfunc()<CR>
31 -
          \|      nnoremap <silent><buffer> <Leader>[ :call MyTagfuncBack()<CR>
32 -
          \|  endif
33 -
  augroup END
34 -
endfunction
35 -
36 -
function! MyTagfunc() abort
37 -
  mark H
38 -
  let s:MyTagfunc_flag = 1
39 -
  UniteWithCursorWord -force-immediately tag
40 -
endfunction
41 -
42 -
function! MyTagfuncBack() abort
43 -
  if exists('s:MyTagfunc_flag')&&s:MyTagfunc_flag
44 -
    exe 'normal! `H'
45 -
    let s:MyTagfunc_flag =0
36 +
  call SpaceVim#plugins#projectmanager#reg_callback(funcref('s:update_ctags_option'))
37 +
  if s:auto_update
38 +
    augroup spacevim_layer_gtags
39 +
      autocmd!
40 +
      au BufWritePost * call ctags#update()
41 +
      au BufWritePost * call gtags#update(1)
42 +
    augroup END
46 43
  endif
47 44
endfunction
48 45
49 -
50 -
let s:gtagslabel = ''
51 -
52 46
function! SpaceVim#layers#gtags#set_variable(var) abort
53 47
54 48
  let s:gtagslabel = get(a:var,
55 49
        \ 'gtagslabel',
56 50
        \ '')
51 +
  let g:tags_cache_dir = get(a:var,
52 +
        \ 'tags_cache_dir',
53 +
        \ g:tags_cache_dir)
54 +
55 +
  let s:auto_update = get(a:var,
56 +
        \ 'auto_update',
57 +
        \ s:auto_update)
57 58
endfunction
58 59
59 60
@@ -62,3 +63,12 @@
Loading
62 63
  return ['gtagslabel']
63 64
64 65
endfunction
66 +
67 +
function! s:update_ctags_option() abort
68 +
  let project_root = getcwd()
69 +
  let dir = s:FILE.unify_path(g:tags_cache_dir) 
70 +
        \ . s:FILE.path_to_fname(project_root)
71 +
  let tags = filter(split(&tags, ','), 'v:val !~# ".cache/SpaceVim/tags"')
72 +
  call add(tags, dir . '/tags')
73 +
  let &tags = join(tags, ',')
74 +
endfunction

@@ -0,0 +1,474 @@
Loading
1 +
scriptencoding utf-8
2 +
3 +
let s:LOGGER =SpaceVim#logger#derive('gtags')
4 +
5 +
if !executable('gtags')
6 +
  call s:LOGGER.warn('gtags is not executable, you need to install gnu global!')
7 +
  finish
8 +
endif
9 +
10 +
if exists('g:loaded_gtags')
11 +
  finish
12 +
endif
13 +
let s:JOB = SpaceVim#api#import('job')
14 +
let s:FILE = SpaceVim#api#import('file')
15 +
16 +
let g:loaded_gtags = 1
17 +
let s:version = split(matchstr(split(system('gtags --version'), '\n')[0], '[0-9]\+\.[0-9]\+'), '\.')
18 +
19 +
""
20 +
" Set the global command name. If it is not set, will use $GTAGSGLOBAL, and if
21 +
" $GTAGSGLOBAL still is an empty string, then will use 'global'.
22 +
let g:gtags_global_command = get(g:, 'gtags_global_command',
23 +
      \ empty($GTAGSGLOBAL) ? 'global' : $GTAGSGLOBAL
24 +
      \ )
25 +
26 +
""
27 +
" Enable/Disable default mappings. By default it is disabled.
28 +
let g:gtags_auto_map = get(g:, 'gtags_auto_map', 0)
29 +
30 +
""
31 +
" This setting will open the |quickfix| list when adding entries. A value of 2 will
32 +
" preserve the cursor position when the |quickfix| window is
33 +
" opened. Defaults to 2.
34 +
let g:gtags_open_list = get(g:, 'gtags_open_list', 2)
35 +
36 +
" -- ctags-x format
37 +
" let Gtags_Result = "ctags-x"
38 +
" let Gtags_Efm = "%*\\S%*\\s%l%\\s%f%\\s%m"
39 +
"
40 +
" -- ctags format
41 +
" let Gtags_Result = "ctags"
42 +
" let Gtags_Efm = "%m\t%f\t%l"
43 +
"
44 +
" Gtags_Use_Tags_Format is obsoleted.
45 +
if exists('g:Gtags_Use_Tags_Format')
46 +
  let g:Gtags_Result = 'ctags'
47 +
  let g:Gtags_Efm = "%m\t%f\t%l"
48 +
endif
49 +
if !exists('g:Gtags_Result')
50 +
  let g:Gtags_Result = 'ctags-x'
51 +
endif
52 +
if !exists('g:Gtags_Efm')
53 +
  let g:Gtags_Efm = "%*\\S%*\\s%l%\\s%f%\\s%m"
54 +
endif
55 +
" Character to use to quote patterns and file names before passing to global.
56 +
" (This code was drived from 'grep.vim'.)
57 +
if !exists('g:Gtags_Shell_Quote_Char')
58 +
  if has('win32') || has('win16') || has('win95')
59 +
    let g:Gtags_Shell_Quote_Char = '"'
60 +
  else
61 +
    let g:Gtags_Shell_Quote_Char = "'"
62 +
  endif
63 +
endif
64 +
if !exists('g:Gtags_Single_Quote_Char')
65 +
  if has('win32') || has('win16') || has('win95')
66 +
    let g:Gtags_Single_Quote_Char = "'"
67 +
    let g:Gtags_Double_Quote_Char = '\"'
68 +
  else
69 +
    let s:sq = "'"
70 +
    let s:dq = '"'
71 +
    let g:Gtags_Single_Quote_Char = s:sq . s:dq . s:sq . s:dq . s:sq
72 +
    let g:Gtags_Double_Quote_Char = '"'
73 +
  endif
74 +
endif
75 +
76 +
"
77 +
" Stack Object.
78 +
"
79 +
function! s:Stack() abort
80 +
  let l:this = {}
81 +
  let l:this.container = []
82 +
83 +
  function! l:this.push(item) abort
84 +
    call add(self.container, a:item)
85 +
  endfunction
86 +
87 +
  function! l:this.pop() abort
88 +
    if len(self.container) <= 0
89 +
      throw 'Stack Empty'
90 +
    endif
91 +
92 +
    let l:item = self.container[-1]
93 +
    unlet self.container[-1]
94 +
95 +
    return l:item
96 +
  endfunction
97 +
98 +
  return l:this
99 +
endfunction
100 +
101 +
function! s:Memorize() abort
102 +
  let l:data = {
103 +
        \'file': expand('%'),
104 +
        \'position': getpos('.'),
105 +
        \}
106 +
  call s:crumbs.push(l:data)
107 +
endfunction
108 +
109 +
function! gtags#remind() abort
110 +
  try
111 +
    let l:data = s:crumbs.pop()
112 +
  catch
113 +
    call s:Error(v:exception)
114 +
    return
115 +
  endtry
116 +
117 +
  execute 'e ' . l:data.file
118 +
  call setpos('.', l:data.position)
119 +
endfunction
120 +
121 +
if ! exists('s:crumbs')
122 +
  let s:crumbs = s:Stack()
123 +
endif
124 +
125 +
"
126 +
" Display error message.
127 +
"
128 +
function! s:Error(msg) abort
129 +
  echohl WarningMsg |
130 +
        \ echomsg 'Error: ' . a:msg |
131 +
        \ echohl None
132 +
endfunction
133 +
"
134 +
" Extract pattern or option string.
135 +
"
136 +
function! s:Extract(line, target) abort
137 +
  let l:option = ''
138 +
  let l:pattern = ''
139 +
  let l:force_pattern = 0
140 +
  let l:length = strlen(a:line)
141 +
  let l:i = 0
142 +
143 +
  " skip command name.
144 +
  if a:line =~# '^Gtags'
145 +
    let l:i = 5
146 +
  endif
147 +
  while l:i < l:length && a:line[l:i] ==# ' '
148 +
    let l:i = l:i + 1
149 +
  endwhile
150 +
  while l:i < l:length
151 +
    if a:line[l:i] ==# '-' && l:force_pattern == 0
152 +
      let l:i = l:i + 1
153 +
      " Ignore long name option like --help.
154 +
      if l:i < l:length && a:line[l:i] ==# '-'
155 +
        while l:i < l:length && a:line[l:i] !=# ' '
156 +
          let l:i = l:i + 1
157 +
        endwhile
158 +
      else
159 +
        let l:c = ''
160 +
        while l:i < l:length && a:line[l:i] !=# ' '
161 +
          let l:c = a:line[l:i]
162 +
          let l:option = l:option . l:c
163 +
          let l:i = l:i + 1
164 +
        endwhile
165 +
        if l:c ==# 'e'
166 +
          let l:force_pattern = 1
167 +
        endif
168 +
      endif
169 +
    else
170 +
      let l:pattern = ''
171 +
      " allow pattern includes blanks.
172 +
      while l:i < l:length
173 +
        if a:line[l:i] ==# "'"
174 +
          let l:pattern = l:pattern . g:Gtags_Single_Quote_Char
175 +
        elseif a:line[l:i] ==# '"'
176 +
          let l:pattern = l:pattern . g:Gtags_Double_Quote_Char
177 +
        else
178 +
          let l:pattern = l:pattern . a:line[l:i]
179 +
        endif
180 +
        let l:i = l:i + 1
181 +
      endwhile
182 +
      if a:target ==# 'pattern'
183 +
        return l:pattern
184 +
      endif
185 +
    endif
186 +
    " Skip blanks.
187 +
    while l:i < l:length && a:line[l:i] ==# ' '
188 +
      let l:i = l:i + 1
189 +
    endwhile
190 +
  endwhile
191 +
  if a:target ==# 'option'
192 +
    return l:option
193 +
  endif
194 +
  return ''
195 +
endfunction
196 +
197 +
"
198 +
" Trim options to avoid errors.
199 +
"
200 +
function! s:TrimOption(option) abort
201 +
  let l:option = ''
202 +
  let l:length = strlen(a:option)
203 +
  let l:i = 0
204 +
205 +
  while l:i < l:length
206 +
    let l:c = a:option[l:i]
207 +
    if l:c !~# '[cenpquv]'
208 +
      let l:option = l:option . l:c
209 +
    endif
210 +
    let l:i = l:i + 1
211 +
  endwhile
212 +
  return l:option
213 +
endfunction
214 +
215 +
"
216 +
" Execute global and load the result into quickfix window.
217 +
"
218 +
function! s:ExecLoad(option, long_option, pattern) abort
219 +
  " Execute global(1) command and write the result to a temporary file.
220 +
  let l:isfile = 0
221 +
  let l:option = ''
222 +
  let l:result = ''
223 +
224 +
  if a:option =~# 'f'
225 +
    let l:isfile = 1
226 +
    if filereadable(a:pattern) == 0
227 +
      call s:Error('File ' . a:pattern . ' not found.')
228 +
      return
229 +
    endif
230 +
  endif
231 +
  if a:long_option !=# ''
232 +
    let l:option = a:long_option . ' '
233 +
  endif
234 +
  " if s:version[0] > 6 || (s:version[0] == 6 && s:version[1] >= 5)
235 +
  " let l:option = l:option . '--nearness=' . expand('%:p:h') . ' '
236 +
  " endif
237 +
  let l:option = l:option . '--result=' . g:Gtags_Result . ' -q'
238 +
  let l:option = l:option . s:TrimOption(a:option)
239 +
  if l:isfile == 1
240 +
    let l:cmd = g:gtags_global_command . ' ' . l:option . ' ' . g:Gtags_Shell_Quote_Char . a:pattern . g:Gtags_Shell_Quote_Char
241 +
  else
242 +
    let l:cmd = g:gtags_global_command . ' ' . l:option . 'e ' . g:Gtags_Shell_Quote_Char . a:pattern . g:Gtags_Shell_Quote_Char
243 +
  endif
244 +
245 +
  let l:restore_gtagsroot = 0
246 +
  if empty($GTAGSROOT)
247 +
    let $GTAGSROOT = SpaceVim#plugins#projectmanager#current_root()
248 +
    let l:restore_gtagsroot = 1
249 +
  endif
250 +
251 +
  let l:restore_gtagsdbpath = 0
252 +
  if empty($GTAGSDBPATH)
253 +
    let $GTAGSDBPATH = s:FILE.unify_path(g:gtags_cache_dir) . s:FILE.path_to_fname($GTAGSROOT)
254 +
    let l:restore_gtagsdbpath = 1
255 +
  endif
256 +
257 +
  let l:result = system(l:cmd)
258 +
259 +
  " restore $GTAGSROOT and $GTAGSDBPATH to make it possible to switch
260 +
  " between multiple projects or parent/child projects
261 +
  if l:restore_gtagsroot
262 +
    let $GTAGSROOT = ''
263 +
  endif
264 +
265 +
  if l:restore_gtagsdbpath
266 +
    let $GTAGSDBPATH = ''
267 +
  endif
268 +
269 +
  e
270 +
  if v:shell_error != 0
271 +
    if v:shell_error == 2
272 +
      call s:Error('invalid arguments. (gtags.vim requires GLOBAL 5.7 or later)')
273 +
    elseif v:shell_error == 3
274 +
      call s:Error('GTAGS not found.')
275 +
    else
276 +
      call s:Error('global command failed. command line: ' . l:cmd)
277 +
    endif
278 +
    return
279 +
  endif
280 +
  if l:result ==# ''
281 +
    if a:option =~# 'f'
282 +
      call s:Error('No tags found in ' . a:pattern)
283 +
    elseif a:option =~# 'P'
284 +
      call s:Error('No path matches found for ' . a:pattern)
285 +
    elseif a:option =~# 'g'
286 +
      call s:Error('No line matches found for ' . a:pattern)
287 +
    else
288 +
      call s:Error('No tag matches found for ' . g:Gtags_Shell_Quote_Char . a:pattern . g:Gtags_Shell_Quote_Char)
289 +
    endif
290 +
    return
291 +
  endif
292 +
293 +
  call s:Memorize()
294 +
295 +
  " Open the quickfix window
296 +
  if g:gtags_open_list == 1
297 +
    botright copen
298 +
  elseif g:gtags_open_list == 2
299 +
    call s:save_prev_windows()
300 +
    botright copen
301 +
    call s:restore_prev_windows()
302 +
  endif
303 +
  " Parse the output of 'global -x or -t' and show in the quickfix window.
304 +
  let l:efm_org = &efm
305 +
  let &efm = g:Gtags_Efm
306 +
  cexpr! l:result
307 +
  let &efm = l:efm_org
308 +
endfunction
309 +
310 +
let s:prev_windows = []
311 +
function! s:save_prev_windows() abort
312 +
  let aw = winnr('#')
313 +
  let pw = winnr()
314 +
  if exists('*win_getid')
315 +
    let aw_id = win_getid(aw)
316 +
    let pw_id = win_getid(pw)
317 +
  else
318 +
    let aw_id = 0
319 +
    let pw_id = 0
320 +
  endif
321 +
  call add(s:prev_windows, [aw, pw, aw_id, pw_id])
322 +
endfunction
323 +
324 +
function! s:restore_prev_windows() abort
325 +
  let [aw, pw, aw_id, pw_id] = remove(s:prev_windows, 0)
326 +
  if winnr() != pw
327 +
    " Go back, maintaining the '#' window (CTRL-W_p).
328 +
    if pw_id
329 +
      let aw = win_id2win(aw_id)
330 +
      let pw = win_id2win(pw_id)
331 +
    endif
332 +
    if pw
333 +
      if aw
334 +
        exec aw . 'wincmd w'
335 +
      endif
336 +
      exec pw . 'wincmd w'
337 +
    endif
338 +
  endif
339 +
endfunction
340 +
341 +
"
342 +
" RunGlobal()
343 +
"
344 +
function! gtags#global(line) abort
345 +
  call gtags#logger#log('info', a:line)
346 +
  let l:pattern = s:Extract(a:line, 'pattern')
347 +
348 +
  if l:pattern ==# '%'
349 +
    let l:pattern = expand('%')
350 +
  elseif l:pattern ==# '#'
351 +
    let l:pattern = expand('#')
352 +
  endif
353 +
  let l:option = s:Extract(a:line, 'option')
354 +
  " If no pattern supplied then get it from user.
355 +
  if l:pattern ==# '' && l:option !=# 'P'
356 +
    let s:option = l:option
357 +
    if l:option =~# 'f'
358 +
      let l:line = input('Gtags for file: ', expand('%'), 'file')
359 +
    else
360 +
      let l:line = input('Gtags for pattern: ', expand('<cword>'), 'custom,GtagsCandidateCore')
361 +
    endif
362 +
    let l:pattern = s:Extract(l:line, 'pattern')
363 +
    if l:pattern ==# ''
364 +
      call s:Error('Pattern not specified.')
365 +
      return
366 +
    endif
367 +
  endif
368 +
  call s:ExecLoad(l:option, '', l:pattern)
369 +
endfunction
370 +
371 +
"
372 +
" Execute RunGlobal() depending on the current position.
373 +
"
374 +
function! gtags#cursor() abort
375 +
  let l:pattern = expand('<cword>')
376 +
  let l:option = "--from-here=\"" . line('.') . ':' . expand('%') . "\""
377 +
  call s:ExecLoad('', l:option, l:pattern)
378 +
endfunction
379 +
380 +
"
381 +
" Core Gtags function
382 +
"
383 +
function! gtags#func(type, pattern) abort
384 +
  let l:option = ''
385 +
  if a:type ==# 'g'
386 +
    let l:option .= ' -x '
387 +
  elseif a:type ==# 'r'
388 +
    let l:option .= ' -x -r '
389 +
  elseif a:type ==# 's'
390 +
    let l:option .= ' -x -s '
391 +
  elseif a:type ==# 'e'
392 +
    let l:option .= ' -x -g '
393 +
  elseif a:type ==# 'f'
394 +
    let l:option .= ' -x -P '
395 +
  endif
396 +
  call s:ExecLoad('', l:option, a:pattern)
397 +
endfunction
398 +
399 +
"
400 +
" Show the current position on mozilla.
401 +
" (You need to execute htags(1) in your source directory.)
402 +
"
403 +
function! gtags#gozilla() abort
404 +
  let l:lineno = line('.')
405 +
  let l:filename = expand('%')
406 +
  call system('gozilla +' . l:lineno . ' ' . l:filename)
407 +
endfunction
408 +
409 +
"
410 +
" Custom completion.
411 +
"
412 +
function! gtags#complete(lead, line, pos) abort
413 +
  let s:option = s:Extract(a:line, 'option')
414 +
  return s:GtagsCandidateCore(a:lead, a:line, a:pos)
415 +
endfunction
416 +
417 +
function! s:GtagsCandidateCore(lead, ...) abort
418 +
  if s:option ==# 'g'
419 +
    return ''
420 +
  elseif s:option ==# 'f'
421 +
    if isdirectory(a:lead)
422 +
      if a:lead =~# '/$'
423 +
        let l:pattern = a:lead . '*'
424 +
      else
425 +
        let l:pattern = a:lead . '/*'
426 +
      endif
427 +
    else
428 +
      let l:pattern = a:lead . '*'
429 +
    endif
430 +
    return glob(l:pattern)
431 +
  else
432 +
    let l:cands = system(g:gtags_global_command . ' ' . '-c' . s:option . ' ' . a:lead)
433 +
    if v:shell_error == 0
434 +
      return l:cands
435 +
    endif
436 +
    return ''
437 +
  endif
438 +
endfunction
439 +
440 +
function! gtags#show_lib_path() abort
441 +
  echo $GTAGSLIBPATH
442 +
endfunction
443 +
444 +
function! gtags#add_lib(path) abort
445 +
  let $GTAGSLIBPATH .= ':'.a:path
446 +
  echo $GTAGSLIBPATH
447 +
endfunction
448 +
449 +
450 +
function! gtags#update(single_update) abort
451 +
  let dir = s:FILE.unify_path(g:tags_cache_dir) 
452 +
        \ . s:FILE.path_to_fname(SpaceVim#plugins#projectmanager#current_root())
453 +
  let cmd = ['gtags']
454 +
  if !empty(g:gtags_gtagslabel)
455 +
    let cmd += ['--gtagslabel=' . g:gtags_gtagslabel]
456 +
  endif
457 +
  if a:single_update && filereadable(dir . '/GTAGS')
458 +
    let cmd += ['--single-update', expand('%:p')]
459 +
  else
460 +
    let cmd += ['--skip-unreadable']
461 +
  endif
462 +
  if !isdirectory(dir)
463 +
    call mkdir(dir, 'p')
464 +
  endif
465 +
  let cmd += ['-O', dir]
466 +
  call s:JOB.start(cmd, {'on_exit' : funcref('s:on_update_exit')})
467 +
endfunction
468 +
469 +
function! s:on_update_exit(...) abort
470 +
  if str2nr(a:2) > 0 && !g:gtags_silent
471 +
    call s:LOGGER.warn('failed to update gtags, exit data: ' . a:2)
472 +
  endif
473 +
endfunction
474 +

@@ -0,0 +1,30 @@
Loading
1 +
scriptencoding utf-8
2 +
3 +
let s:LOG = SpaceVim#api#import('logger')
4 +
5 +
call s:LOG.set_name('Gtags')
6 +
7 +
""
8 +
" set the path to gtags log file.
9 +
let g:gtags_log_file = get(g:, 'gtags_log_file', '')
10 +
11 +
if !empty(g:gtags_log_file)
12 +
    call s:LOG.set_file(g:gtags_log_file)
13 +
endif
14 +
15 +
function! gtags#logger#log(level, msg) abort
16 +
    if a:level ==# 'info'
17 +
        call s:LOG.info(a:msg)
18 +
    elseif a:level ==# 'warn'
19 +
        call s:LOG.warn(a:msg)
20 +
    elseif a:level ==# 'error'
21 +
        call s:LOG.error(a:msg)
22 +
    endif
23 +
endfunction
24 +
25 +
function! gtags#logger#view(...)
26 +
    echo s:LOG.view(get(a:000, 0, 'info'))
27 +
endfunction
28 +
29 +
30 +

@@ -14,7 +14,7 @@
Loading
14 14
15 15
let s:CMP = SpaceVim#api#import('vim#compatible')
16 16
17 -
function! SpaceVim#layers#leaderf#loadable()
17 +
function! SpaceVim#layers#leaderf#loadable() abort
18 18
19 19
  return s:CMP.has('python') || s:CMP.has('python3')
20 20
@@ -50,127 +50,127 @@
Loading
50 50
51 51
  let g:Lf_Extensions = get(g:, 'Lf_Extensions', {})
52 52
  let g:Lf_Extensions = {
53 -
  \ "neomru": {
54 -
  \       "source": string(s:_function('s:neomru', 1))[10:-3],
55 -
  \       "accept": string(s:_function('s:neomru_acp', 1))[10:-3],
56 -
  \       "supports_name_only": 1,
57 -
  \       "supports_multi": 0,
53 +
  \ 'neomru': {
54 +
  \       'source': string(s:_function('s:neomru', 1))[10:-3],
55 +
  \       'accept': string(s:_function('s:neomru_acp', 1))[10:-3],
56 +
  \       'supports_name_only': 1,
57 +
  \       'supports_multi': 0,
58 58
  \ },
59 59
  \}
60 60
61 61
  let g:Lf_Extensions.menu =
62 62
        \ {
63 -
        \       "source": string(s:_function('s:menu', 1))[10:-3],
64 -
        \       "arguments": [
65 -
        \           { "name": ["--name"], "nargs": 1, "help": "Use leaderf show unite menu"},
63 +
        \       'source': string(s:_function('s:menu', 1))[10:-3],
64 +
        \       'arguments': [
65 +
        \           { 'name': ['--name'], 'nargs': 1, 'help': 'Use leaderf show unite menu'},
66 66
        \       ],
67 -
        \       "accept": string(s:_function('s:accept', 1))[10:-3],
67 +
        \       'accept': string(s:_function('s:accept', 1))[10:-3],
68 68
        \ }
69 69
70 70
  let g:Lf_Extensions.register =
71 71
        \ {
72 -
        \       "source": string(s:_function('s:register', 1))[10:-3],
73 -
        \       "accept": string(s:_function('s:register_acp', 1))[10:-3],
74 -
        \       "highlights_def": {
75 -
        \               "Lf_register_name": '^".',
76 -
        \               "Lf_register_content": '\s\+.*',
72 +
        \       'source': string(s:_function('s:register', 1))[10:-3],
73 +
        \       'accept': string(s:_function('s:register_acp', 1))[10:-3],
74 +
        \       'highlights_def': {
75 +
        \               'Lf_register_name': '^".',
76 +
        \               'Lf_register_content': '\s\+.*',
77 77
        \       },
78 -
        \       "highlights_cmd": [
79 -
        \               "hi def link Lf_register_name ModeMsg",
80 -
        \               "hi def link Lf_register_content Normal",
78 +
        \       'highlights_cmd': [
79 +
        \               'hi def link Lf_register_name ModeMsg',
80 +
        \               'hi def link Lf_register_content Normal',
81 81
        \       ],
82 82
        \  'after_enter' : string(s:_function('s:init_leaderf_win', 1))[10:-3]
83 83
        \ }
84 84
85 85
  let g:Lf_Extensions.jumplist =
86 86
        \ {
87 -
        \       "source": string(s:_function('s:jumplist', 1))[10:-3],
88 -
        \       "accept": string(s:_function('s:jumplist_acp', 1))[10:-3],
89 -
        \       "highlights_def": {
90 -
        \               "Lf_register_name": '^".',
91 -
        \               "Lf_register_content": '\s\+.*',
87 +
        \       'source': string(s:_function('s:jumplist', 1))[10:-3],
88 +
        \       'accept': string(s:_function('s:jumplist_acp', 1))[10:-3],
89 +
        \       'highlights_def': {
90 +
        \               'Lf_register_name': '^".',
91 +
        \               'Lf_register_content': '\s\+.*',
92 92
        \       },
93 -
        \       "highlights_cmd": [
94 -
        \               "hi def link Lf_register_name ModeMsg",
95 -
        \               "hi def link Lf_register_content Normal",
93 +
        \       'highlights_cmd': [
94 +
        \               'hi def link Lf_register_name ModeMsg',
95 +
        \               'hi def link Lf_register_content Normal',
96 96
        \       ],
97 97
        \  'after_enter' : string(s:_function('s:init_leaderf_win', 1))[10:-3]
98 98
        \ }
99 99
100 100
  let g:Lf_Extensions.message =
101 101
        \ {
102 -
        \       "source": string(s:_function('s:message', 1))[10:-3],
103 -
        \       "accept": string(s:_function('s:message_acp', 1))[10:-3],
104 -
        \       "highlights_def": {
105 -
        \               "Lf_register_name": '^".',
106 -
        \               "Lf_register_content": '\s\+.*',
102 +
        \       'source': string(s:_function('s:message', 1))[10:-3],
103 +
        \       'accept': string(s:_function('s:message_acp', 1))[10:-3],
104 +
        \       'highlights_def': {
105 +
        \               'Lf_register_name': '^".',
106 +
        \               'Lf_register_content': '\s\+.*',
107 107
        \       },
108 -
        \       "highlights_cmd": [
109 -
        \               "hi def link Lf_register_name ModeMsg",
110 -
        \               "hi def link Lf_register_content Normal",
108 +
        \       'highlights_cmd': [
109 +
        \               'hi def link Lf_register_name ModeMsg',
110 +
        \               'hi def link Lf_register_content Normal',
111 111
        \       ],
112 112
        \  'after_enter' : string(s:_function('s:init_leaderf_win', 1))[10:-3]
113 113
        \ }
114 114
115 115
  let g:Lf_Extensions.neoyank =
116 116
        \ {
117 -
        \       "source": string(s:_function('s:neoyank', 1))[10:-3],
118 -
        \       "accept": string(s:_function('s:neoyank_acp', 1))[10:-3],
119 -
        \       "highlights_def": {
120 -
        \               "Lf_register_name": '^".',
121 -
        \               "Lf_register_content": '\s\+.*',
117 +
        \       'source': string(s:_function('s:neoyank', 1))[10:-3],
118 +
        \       'accept': string(s:_function('s:neoyank_acp', 1))[10:-3],
119 +
        \       'highlights_def': {
120 +
        \               'Lf_register_name': '^".',
121 +
        \               'Lf_register_content': '\s\+.*',
122 122
        \       },
123 -
        \       "highlights_cmd": [
124 -
        \               "hi def link Lf_register_name ModeMsg",
125 -
        \               "hi def link Lf_register_content Normal",
123 +
        \       'highlights_cmd': [
124 +
        \               'hi def link Lf_register_name ModeMsg',
125 +
        \               'hi def link Lf_register_content Normal',
126 126
        \       ],
127 127
        \  'after_enter' : string(s:_function('s:init_leaderf_win', 1))[10:-3]
128 128
        \ }
129 129
130 130
  let g:Lf_Extensions.quickfix =
131 131
        \ {
132 -
        \       "source": string(s:_function('s:quickfix', 1))[10:-3],
133 -
        \       "accept": string(s:_function('s:quickfix_acp', 1))[10:-3],
134 -
        \       "highlights_def": {
135 -
        \               "Lf_register_name": '^".',
136 -
        \               "Lf_register_content": '\s\+.*',
132 +
        \       'source': string(s:_function('s:quickfix', 1))[10:-3],
133 +
        \       'accept': string(s:_function('s:quickfix_acp', 1))[10:-3],
134 +
        \       'highlights_def': {
135 +
        \               'Lf_register_name': '^".',
136 +
        \               'Lf_register_content': '\s\+.*',
137 137
        \       },
138 -
        \       "highlights_cmd": [
139 -
        \               "hi def link Lf_register_name ModeMsg",
140 -
        \               "hi def link Lf_register_content Normal",
138 +
        \       'highlights_cmd': [
139 +
        \               'hi def link Lf_register_name ModeMsg',
140 +
        \               'hi def link Lf_register_content Normal',
141 141
        \       ],
142 142
        \  'after_enter' : string(s:_function('s:init_leaderf_win', 1))[10:-3]
143 143
        \ }
144 144
145 145
  let g:Lf_Extensions.locationlist =
146 146
        \ {
147 -
        \       "source": string(s:_function('s:locationlist', 1))[10:-3],
148 -
        \       "accept": string(s:_function('s:locationlist_acp', 1))[10:-3],
149 -
        \       "highlights_def": {
150 -
        \               "Lf_register_name": '^".',
151 -
        \               "Lf_register_content": '\s\+.*',
147 +
        \       'source': string(s:_function('s:locationlist', 1))[10:-3],
148 +
        \       'accept': string(s:_function('s:locationlist_acp', 1))[10:-3],
149 +
        \       'highlights_def': {
150 +
        \               'Lf_register_name': '^".',
151 +
        \               'Lf_register_content': '\s\+.*',
152 152
        \       },
153 -
        \       "highlights_cmd": [
154 -
        \               "hi def link Lf_register_name ModeMsg",
155 -
        \               "hi def link Lf_register_content Normal",
153 +
        \       'highlights_cmd': [
154 +
        \               'hi def link Lf_register_name ModeMsg',
155 +
        \               'hi def link Lf_register_content Normal',
156 156
        \       ],
157 157
        \  'after_enter' : string(s:_function('s:init_leaderf_win', 1))[10:-3]
158 158
        \ }
159 159
160 160
  let g:Lf_Extensions.unicode =
161 161
        \ {
162 -
        \       "source": string(s:_function('s:unicode', 1))[10:-3],
163 -
        \       "accept": string(s:_function('s:unicode_acp', 1))[10:-3],
164 -
        \       "arguments": [
165 -
        \           { "name": ["--name"], "nargs": '*', "help": "Use leaderf show unite menu"},
162 +
        \       'source': string(s:_function('s:unicode', 1))[10:-3],
163 +
        \       'accept': string(s:_function('s:unicode_acp', 1))[10:-3],
164 +
        \       'arguments': [
165 +
        \           { 'name': ['--name'], 'nargs': '*', 'help': 'Use leaderf show unite menu'},
166 166
        \       ],
167 -
        \       "highlights_def": {
168 -
        \               "Lf_register_name": '^".',
169 -
        \               "Lf_register_content": '\s\+.*',
167 +
        \       'highlights_def': {
168 +
        \               'Lf_register_name': '^".',
169 +
        \               'Lf_register_content': '\s\+.*',
170 170
        \       },
171 -
        \       "highlights_cmd": [
172 -
        \               "hi def link Lf_register_name ModeMsg",
173 -
        \               "hi def link Lf_register_content Normal",
171 +
        \       'highlights_cmd': [
172 +
        \               'hi def link Lf_register_name ModeMsg',
173 +
        \               'hi def link Lf_register_content Normal',
174 174
        \       ],
175 175
        \  'after_enter' : string(s:_function('s:init_leaderf_win', 1))[10:-3]
176 176
        \ }
@@ -301,16 +301,16 @@
Loading
301 301
  call s:defind_fuzzy_finder()
302 302
endfunction
303 303
304 -
function! s:init_leaderf_win(...)
304 +
function! s:init_leaderf_win(...) abort
305 305
  setlocal nonumber
306 306
  setlocal nowrap
307 307
endfunction
308 308
309 -
function! s:register(...)
309 +
function! s:register(...) abort
310 310
  return split(s:CMP.execute('registers'), '\n')[1:]
311 311
endfunction
312 312
313 -
function! s:register_acp(line, args)
313 +
function! s:register_acp(line, args) abort
314 314
  let @" = a:line
315 315
  echohl ModeMsg
316 316
  echon 'Yanked!'
@@ -365,7 +365,7 @@
Loading
365 365
  echohl None
366 366
endfunction
367 367
368 -
func! s:neoyank(...)
368 +
func! s:neoyank(...) abort
369 369
  let yank = []
370 370
  for text in neoyank#_get_yank_histories()['"']
371 371
    call add(yank, '": ' . join(split(text[0], "\n"), '\n'))
@@ -378,7 +378,7 @@
Loading
378 378
  call append(0, split(line, '\\n'))
379 379
endfunction
380 380
381 -
function! s:menu(name)
381 +
function! s:menu(name) abort
382 382
  let s:menu_action = {}
383 383
  let menu = get(g:unite_source_menu_menus, a:name['--name'][0], {})
384 384
  if has_key(menu, 'command_candidates')
@@ -393,7 +393,7 @@
Loading
393 393
  endif
394 394
endfunction
395 395
396 -
function! s:accept(line, args)
396 +
function! s:accept(line, args) abort
397 397
  let action = get(s:menu_action, a:line, '')
398 398
  exe action
399 399
endfunction
@@ -451,7 +451,7 @@
Loading
451 451
    let glyph = matchstr(a:line, ';\x\{4,5}')
452 452
    let writable = nr2char(str2nr(glyph[1:], 16))
453 453
454 -
    exe "norm! a" . eval("\"" . writable . "\"")
454 +
    exe 'norm! a' . eval("\"" . writable . "\"")
455 455
    " echo printf("%s%s", writable, glyph)
456 456
  else
457 457
    exe 'Leaderf unicode --name ' . a:line
@@ -548,6 +548,16 @@
Loading
548 548
        \ 'Definition: ' . s:file . ':' . lnum,
549 549
        \ ]
550 550
        \ ]
551 +
  nnoremap <silent> <Leader>ft :<C-u>Leaderf tag<CR>
552 +
  let lnum = expand('<slnum>') + s:unite_lnum - 4
553 +
  let g:_spacevim_mappings.f.t = ['Leaderf tag',
554 +
        \ 'fuzzy find tags',
555 +
        \ [
556 +
        \ '[Leader f t] is to fuzzy find tags',
557 +
        \ '',
558 +
        \ 'Definition: ' . s:file . ':' . lnum,
559 +
        \ ]
560 +
        \ ]
551 561
  nnoremap <silent> <Leader>f<Space> :<C-u>Leaderf menu --name CustomKeyMaps<CR>
552 562
  let g:_spacevim_mappings.f['[SPC]'] = ['Leaderf menu --name CustomKeyMaps',
553 563
        \ 'fuzzy find custom key bindings',
@@ -570,7 +580,7 @@
Loading
570 580
endfunction
571 581
572 582
function! s:accept_mru(line) abort
573 -
  exe 'e ' . line
583 +
  exe 'e ' . a:line
574 584
endfunction
575 585
576 586
function! s:warp_denite(cmd) abort
Files Coverage
.SpaceVim.d/autoload/SpaceVim 0.00%
autoload 3.12%
bundle 2.43%
config 29.92%
ftplugin 23.33%
syntax 94.48%
.ci/common/github_commenter.vim 0.00%
after/syntax/help.vim 0.00%
colors/SpaceVim.vim 0.00%
filetype.vim 100.00%
ginit.vim 0.00%
init.vim 0.00%
test/vimrc 100.00%
vimrc 30.77%
Project Totals (1601 files) 3.13%
11749.19
TRAVIS_PYTHON_VERSION=3.6
TRAVIS_OS_NAME=linux
11749.18
TRAVIS_PYTHON_VERSION=3.6
TRAVIS_OS_NAME=linux
11748.15
TRAVIS_PYTHON_VERSION=3.6
TRAVIS_OS_NAME=linux
11748.14
TRAVIS_PYTHON_VERSION=3.6
TRAVIS_OS_NAME=linux
11748.17
TRAVIS_PYTHON_VERSION=3.6
TRAVIS_OS_NAME=linux
11748.16
TRAVIS_PYTHON_VERSION=3.6
TRAVIS_OS_NAME=linux
11748.19
TRAVIS_PYTHON_VERSION=3.6
TRAVIS_OS_NAME=linux
11748.18
TRAVIS_PYTHON_VERSION=3.6
TRAVIS_OS_NAME=linux
11749.15
TRAVIS_PYTHON_VERSION=3.6
TRAVIS_OS_NAME=linux
11749.14
TRAVIS_PYTHON_VERSION=3.6
TRAVIS_OS_NAME=linux
11749.17
TRAVIS_PYTHON_VERSION=3.6
TRAVIS_OS_NAME=linux
11749.16
TRAVIS_PYTHON_VERSION=3.6
TRAVIS_OS_NAME=linux
1
comment: off
2
codecov:
3
  branch: master
4
coverage:
5
  status:
6
    patch:
7
      default: false
8
    project:
9
      default: false  # disable the default status that measures entire project
10
      api:  # declare a new status context "api"
11
        target: 1%  # we always want 35% coverage here
12
        paths:
13
          - "autoload/SpaceVim/api/"  # only include coverage in "autoload/SpaceVim/api/" folder
14
      plugins:  # declare a new status context "api"
15
        target: 1%  # we always want 35% coverage here
16
        paths:
17
          - "autoload/SpaceVim/plugins/"  # only include coverage in "autoload/SpaceVim/api/" folder
18
      all:  # declare a new status context "all"
19
        target: 1%  # we always want 35% coverage here
20
        paths:
21
          - "!tests/"  # remove all files in "tests/"
22
          - "!bundle/"  # remove all files in "tests/"
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.