1
0
mirror of https://github.com/gryf/tagbar.git synced 2026-02-02 06:05:50 +01:00

Merge pull request #656 from raven42/large-file-handling

Add option to not trigger update on large files
This commit is contained in:
raven42
2020-09-23 12:17:50 -05:00
committed by GitHub
4 changed files with 65 additions and 2 deletions

View File

@@ -1190,7 +1190,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.
@@ -1209,6 +1216,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)
@@ -1217,6 +1225,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
@@ -1857,7 +1866,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
@@ -3587,6 +3605,15 @@ 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
endif
endfunction
" tagbar#toggle_pause() {{{2
function! tagbar#toggle_pause() abort
let s:paused = !s:paused

View File

@@ -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

View File

@@ -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*
@@ -337,6 +343,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*
@@ -928,6 +938,23 @@ 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 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 or with the |:TagbarForceUpdate| command. If
the value is set to 0, then the file will always be processed.
Example:
>
let g:tagbar_file_size_limit = 10000
<
*g:tagbar_wrap*
g:tagbar_wrap~
Default: 0

View File

@@ -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],
@@ -182,6 +183,7 @@ command! -nargs=1 TagbarGetTypeConfig call tagbar#gettypeconfig(<f-args>)
command! -nargs=? TagbarDebug call tagbar#debug#start_debug(<f-args>)
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