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:
parent
7f0412e91d
commit
7319cb6a9e
39
autoload/syntastic/postprocess.vim
Normal file
39
autoload/syntastic/postprocess.vim
Normal 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:
|
@ -117,18 +117,6 @@ function! syntastic#util#bufIsActive(buffer)
|
|||||||
return 0
|
return 0
|
||||||
endfunction
|
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
|
" Returns unique elements in a list
|
||||||
function! syntastic#util#unique(list)
|
function! syntastic#util#unique(list)
|
||||||
let seen = {}
|
let seen = {}
|
||||||
|
@ -287,6 +287,7 @@ endfunction
|
|||||||
"a:options may also contain:
|
"a:options may also contain:
|
||||||
" 'defaults' - a dict containing default values for the returned errors
|
" 'defaults' - a dict containing default values for the returned errors
|
||||||
" 'subtype' - all errors will be assigned the given subtype
|
" 'subtype' - all errors will be assigned the given subtype
|
||||||
|
" 'postprocess' - a list of functions to be applied to the error list
|
||||||
function! SyntasticMake(options)
|
function! SyntasticMake(options)
|
||||||
call syntastic#util#debug('SyntasticMake: called with options: '. string(a: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']})
|
call SyntasticAddToErrors(errors, {'subtype': a:options['subtype']})
|
||||||
endif
|
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
|
return errors
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
@ -43,12 +43,17 @@ function! SyntaxCheckers_css_prettycss_GetLocList()
|
|||||||
\ '%WWarning: %m\, line %l\, char %c),' .
|
\ '%WWarning: %m\, line %l\, char %c),' .
|
||||||
\ '%-G%.%#'
|
\ '%-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))
|
for n in range(len(loclist))
|
||||||
let loclist[n]["text"] .= ')'
|
let loclist[n]["text"] .= ')'
|
||||||
endfor
|
endfor
|
||||||
|
|
||||||
return sort(loclist, 'syntastic#util#compareErrorItems')
|
return loclist
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
call g:SyntasticRegistry.CreateAndRegisterChecker({
|
call g:SyntasticRegistry.CreateAndRegisterChecker({
|
||||||
|
@ -21,19 +21,22 @@ endfunction
|
|||||||
|
|
||||||
function! SyntaxCheckers_haskell_hdevtools_GetLocList()
|
function! SyntaxCheckers_haskell_hdevtools_GetLocList()
|
||||||
let makeprg = syntastic#makeprg#build({
|
let makeprg = syntastic#makeprg#build({
|
||||||
\ 'exe': 'hdevtools check',
|
\ 'exe': 'hdevtools check',
|
||||||
\ 'args': get(g:, 'hdevtools_options', ''),
|
\ 'args': get(g:, 'hdevtools_options', ''),
|
||||||
\ 'subchecker': 'hdevtools' })
|
\ 'subchecker': 'hdevtools' })
|
||||||
|
|
||||||
let errorformat= '\%-Z\ %#,'.
|
let errorformat= '\%-Z\ %#,'.
|
||||||
\ '%W%f:%l:%c:\ Warning:\ %m,'.
|
\ '%W%f:%l:%c:\ Warning:\ %m,'.
|
||||||
\ '%E%f:%l:%c:\ %m,'.
|
\ '%E%f:%l:%c:\ %m,'.
|
||||||
\ '%E%>%f:%l:%c:,'.
|
\ '%E%>%f:%l:%c:,'.
|
||||||
\ '%+C\ \ %#%m,'.
|
\ '%+C\ \ %#%m,'.
|
||||||
\ '%W%>%f:%l:%c:,'.
|
\ '%W%>%f:%l:%c:,'.
|
||||||
\ '%+C\ \ %#%tarning:\ %m,'
|
\ '%+C\ \ %#%tarning:\ %m,'
|
||||||
|
|
||||||
return SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat })
|
return SyntasticMake({
|
||||||
|
\ 'makeprg': makeprg,
|
||||||
|
\ 'errorformat': errorformat,
|
||||||
|
\ 'postprocess': ['compressWhitespace'] })
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
call g:SyntasticRegistry.CreateAndRegisterChecker({
|
call g:SyntasticRegistry.CreateAndRegisterChecker({
|
||||||
|
@ -15,22 +15,25 @@ endfunction
|
|||||||
|
|
||||||
function! SyntaxCheckers_python_pylint_GetLocList()
|
function! SyntaxCheckers_python_pylint_GetLocList()
|
||||||
let makeprg = syntastic#makeprg#build({
|
let makeprg = syntastic#makeprg#build({
|
||||||
\ 'exe': 'pylint',
|
\ 'exe': 'pylint',
|
||||||
\ 'args': ' -f parseable -r n -i y',
|
\ 'args': ' -f parseable -r n -i y',
|
||||||
\ 'subchecker': 'pylint' })
|
\ 'subchecker': 'pylint' })
|
||||||
let errorformat =
|
let errorformat =
|
||||||
\ '%A%f:%l:%m,' .
|
\ '%A%f:%l:%m,' .
|
||||||
\ '%A%f:(%l):%m,' .
|
\ '%A%f:(%l):%m,' .
|
||||||
\ '%-Z%p^%.%#,' .
|
\ '%-Z%p^%.%#,' .
|
||||||
\ '%-G%.%#'
|
\ '%-G%.%#'
|
||||||
|
|
||||||
let loclist=SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat })
|
let loclist=SyntasticMake({
|
||||||
|
\ 'makeprg': makeprg,
|
||||||
|
\ 'errorformat': errorformat,
|
||||||
|
\ 'postprocess': ['sort'] })
|
||||||
|
|
||||||
for n in range(len(loclist))
|
for n in range(len(loclist))
|
||||||
let loclist[n]['type'] = match(['R', 'C', 'W'], loclist[n]['text'][2]) >= 0 ? 'W' : 'E'
|
let loclist[n]['type'] = match(['R', 'C', 'W'], loclist[n]['text'][2]) >= 0 ? 'W' : 'E'
|
||||||
endfor
|
endfor
|
||||||
|
|
||||||
return sort(loclist, 'syntastic#util#compareErrorItems')
|
return loclist
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
call g:SyntasticRegistry.CreateAndRegisterChecker({
|
call g:SyntasticRegistry.CreateAndRegisterChecker({
|
||||||
|
@ -38,14 +38,22 @@ endfunction
|
|||||||
|
|
||||||
function! SyntaxCheckers_tex_chktex_GetLocList()
|
function! SyntaxCheckers_tex_chktex_GetLocList()
|
||||||
let makeprg = syntastic#makeprg#build({
|
let makeprg = syntastic#makeprg#build({
|
||||||
\ 'exe': 'chktex',
|
\ 'exe': 'chktex',
|
||||||
\ 'post_args': '-q -v1',
|
\ 'post_args': '-q -v1',
|
||||||
\ 'subchecker': 'chktex' })
|
\ '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,' : '') .
|
let errorformat =
|
||||||
\ '%+Z%p^,%-G%.%#'
|
\ '%EError\ %\\d%\\+\ in\ %f\ line\ %l:\ %m,' .
|
||||||
let loclist = SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat, 'subtype': 'Style' })
|
\ '%WWarning\ %\\d%\\+\ in\ %f\ line\ %l:\ %m,' .
|
||||||
return sort(loclist, 'syntastic#util#compareErrorItems')
|
\ (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
|
endfunction
|
||||||
|
|
||||||
call g:SyntasticRegistry.CreateAndRegisterChecker({
|
call g:SyntasticRegistry.CreateAndRegisterChecker({
|
||||||
|
Loading…
x
Reference in New Issue
Block a user