From 3634e7ab4feeab8ad49166e9e716638c20f1637c Mon Sep 17 00:00:00 2001 From: Jan Larres Date: Tue, 17 Mar 2015 19:35:42 +1300 Subject: [PATCH] Support 'kind' field with name, ref #254 --- autoload/tagbar.vim | 21 ++++++++++++++++++--- doc/tagbar.txt | 9 +++++---- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/autoload/tagbar.vim b/autoload/tagbar.vim index 49b2eff..45a8f08 100644 --- a/autoload/tagbar.vim +++ b/autoload/tagbar.vim @@ -2077,8 +2077,10 @@ function! s:ProcessFile(fname, ftype) abort let parts = split(line, ';"') if len(parts) == 2 " Is a valid tag line let taginfo = s:ParseTagline(parts[0], parts[1], typeinfo, fileinfo) - let fileinfo.fline[taginfo.fields.line] = taginfo - call add(fileinfo.tags, taginfo) + if !empty(taginfo) + let fileinfo.fline[taginfo.fields.line] = taginfo + call add(fileinfo.tags, taginfo) + endif endif endfor @@ -2255,7 +2257,9 @@ function! s:ParseTagline(part1, part2, typeinfo, fileinfo) abort " When splitting fields make sure not to create empty keys or values in " case a value illegally contains tabs let fields = split(a:part2, '^\t\|\t\ze\w\+:') - let taginfo.fields.kind = remove(fields, 0) + if fields[0] !~# ':' + let taginfo.fields.kind = remove(fields, 0) + endif for field in fields " can't use split() since the value can contain ':' let delimit = stridx(field, ':') @@ -2283,6 +2287,16 @@ function! s:ParseTagline(part1, part2, typeinfo, fileinfo) abort let taginfo.fields.line = 0 endif + if !has_key(taginfo.fields, 'kind') + call s:debug("Warning: No 'kind' field found for tag " . basic_info[0] . "!") + if index(s:warnings.type, a:typeinfo.ftype) == -1 + call s:warning("No 'kind' field found for tag " . basic_info[0] . "!" . + \ " Please read the last section of ':help tagbar-extend'.") + call add(s:warnings.type, a:typeinfo.ftype) + endif + return {} + endif + " Make some information easier accessible if has_key(a:typeinfo, 'scope2kind') for scope in keys(a:typeinfo.scope2kind) @@ -2314,6 +2328,7 @@ function! s:ParseTagline(part1, part2, typeinfo, fileinfo) abort \ ' Please read '':help tagbar-extend''.') call add(s:warnings.type, a:typeinfo.ftype) endif + return {} endtry return taginfo diff --git a/doc/tagbar.txt b/doc/tagbar.txt index 3b574a6..cf100ea 100644 --- a/doc/tagbar.txt +++ b/doc/tagbar.txt @@ -1202,10 +1202,11 @@ imporant tips to get it to integrate well with Tagbar: (stdout), it doesn't generate files and reads them in after that. So make sure that your program has an option to output the tags on stdout. - Some fields are supported for providing additional information about a - tag. One field is required: the "kind" field as a single letter without - a "kind:" fieldname. This field has to be the first one in the list. All - other fields need to have a fieldname in order to determine what they are. - The following fields are supported for all filetypes: + tag. One field is required: the "kind" field as a single letter, either + with or without a "kind:" fieldname. If it is used without the fieldname + then it has to be the first field in the list. All other fields need to + have a fieldname in order to determine what they are. The following fields + are supported for all filetypes: * line: The line number of the tag. * column: The column number of the tag.