Support filtering on level/kind
This commit is contained in:
parent
f7fbbd16f7
commit
73343bd98f
@ -86,10 +86,24 @@ def _Not( fn ):
|
|||||||
def _CompileRegex( raw_regex ):
|
def _CompileRegex( raw_regex ):
|
||||||
pattern = re.compile( raw_regex, re.IGNORECASE )
|
pattern = re.compile( raw_regex, re.IGNORECASE )
|
||||||
|
|
||||||
def Filter( diagnostic ):
|
def FilterRegex( diagnostic ):
|
||||||
return pattern.search( diagnostic[ 'text' ] ) is not None
|
return pattern.search( diagnostic[ 'text' ] ) is not None
|
||||||
|
|
||||||
return Filter
|
return FilterRegex
|
||||||
|
|
||||||
|
|
||||||
FILTER_COMPILERS = { 'regex' : _CompileRegex }
|
def _CompileLevel( level ):
|
||||||
|
# valid kinds are WARNING and ERROR;
|
||||||
|
# expected input levels are `warnings` and `errors`
|
||||||
|
# NB: we don't validate the input...
|
||||||
|
expected_kind = level.upper()[:-1]
|
||||||
|
|
||||||
|
def FilterLevel( diagnostic ):
|
||||||
|
print( diagnostic, 'matches?', expected_kind )
|
||||||
|
return diagnostic[ 'kind' ] == expected_kind
|
||||||
|
|
||||||
|
return FilterLevel
|
||||||
|
|
||||||
|
|
||||||
|
FILTER_COMPILERS = { 'regex' : _CompileRegex,
|
||||||
|
'level' : _CompileLevel }
|
||||||
|
@ -31,8 +31,11 @@ from hamcrest import assert_that, equal_to
|
|||||||
from ycm.diagnostic_filter import DiagnosticFilter
|
from ycm.diagnostic_filter import DiagnosticFilter
|
||||||
|
|
||||||
|
|
||||||
def _assert_accept_equals( filter, text, expected ):
|
def _assert_accept_equals( filter, text_or_obj, expected ):
|
||||||
assert_that( filter.Accept( { 'text': text } ), equal_to( expected ) )
|
if type( text_or_obj ) is not type( {} ):
|
||||||
|
text_or_obj = { 'text': text_or_obj }
|
||||||
|
|
||||||
|
assert_that( filter.Accept( text_or_obj ), equal_to( expected ) )
|
||||||
|
|
||||||
def _assert_accepts( filter, text ):
|
def _assert_accepts( filter, text ):
|
||||||
_assert_accept_equals( filter, text, True )
|
_assert_accept_equals( filter, text, True )
|
||||||
@ -95,9 +98,30 @@ class ListOrSingle_test():
|
|||||||
|
|
||||||
|
|
||||||
def Invert_test():
|
def Invert_test():
|
||||||
opts = { 'quiet_messages' : { '!regex': [ 'taco' ] } }
|
opts = { 'quiet_messages' : { '!regex': 'taco' } }
|
||||||
f = DiagnosticFilter.from_filetype( opts, [ 'java' ] )
|
f = DiagnosticFilter.from_filetype( opts, [ 'java' ] )
|
||||||
|
|
||||||
_assert_accepts( f, 'This is a Taco' )
|
_assert_accepts( f, 'This is a Taco' )
|
||||||
_assert_rejects( f, 'This is a Burrito' )
|
_assert_rejects( f, 'This is a Burrito' )
|
||||||
|
|
||||||
|
|
||||||
|
class Level_test():
|
||||||
|
|
||||||
|
def Level_warnings_test( self ):
|
||||||
|
opts = { 'quiet_messages' : { 'level': 'warnings' } }
|
||||||
|
f = DiagnosticFilter.from_filetype( opts, [ 'java' ] )
|
||||||
|
|
||||||
|
_assert_rejects( f, { 'text': 'This is an unimportant taco',
|
||||||
|
'kind': 'WARNING' } )
|
||||||
|
_assert_accepts( f, { 'text': 'This taco will be shown',
|
||||||
|
'kind': 'ERROR' } )
|
||||||
|
|
||||||
|
|
||||||
|
def Level_errors_test( self ):
|
||||||
|
opts = { 'quiet_messages' : { 'level': 'errors' } }
|
||||||
|
f = DiagnosticFilter.from_filetype( opts, [ 'java' ] )
|
||||||
|
|
||||||
|
_assert_accepts( f, { 'text': 'This is an IMPORTANT taco',
|
||||||
|
'kind': 'WARNING' } )
|
||||||
|
_assert_rejects( f, { 'text': 'This taco will NOT be shown',
|
||||||
|
'kind': 'ERROR' } )
|
||||||
|
Loading…
Reference in New Issue
Block a user