New postprocess function: guards
.
The new function ensures line numbers in loclists are not beyond end of buffer. The implementation is very inefficient, because it loads all buffers in memory. `eslint` and `lessc` checkers need this function.
This commit is contained in:
parent
c2d73ffa36
commit
4aadf589be
@ -46,6 +46,25 @@ function! syntastic#postprocess#filterForeignErrors(errors) " {{{2
|
||||
return filter(copy(a:errors), 'get(v:val, "bufnr") == ' . bufnr(''))
|
||||
endfunction " }}}2
|
||||
|
||||
" make sure line numbers are not past end of buffers
|
||||
" XXX: this loads all referenced buffers in memory
|
||||
function! syntastic#postprocess#guards(errors) " {{{2
|
||||
let buffers = syntastic#util#unique(map(filter(copy(a:errors), 'v:val["valid"]'), 'str2nr(v:val["bufnr"])'))
|
||||
|
||||
let guards = {}
|
||||
for b in buffers
|
||||
let guards[b] = len(getbufline(b, 1, '$'))
|
||||
endfor
|
||||
|
||||
for e in a:errors
|
||||
if e['valid'] && e['lnum'] > guards[e['bufnr']]
|
||||
let e['lnum'] = guards[e['bufnr']]
|
||||
endif
|
||||
endfor
|
||||
|
||||
return a:errors
|
||||
endfunction " }}}2
|
||||
|
||||
" }}}1
|
||||
|
||||
let &cpo = s:save_cpo
|
||||
|
@ -19,7 +19,7 @@ if has('reltime')
|
||||
lockvar! g:syntastic_start
|
||||
endif
|
||||
|
||||
let g:syntastic_version = '3.5.0-3'
|
||||
let g:syntastic_version = '3.5.0-6'
|
||||
lockvar g:syntastic_version
|
||||
|
||||
" Sanity checks {{{1
|
||||
|
@ -35,7 +35,8 @@ function! SyntaxCheckers_javascript_eslint_GetLocList() dict
|
||||
|
||||
let loclist = SyntasticMake({
|
||||
\ 'makeprg': makeprg,
|
||||
\ 'errorformat': errorformat })
|
||||
\ 'errorformat': errorformat,
|
||||
\ 'postprocess': ['guards'] })
|
||||
|
||||
for e in loclist
|
||||
let e['col'] += 1
|
||||
|
@ -58,6 +58,7 @@ function! SyntaxCheckers_less_lessc_GetLocList() dict
|
||||
return SyntasticMake({
|
||||
\ 'makeprg': makeprg,
|
||||
\ 'errorformat': errorformat,
|
||||
\ 'postprocess': ['guards'],
|
||||
\ 'defaults': {'bufnr': bufnr(""), 'text': "Syntax error"} })
|
||||
endfunction
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user