diff --git a/autoload/tagbar.vim b/autoload/tagbar.vim index c06e675..8901efc 100644 --- a/autoload/tagbar.vim +++ b/autoload/tagbar.vim @@ -83,6 +83,11 @@ let s:last_highlight_tline = 0 let s:debug = 0 let s:debug_file = '' +let s:warnings = { + \ 'type': [], + \ 'encoding': 0 +\ } + " s:Init() {{{2 function! s:Init(silent) abort if s:checked_ctags == 2 && a:silent @@ -801,6 +806,10 @@ function! s:InitTypes() abort let s:known_types.yacc = type_yacc " }}}3 + for [type, typeinfo] in items(s:known_types) + let typeinfo.ftype = type + endfor + call s:LoadUserTypeDefs() for typeinfo in values(s:known_types) @@ -828,6 +837,7 @@ function! s:LoadUserTypeDefs(...) abort let transformed = {} for [type, def] in items(defdict) let transformed[type] = s:TransformUserTypeDef(def) + let transformed[type].ftype = type endfor for [key, value] in items(transformed) @@ -1093,7 +1103,7 @@ function! s:CtagsErrMsg(errmsg, infomsg, silent, ...) abort endif if !a:silent - echoerr a:errmsg + call s:warning(a:errmsg) echomsg a:infomsg if ctags_cmd == '' @@ -2180,7 +2190,7 @@ function! s:ExecuteCtagsOnFile(fname, realfname, typeinfo) abort if bufwinnr("__Tagbar__") != -1 && \ (!s:known_files.has(a:realfname) || \ !empty(s:known_files.get(a:realfname))) - echoerr 'Tagbar: Could not execute ctags for ' . a:fname . '!' + call s:warning('Tagbar: Could not execute ctags for ' . a:realfname . '!') echomsg 'Executed command: "' . ctags_cmd . '"' if !empty(ctags_output) call s:debug('Command output:') @@ -2273,10 +2283,14 @@ function! s:ParseTagline(part1, part2, typeinfo, fileinfo) abort call taginfo.initFoldState() catch /^Vim(\a\+):E716:/ " 'Key not present in Dictionary' " The tag has a 'kind' that doesn't exist in the type definition - call s:debug('ERROR Unknown tag kind: ' . taginfo.fields.kind) - echoerr 'Unknown tag kind encountered: ' . taginfo.fields.kind - \ 'Your ctags and Tagbar configurations are out of sync!' - \ 'Please read '':help tagbar-extend''.' + call s:debug('Warning: Unknown tag kind: ' . taginfo.fields.kind) + if index(s:warnings.type, a:typeinfo.ftype) == -1 + call s:warning('Unknown tag kind encountered: ' . + \ '"' . taginfo.fields.kind . '".' . + \ ' Your ctags and Tagbar configurations are out of sync!' . + \ ' Please read '':help tagbar-extend''.') + call add(s:warnings.type, a:typeinfo.ftype) + endif endtry return taginfo @@ -3195,7 +3209,7 @@ endfunction " s:SetFoldLevel() {{{2 function! s:SetFoldLevel(level, force) abort if a:level < 0 - echoerr 'Foldlevel can''t be negative' + call s:warning('Foldlevel can''t be negative') return endif @@ -3494,9 +3508,11 @@ function! s:EscapeCtagsCmd(ctags_bin, args, ...) abort call s:debug('Escaped ctags command: ' . ctags_cmd) if ctags_cmd == '' - echoerr 'Tagbar: Encoding conversion failed!' - \ 'Please make sure your system is set up correctly' - \ 'and that Vim is compiled with the "+iconv" feature.' + if !s:warnings.encoding + call s:warning('Tagbar: Ctags command encoding conversion failed!' . + \ ' Please read ":h g:tagbar_systemenc".') + let s:warnings.encoding = 1 + endif endif return ctags_cmd @@ -3879,6 +3895,13 @@ function! s:goto_markedwin(...) abort endfor endfunction +" s:warning() {{{2 +function! s:warning(msg) abort + echohl WarningMsg + echomsg a:msg + echohl None +endfunction + " TagbarBalloonExpr() {{{2 function! TagbarBalloonExpr() abort let taginfo = s:GetTagInfo(v:beval_lnum, 1) @@ -4086,7 +4109,7 @@ function! tagbar#gettypeconfig(type) abort let typeinfo = get(s:known_types, a:type, {}) if empty(typeinfo) - echoerr 'Unknown type ' . a:type . '!' + call s:warning('Unknown type ' . a:type . '!') return endif