Postprocessing functions.

This patch adds an option 'postprocess' to SyntasticMake().  The value
of this option is a list of names.  Each name is translated to a
function syntastic#postprocess#name().  These functions are applied in
order to the list of errors just before SyntasticMake() returns.  They
take a single parameter, the list of errors, and are supposed to
returned the processed list.
This commit is contained in:
LCD 47 2013-05-10 14:11:07 +03:00
parent 7f0412e91d
commit 7319cb6a9e
7 changed files with 94 additions and 41 deletions

View File

@ -0,0 +1,39 @@
if exists("g:loaded_syntastic_postprocess_autoload")
finish
endif
let g:loaded_syntastic_postprocess_autoload = 1
let s:save_cpo = &cpo
set cpo&vim
function! s:compareErrorItems(a, b)
if a:a['bufnr'] != a:b['bufnr']
return a:a['bufnr'] - a:b['bufnr']
elseif a:a['lnum'] != a:b['lnum']
return a:a['lnum'] - a:b['lnum']
elseif a:a['type'] !=? a:b['type']
" errors take precedence over warnings
return a:a['type'] ==? 'e' ? -1 : 1
else
return a:a['col'] - a:b['col']
endif
endfunction
" natural sort
function! syntastic#postprocess#sort(errors)
return sort(a:errors, 's:compareErrorItems')
endfunction
function syntastic#postprocess#compressWhitespace(errors)
let llist = []
for e in a:errors
call add(llist, substitute(e['text'], '\s\{2,}', ' ', 'g'))
endfor
return llist
endfunction
let &cpo = s:save_cpo
unlet s:save_cpo
" vim: set et sts=4 sw=4:

View File

@ -117,18 +117,6 @@ function! syntastic#util#bufIsActive(buffer)
return 0
endfunction
" Used to sort error lists
function! syntastic#util#compareErrorItems(a, b)
if a:a['lnum'] != a:b['lnum']
return a:a['lnum'] - a:b['lnum']
elseif a:a['type'] !=? a:b['type']
" errors take precedence over warnings
return a:a['type'] ==? 'e' ? -1 : 1
else
return a:a['col'] - a:b['col']
endif
endfunction
" Returns unique elements in a list
function! syntastic#util#unique(list)
let seen = {}

View File

@ -287,6 +287,7 @@ endfunction
"a:options may also contain:
" 'defaults' - a dict containing default values for the returned errors
" 'subtype' - all errors will be assigned the given subtype
" 'postprocess' - a list of functions to be applied to the error list
function! SyntasticMake(options)
call syntastic#util#debug('SyntasticMake: called with options: '. string(a:options))
@ -333,6 +334,12 @@ function! SyntasticMake(options)
call SyntasticAddToErrors(errors, {'subtype': a:options['subtype']})
endif
if has_key(a:options, 'postprocess') && !empty(a:options['postprocess'])
for rule in a:options['postprocess']
let errors = call('syntastic#postprocess#' . rule, [errors])
endfor
endif
return errors
endfunction

View File

