1
0
mirror of https://github.com/gryf/tagbar.git synced 2025-12-17 11:30:28 +01:00

Fix tag jumping if tag pattern is not actually a pattern

Closes #439
References jstemmer/gotags#31
This commit is contained in:
Jan Larres
2017-09-03 20:36:07 +12:00
parent 937354ebb5
commit 7299257d77

View File

@@ -1167,15 +1167,19 @@ function! s:ParseTagline(part1, part2, typeinfo, fileinfo) abort
" the pattern can contain tabs and thus may have been split up, so join
" the rest of the items together again
let pattern = join(basic_info[2:], "\t")
let start = 2 " skip the slash and the ^
let end = strlen(pattern) - 1
if pattern[end - 1] ==# '$'
let end -= 1
let dollar = '\$'
if pattern[0] == '/'
let start = 2 " skip the slash and the ^
let end = strlen(pattern) - 1
if pattern[end - 1] ==# '$'
let end -= 1
let dollar = '\$'
else
let dollar = ''
endif
let pattern = '\V\^\C' . strpart(pattern, start, end - start) . dollar
else
let dollar = ''
let pattern = ''
endif
let pattern = '\M\^\C' . strpart(pattern, start, end - start) . dollar
" When splitting fields make sure not to create empty keys or values in
" case a value illegally contains tabs
@@ -1959,23 +1963,27 @@ function! s:JumpToTag(stay_in_tagbar) abort
" Jump to the line where the tag is defined. Don't use the search pattern
" since it doesn't take the scope into account and thus can fail if tags
" with the same name are defined in different scopes (e.g. classes)
call tagbar#debug#log('Jumping to line ' . taginfo.fields.line)
execute taginfo.fields.line
" If the file has been changed but not saved, the tag may not be on the
" saved line anymore, so search for it in the vicinity of the saved line
if match(getline('.'), taginfo.pattern) == -1
let interval = 1
let forward = 1
while search(taginfo.pattern, 'W' . forward ? '' : 'b') == 0
if !forward
if interval > line('$')
break
else
let interval = interval * 2
if taginfo.pattern != ''
call tagbar#debug#log('Searching for pattern "' . taginfo.pattern . '"')
if match(getline('.'), taginfo.pattern) == -1
let interval = 1
let forward = 1
while search(taginfo.pattern, 'W' . forward ? '' : 'b') == 0
if !forward
if interval > line('$')
break
else
let interval = interval * 2
endif
endif
endif
let forward = !forward
endwhile
let forward = !forward
endwhile
endif
endif
" If the tag is on a different line after unsaved changes update the tag
@@ -2065,9 +2073,13 @@ function! s:ShowInPreviewWin() abort
" find the correct tag in case of tags with the same name and to speed up
" the searching. Unfortunately the /\%l pattern doesn't seem to work with
" psearch.
let pattern = taginfo.pattern
if pattern == ''
let pattern = '\V\^' . escape(getline(taginfo.fields.line), '\') . '\$'
endif
let include_save = &include
set include=
silent! execute taginfo.fields.line . ',$psearch! /' . taginfo.pattern . '/'
silent! execute taginfo.fields.line . ',$psearch! /' . pattern . '/'
let &include = include_save
call s:goto_win('P', 1)