From be67ff7ae7b7be086966aa72fb32f3ec47e3a9fa Mon Sep 17 00:00:00 2001 From: raven42 Date: Mon, 14 Sep 2020 15:15:39 -0500 Subject: [PATCH 1/4] Add option to not trigger update on large files --- autoload/tagbar.vim | 24 ++++++++++++++++++++++++ doc/tagbar.txt | 19 +++++++++++++++++++ plugin/tagbar.vim | 1 + 3 files changed, 44 insertions(+) diff --git a/autoload/tagbar.vim b/autoload/tagbar.vim index ca0fdd0..26c6a9d 100644 --- a/autoload/tagbar.vim +++ b/autoload/tagbar.vim @@ -1158,6 +1158,20 @@ function! s:ProcessFile(fname, ftype) abort return endif + " If the file size limit it set, then check the linecount to see if + " this file should be ignored or not. + if g:tagbar_file_size_limit > 0 + let linecount = line('$') + if linecount > g:tagbar_file_size_limit && !exists('b:tagbar_force_update') + call tagbar#debug#log('[ProcessFile] File size too large (' . linecount . ' lines) - limit set to ' . g:tagbar_file_size_limit) + if !exists('b:tagbar_file_exceeds_limit') + echom 'File size too large (' . linecount . ' lines) - 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 @@ -3578,6 +3592,16 @@ function! tagbar#Update() abort call s:AutoUpdate(fnamemodify(expand('%'), ':p'), 0) endfunction +" 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 + " tagbar#toggle_pause() {{{2 function! tagbar#toggle_pause() abort let s:paused = !s:paused diff --git a/doc/tagbar.txt b/doc/tagbar.txt index 757c9f3..b4bc11b 100644 --- a/doc/tagbar.txt +++ b/doc/tagbar.txt @@ -337,6 +337,10 @@ FUNCTIONS *tagbar-functions* return tag . ' --- ' . lines . ' lines' endfunction < +*tagbar#ForceUpdate()* + Forcefully update a file even if it exceeds the |g:tagbar_file_size_limit| + value. This also clears the internal flags to the file will be re-examined + again. ------------------------------------------------------------------------------ KEY MAPPINGS *tagbar-keys* @@ -882,6 +886,21 @@ Example: > let g:tagbar_use_cache = 0 < + *g:tagbar_file_size_limit* +g:tagbar_file_size_limit~ +Default: 0 + +By default, all files are processed by tagbar. Setting this value to non-zero +will disable processing for any file with a line 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. + +Example: +> + let g:tagbar_file_size_limit = 10000 +< ------------------------------------------------------------------------------ HIGHLIGHT COLOURS *tagbar-highlight* diff --git a/plugin/tagbar.vim b/plugin/tagbar.vim index 7fb69a3..40b66db 100644 --- a/plugin/tagbar.vim +++ b/plugin/tagbar.vim @@ -91,6 +91,7 @@ function! s:setup_options() abort \ ['case_insensitive', 0], \ ['compact', 0], \ ['expand', 0], + \ ['file_size_limit', 0], \ ['foldlevel', 99], \ ['hide_nonpublic', 0], \ ['height', 10], From 14a86de04b447a8bda0173229587ccc077936095 Mon Sep 17 00:00:00 2001 From: raven42 Date: Wed, 16 Sep 2020 12:15:48 -0500 Subject: [PATCH 2/4] Update to use file size instead of line count --- autoload/tagbar.vim | 10 ++++++---- doc/tagbar.txt | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/autoload/tagbar.vim b/autoload/tagbar.vim index 26c6a9d..1138204 100644 --- a/autoload/tagbar.vim +++ b/autoload/tagbar.vim @@ -1158,14 +1158,16 @@ function! s:ProcessFile(fname, ftype) abort return endif - " If the file size limit it set, then check the linecount to see if + " 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 linecount = line('$') + let linecount = getfsize(expand('%')) if linecount > g:tagbar_file_size_limit && !exists('b:tagbar_force_update') - call tagbar#debug#log('[ProcessFile] File size too large (' . linecount . ' lines) - limit set to ' . g:tagbar_file_size_limit) + call tagbar#debug#log('[ProcessFile] File size too large (' . linecount . + \ ' bytes) - limit set to ' . g:tagbar_file_size_limit) if !exists('b:tagbar_file_exceeds_limit') - echom 'File size too large (' . linecount . ' lines) - Not processing file (see help for g:tagbar_file_size_limit).' + echom 'File size too large (' . linecount . + \ ' bytes) - Not processing file (see help for g:tagbar_file_size_limit).' let b:tagbar_file_exceeds_limit = 1 endif return diff --git a/doc/tagbar.txt b/doc/tagbar.txt index b4bc11b..524ffc8 100644 --- a/doc/tagbar.txt +++ b/doc/tagbar.txt @@ -891,7 +891,7 @@ g:tagbar_file_size_limit~ Default: 0 By default, all files are processed by tagbar. Setting this value to non-zero -will disable processing for any file with a line count greater than +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 From 6cb336d014e79cb8df8f66384bf994a268505fb1 Mon Sep 17 00:00:00 2001 From: raven42 Date: Wed, 16 Sep 2020 12:17:21 -0500 Subject: [PATCH 3/4] Update variable name --- autoload/tagbar.vim | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/autoload/tagbar.vim b/autoload/tagbar.vim index 1138204..a00a8ff 100644 --- a/autoload/tagbar.vim +++ b/autoload/tagbar.vim @@ -1161,12 +1161,12 @@ function! s:ProcessFile(fname, ftype) abort " 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 linecount = getfsize(expand('%')) - if linecount > g:tagbar_file_size_limit && !exists('b:tagbar_force_update') - call tagbar#debug#log('[ProcessFile] File size too large (' . linecount . + 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 (' . linecount . + 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 From 64730d27a9e4fa0ad0901145c188699965b3c8b7 Mon Sep 17 00:00:00 2001 From: David Hegland Date: Wed, 23 Sep 2020 11:45:02 -0500 Subject: [PATCH 4/4] 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