@ -43,12 +43,17 @@ function! SyntaxCheckers_css_prettycss_GetLocList()
\ '%WWarning: %m\, line %l\, char %c),' .
\ '%-G%.%#'
let loclist = SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat, 'defaults': {'bufnr': bufnr("")} })
let loclist = SyntasticMake({
\ 'makeprg': makeprg,
\ 'errorformat': errorformat,
\ 'defaults': {'bufnr': bufnr("")},
\ 'postprocess': ['sort'] })
for n in range(len(loclist))
let loclist[n]["text"] .= ')'
endfor
return sort(loclist, 'syntastic#util#compareErrorItems')
return loclist
endfunction
call g:SyntasticRegistry.CreateAndRegisterChecker({

View File

@ -21,19 +21,22 @@ endfunction
function! SyntaxCheckers_haskell_hdevtools_GetLocList()
let makeprg = syntastic#makeprg#build({
\ 'exe': 'hdevtools check',
\ 'args': get(g:, 'hdevtools_options', ''),
\ 'subchecker': 'hdevtools' })
\ 'exe': 'hdevtools check',
\ 'args': get(g:, 'hdevtools_options', ''),
\ 'subchecker': 'hdevtools' })
let errorformat= '\%-Z\ %#,'.
\ '%W%f:%l:%c:\ Warning:\ %m,'.
\ '%E%f:%l:%c:\ %m,'.
\ '%E%>%f:%l:%c:,'.
\ '%+C\ \ %#%m,'.
\ '%W%>%f:%l:%c:,'.
\ '%+C\ \ %#%tarning:\ %m,'
\ '%W%f:%l:%c:\ Warning:\ %m,'.
\ '%E%f:%l:%c:\ %m,'.
\ '%E%>%f:%l:%c:,'.
\ '%+C\ \ %#%m,'.
\ '%W%>%f:%l:%c:,'.
\ '%+C\ \ %#%tarning:\ %m,'
return SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat })
return SyntasticMake({
\ 'makeprg': makeprg,
\ 'errorformat': errorformat,
\ 'postprocess': ['compressWhitespace'] })
endfunction
call g:SyntasticRegistry.CreateAndRegisterChecker({

View File

@ -15,22 +15,25 @@ endfunction
function! SyntaxCheckers_python_pylint_GetLocList()
let makeprg = syntastic#makeprg#build({
\ 'exe': 'pylint',
\ 'args': ' -f parseable -r n -i y',
\ 'subchecker': 'pylint' })
\ 'exe': 'pylint',
\ 'args': ' -f parseable -r n -i y',
\ 'subchecker': 'pylint' })
let errorformat =
\ '%A%f:%l:%m,' .
\ '%A%f:(%l):%m,' .
\ '%-Z%p^%.%#,' .
\ '%-G%.%#'
\ '%A%f:%l:%m,' .
\ '%A%f:(%l):%m,' .
\ '%-Z%p^%.%#,' .
\ '%-G%.%#'
let loclist=SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat })
let loclist=SyntasticMake({
\ 'makeprg': makeprg,
\ 'errorformat': errorformat,
\ 'postprocess': ['sort'] })
for n in range(len(loclist))
let loclist[n]['type'] = match(['R', 'C', 'W'], loclist[n]['text'][2]) >= 0 ? 'W' : 'E'
endfor
return sort(loclist, 'syntastic#util#compareErrorItems')
return loclist
endfunction
call g:SyntasticRegistry.CreateAndRegisterChecker({

View File

@ -38,14 +38,22 @@ endfunction
function! SyntaxCheckers_tex_chktex_GetLocList()
let makeprg = syntastic#makeprg#build({
\ 'exe': 'chktex',
\ 'post_args': '-q -v1',
\ 'subchecker': 'chktex' })
let errorformat = '%EError\ %\\d%\\+\ in\ %f\ line\ %l:\ %m,%WWarning\ %\\d%\\+\ in\ %f\ line\ %l:\ %m,' .
\ (g:syntastic_tex_chktex_showmsgs ? '%WMessage\ %\\d%\\+\ in\ %f\ line %l:\ %m,' : '') .
\ '%+Z%p^,%-G%.%#'
let loclist = SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat, 'subtype': 'Style' })
return sort(loclist, 'syntastic#util#compareErrorItems')
\ 'exe': 'chktex',
\ 'post_args': '-q -v1',
\ 'subchecker': 'chktex' })
let errorformat =
\ '%EError\ %\\d%\\+\ in\ %f\ line\ %l:\ %m,' .
\ '%WWarning\ %\\d%\\+\ in\ %f\ line\ %l:\ %m,' .
\ (g:syntastic_tex_chktex_showmsgs ? '%WMessage\ %\\d%\\+\ in\ %f\ line %l:\ %m,' : '') .
\ '%+Z%p^,' .
\ '%-G%.%#'
return SyntasticMake({
\ 'makeprg': makeprg,
\ 'errorformat': errorformat,
\ 'subtype': 'Style',
\ 'postprocess': ['sort'] })
endfunction
call g:SyntasticRegistry.CreateAndRegisterChecker({