Add protection for unknown kinds

Perform a has_key() check prior to referencing the dictionary to ensure
the dictionary has a valid key for the specified kind.
Note: When an unknown kind is found, it can mess up the tag highlighting
in the tagbar window. Not sure why this is occurring.
This commit is contained in:
raven42 2020-10-19 12:16:36 -05:00
parent 98efae9899
commit 34a95983ed
2 changed files with 8 additions and 1 deletions

View File

@ -15,7 +15,8 @@ endfunction
" s:getKind() {{{1
function! s:getKind(kind) abort dict
let idx = self.kinddict[a:kind]
"let idx = self.kinddict[a:kind]
let idx = has_key(self.kinddict, a:kind) ? self.kinddict[a:kind] : -1
return self.kinds[idx]
endfunction

View File

@ -21,6 +21,12 @@ endfunction
function! s:compare_by_kind(tag1, tag2) abort
let typeinfo = s:compare_typeinfo
if !has_key(typeinfo.kinddict, a:tag1.fields.kind)
return -1
endif
if !has_key(typeinfo.kinddict, a:tag2.fields.kind)
return 1
endif
if typeinfo.kinddict[a:tag1.fields.kind] <#
\ typeinfo.kinddict[a:tag2.fields.kind]
return -1