From 34a95983ed0c56490e07478387c8a365661e6429 Mon Sep 17 00:00:00 2001 From: raven42 Date: Mon, 19 Oct 2020 12:16:36 -0500 Subject: [PATCH] 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. --- autoload/tagbar/prototypes/typeinfo.vim | 3 ++- autoload/tagbar/sorting.vim | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/autoload/tagbar/prototypes/typeinfo.vim b/autoload/tagbar/prototypes/typeinfo.vim index 67dbbca..1ed9588 100644 --- a/autoload/tagbar/prototypes/typeinfo.vim +++ b/autoload/tagbar/prototypes/typeinfo.vim @@ -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 diff --git a/autoload/tagbar/sorting.vim b/autoload/tagbar/sorting.vim index 2d24ecb..b03faff 100644 --- a/autoload/tagbar/sorting.vim +++ b/autoload/tagbar/sorting.vim @@ -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