From 64730d27a9e4fa0ad0901145c188699965b3c8b7 Mon Sep 17 00:00:00 2001 From: David Hegland Date: Wed, 23 Sep 2020 11:45:02 -0500 Subject: [PATCH] Added fsize calculation in fileinfo so better tracking can be used to display in tagbar window --- autoload/tagbar.vim | 41 +++++++++++++------------ autoload/tagbar/prototypes/fileinfo.vim | 7 +++++ doc/tagbar.txt | 10 ++++-- plugin/tagbar.vim | 1 + 4 files changed, 37 insertions(+), 22 deletions(-) diff --git a/autoload/tagbar.vim b/autoload/tagbar.vim index a00a8ff..6228050 100644 --- a/autoload/tagbar.vim +++ b/autoload/tagbar.vim @@ -1158,22 +1158,6 @@ function! s:ProcessFile(fname, ftype) abort return endif - " If the file size limit it set, then check the file size to see if - " this file should be ignored or not. - if g:tagbar_file_size_limit > 0 - let fsize = getfsize(expand('%')) - if fsize > g:tagbar_file_size_limit && !exists('b:tagbar_force_update') - call tagbar#debug#log('[ProcessFile] File size too large (' . fsize . - \ ' bytes) - limit set to ' . g:tagbar_file_size_limit) - if !exists('b:tagbar_file_exceeds_limit') - echom 'File size too large (' . fsize . - \ ' bytes) - Not processing file (see help for g:tagbar_file_size_limit).' - let b:tagbar_file_exceeds_limit = 1 - endif - return - endif - endif - let typeinfo = s:known_types[a:ftype] " If the file has only been updated preserve the fold states, otherwise @@ -1197,7 +1181,14 @@ function! s:ProcessFile(fname, ftype) abort call tagbar#debug#log('typeinfo for file to process: ' . string(typeinfo)) - if g:tagbar_use_cache + if g:tagbar_file_size_limit > 0 + \ && fileinfo.fsize > g:tagbar_file_size_limit + \ && !exists('b:tagbar_force_update') + call tagbar#debug#log('File size exceeds defined limit') + let fileinfo.fsize_exceeded = 1 + call s:known_files.put(fileinfo) + return + elseif g:tagbar_use_cache " Use a temporary files for ctags processing instead of the original one. " This allows using Tagbar for files accessed with netrw, and also doesn't " slow down Tagbar for files that sit on slow network drives. @@ -1216,6 +1207,7 @@ function! s:ProcessFile(fname, ftype) abort return endif let fileinfo.mtime = getftime(tempfile) + let fileinfo.fsize_exceeded = 0 let ctags_output = s:ExecuteCtagsOnFile(tempfile, a:fname, typeinfo) @@ -1224,6 +1216,7 @@ function! s:ProcessFile(fname, ftype) abort endif else call tagbar#debug#log('File caching disabled') + let fileinfo.fsize_exceeded = 0 let ctags_output = s:ExecuteCtagsOnFile(a:fname, a:fname, typeinfo) endif @@ -1864,7 +1857,16 @@ function! s:RenderContent(...) abort let typeinfo = fileinfo.typeinfo - if !empty(fileinfo.getTags()) + if fileinfo.fsize_exceeded == 1 + if g:tagbar_compact + silent 0put ='\" File size [' . fileinfo.fsize . 'B] exceeds limit' + else + silent put ='\" File size exceeds defined limit' + silent put ='\" File Size [' . fileinfo.fsize . ' bytes]' + silent put ='\" Limit [' . g:tagbar_file_size_limit . ' bytes]' + silent put ='\" Use TagbarForceUpdate override' + endif + elseif !empty(fileinfo.getTags()) " Print tags call s:PrintKinds(typeinfo, fileinfo) else @@ -3594,13 +3596,12 @@ function! tagbar#Update() abort call s:AutoUpdate(fnamemodify(expand('%'), ':p'), 0) endfunction -" tagbar#ForceUpdate() {{{2 +" tagbar#ForceUpdate() {{{2 function! tagbar#ForceUpdate() abort if !exists('b:tagbar_force_update') let b:tagbar_force_update = 1 call s:AutoUpdate(fnamemodify(expand('%'), ':p'), 1) unlet b:tagbar_force_update - unlet b:tagbar_file_exceeds_limit endif endfunction diff --git a/autoload/tagbar/prototypes/fileinfo.vim b/autoload/tagbar/prototypes/fileinfo.vim index fd275b8..934ae1a 100644 --- a/autoload/tagbar/prototypes/fileinfo.vim +++ b/autoload/tagbar/prototypes/fileinfo.vim @@ -9,6 +9,9 @@ function! tagbar#prototypes#fileinfo#new(fname, ftype, typeinfo) abort " File modification time let newobj.mtime = getftime(a:fname) + " Get file size + let newobj.fsize = getfsize(a:fname) + " The vim file type let newobj.ftype = a:ftype @@ -52,6 +55,10 @@ function! tagbar#prototypes#fileinfo#new(fname, ftype, typeinfo) abort let newobj.openKindFold = function(s:add_snr('s:openKindFold')) let newobj.closeKindFold = function(s:add_snr('s:closeKindFold')) + " This is used during file processing. If the limit is exceeded at that + " point, then mark this flag for displaying to the tagbar window + let newobj.fsize_exceeded = 0 + return newobj endfunction diff --git a/doc/tagbar.txt b/doc/tagbar.txt index 524ffc8..de551f4 100644 --- a/doc/tagbar.txt +++ b/doc/tagbar.txt @@ -311,6 +311,12 @@ COMMANDS *tagbar-commands* :TagbarDebugEnd *:TagbarDebugEnd* End debug mode, debug messages will no longer be written to the logfile. +:TagbarForceUpdate *:TagbarForceUpdate* + Forcefully update a file even if it exceeds the |g:tagbar_file_size_limit| + value. This will only work for one invocation of the file processing. + After the file is processed and tags are generated, then it will re-enable + the file size limit. So if the file is written and needs to be processed + again, this command will need to be re-executed. ------------------------------------------------------------------------------ FUNCTIONS *tagbar-functions* @@ -894,8 +900,8 @@ By default, all files are processed by tagbar. Setting this value to non-zero will disable processing for any file with a byte count greater than |g:tagbar_file_size_limit|. A message will be displayed once for a given buffer if the limit is exceeded. The file can be forcefully updated with the -|tagbar#ForceUpdate()| function. If the value is set to 0, then the file will -always be processed. +|tagbar#ForceUpdate()| function or with the |:TagbarForceUpdate| command. If +the value is set to 0, then the file will always be processed. Example: > diff --git a/plugin/tagbar.vim b/plugin/tagbar.vim index 40b66db..149abad 100644 --- a/plugin/tagbar.vim +++ b/plugin/tagbar.vim @@ -181,6 +181,7 @@ command! -nargs=1 TagbarGetTypeConfig call tagbar#gettypeconfig() command! -nargs=? TagbarDebug call tagbar#debug#start_debug() command! -nargs=0 TagbarDebugEnd call tagbar#debug#stop_debug() command! -nargs=0 TagbarTogglePause call tagbar#toggle_pause() +command! -nargs=0 TagbarForceUpdate call tagbar#ForceUpdate() " Modeline {{{1 " vim: ts=8 sw=4 sts=4 et foldenable foldmethod=marker foldcolumn=1