Added support for error/warning subtyping.

This commit is contained in:
Matt Butcher 2012-01-27 13:43:48 -06:00
parent 10f4d4d3e0
commit 8df5c3bcdc
2 changed files with 37 additions and 7 deletions

View File

@ -267,6 +267,8 @@ if g:syntastic_enable_signs
"use >> to display syntax errors in the sign column
sign define SyntasticError text=>> texthl=error
sign define SyntasticWarning text=>> texthl=todo
sign define SyntasticStyleError text=S> texthl=error
sign define SyntasticStyleWarning text=S> texthl=todo
endif
"start counting sign ids at 5000, start here to hopefully avoid conflicting
@ -281,12 +283,17 @@ function! s:SignErrors()
let errors = s:FilterLocList({'bufnr': bufnr('')})
for i in errors
let sign_type = 'SyntasticError'
if i['type'] ==? 'W'
let sign_type = 'SyntasticWarning'
let sign_severity = 'Error'
let sign_subtype = ''
if has_key(i,'subtype')
let sign_subtype = i['subtype']
endif
if i['type'] ==? 'w'
let sign_severity = 'Warning'
endif
let sign_type = 'Syntastic' . sign_subtype . sign_severity
if !s:WarningMasksError(i, errors)
if !s:WarningMasksError(i, errors) && !s:SubtypeMasksType(i, errors)
exec "sign place ". s:next_sign_id ." line=". i['lnum'] ." name=". sign_type ." file=". expand("%:p")
call add(s:BufSignIds(), s:next_sign_id)
let s:next_sign_id += 1
@ -305,6 +312,21 @@ function! s:WarningMasksError(error, llist)
return len(s:FilterLocList({ 'type': "E", 'lnum': a:error['lnum'] }, a:llist)) > 0
endfunction
" Return 1 if this subtype error is masking a non-subtyped error.
" We give primacy to non-subtyped errors, assuming they are true syntax
" errors.
function! s:SubtypeMasksType(error, llist)
if !has_key(a:error, 'subtype')
return 0
endif
for item in a:llist
if !has_key(item, 'subtype') && item['lnum'] == a:error['lnum']
return 1
endif
endfor
endfunction
"remove the signs with the given ids from this buffer
function! s:RemoveSigns(ids)
for i in a:ids
@ -501,6 +523,14 @@ function! SyntasticMake(options)
redraw!
endif
" Add subtype info if present.
if has_key(a:options, 'subtype')
if !has_key(a:options, 'defaults')
let a:options['defaults'] = {}
endif
let a:options['defaults']['subtype'] = a:options['subtype']
endif
if has_key(a:options, 'defaults')
call SyntasticAddToErrors(errors, a:options['defaults'])
endif
@ -551,7 +581,7 @@ endfunction
function! SyntasticAddToErrors(errors, options)
for i in range(0, len(a:errors)-1)
for key in keys(a:options)
if empty(a:errors[i][key])
if !has_key(a:errors[i], key) || empty(a:errors[i][key])
let a:errors[i][key] = a:options[key]
endif
endfor

View File

@ -42,7 +42,7 @@ function! SyntaxCheckers_php_GetLocList()
let errorformat='%-GNo syntax errors detected in%.%#,PHP Parse error: %#syntax %trror\, %m in %f on line %l,PHP Fatal %trror: %m in %f on line %l,%-GErrors parsing %.%#,%-G\s%#,Parse error: %#syntax %trror\, %m in %f on line %l,Fatal %trror: %m in %f on line %l'
let errors = SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat })
if empty(errors) && !g:syntastic_phpcs_disable && executable("phpcs")
if !g:syntastic_phpcs_disable && executable("phpcs")
let errors = errors + s:GetPHPCSErrors()
endif
@ -54,5 +54,5 @@ endfunction
function! s:GetPHPCSErrors()
let makeprg = "phpcs " . g:syntastic_phpcs_conf . " --report=csv ".shellescape(expand('%'))
let errorformat = '%-GFile\,Line\,Column\,Type\,Message\,Source\,Severity,"%f"\,%l\,%c\,%t%*[a-zA-Z]\,"%m"\,%*[a-zA-Z0-9_.-]\,%*[0-9]'
return SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat })
return SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat, 'subtype': 'Style' })
endfunction