Refactor _FilterDiagnostics to rely on _ApplyDiagnosticFilter
Also builds the predicates using compilers from diagnostic_filter
This commit is contained in:
parent
e2852a8b2b
commit
13fda74cc1
@ -32,11 +32,9 @@ class DiagnosticFilter( object ):
|
|||||||
def __init__( self, config_or_filters ):
|
def __init__( self, config_or_filters ):
|
||||||
if isinstance( config_or_filters, list ):
|
if isinstance( config_or_filters, list ):
|
||||||
self._filters = config_or_filters
|
self._filters = config_or_filters
|
||||||
print( 'NewFilter', config_or_filters)
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
self._filters = _CompileFilters( config_or_filters )
|
self._filters = _CompileFilters( config_or_filters )
|
||||||
print( 'CompileFilters', config_or_filters)
|
|
||||||
|
|
||||||
|
|
||||||
def IsAllowed( self, diagnostic ):
|
def IsAllowed( self, diagnostic ):
|
||||||
@ -91,7 +89,7 @@ class _MasterDiagnosticFilter( object ):
|
|||||||
if cached is not None:
|
if cached is not None:
|
||||||
return cached
|
return cached
|
||||||
|
|
||||||
# build a new DiagnosticFilter mergin all filters
|
# build a new DiagnosticFilter merging all filters
|
||||||
# for the provided filetypes
|
# for the provided filetypes
|
||||||
spec = []
|
spec = []
|
||||||
for filetype in filetypes:
|
for filetype in filetypes:
|
||||||
@ -113,7 +111,7 @@ def _ListOf( config_entry ):
|
|||||||
return [ config_entry ]
|
return [ config_entry ]
|
||||||
|
|
||||||
|
|
||||||
def _CompileRegex( raw_regex ):
|
def CompileRegex( raw_regex ):
|
||||||
pattern = re.compile( raw_regex, re.IGNORECASE )
|
pattern = re.compile( raw_regex, re.IGNORECASE )
|
||||||
|
|
||||||
def FilterRegex( diagnostic ):
|
def FilterRegex( diagnostic ):
|
||||||
@ -122,7 +120,7 @@ def _CompileRegex( raw_regex ):
|
|||||||
return FilterRegex
|
return FilterRegex
|
||||||
|
|
||||||
|
|
||||||
def _CompileLevel( level ):
|
def CompileLevel( level ):
|
||||||
# valid kinds are WARNING and ERROR;
|
# valid kinds are WARNING and ERROR;
|
||||||
# expected input levels are `warning` and `error`
|
# expected input levels are `warning` and `error`
|
||||||
# NOTE: we don't validate the input...
|
# NOTE: we don't validate the input...
|
||||||
@ -134,8 +132,8 @@ def _CompileLevel( level ):
|
|||||||
return FilterLevel
|
return FilterLevel
|
||||||
|
|
||||||
|
|
||||||
FILTER_COMPILERS = { 'regex' : _CompileRegex,
|
FILTER_COMPILERS = { 'regex' : CompileRegex,
|
||||||
'level' : _CompileLevel }
|
'level' : CompileLevel }
|
||||||
|
|
||||||
|
|
||||||
def _CompileFilters( config ):
|
def _CompileFilters( config ):
|
||||||
|
@ -26,7 +26,7 @@ from builtins import * # noqa
|
|||||||
from future.utils import itervalues, iteritems
|
from future.utils import itervalues, iteritems
|
||||||
from collections import defaultdict, namedtuple
|
from collections import defaultdict, namedtuple
|
||||||
from ycm import vimsupport
|
from ycm import vimsupport
|
||||||
from ycm.diagnostic_filter import DiagnosticFilter
|
from ycm.diagnostic_filter import DiagnosticFilter, CompileLevel
|
||||||
import vim
|
import vim
|
||||||
|
|
||||||
|
|
||||||
@ -86,10 +86,17 @@ class DiagnosticInterface( object ):
|
|||||||
self.PopulateLocationList( normalized_diags )
|
self.PopulateLocationList( normalized_diags )
|
||||||
|
|
||||||
|
|
||||||
def _ApplyDiagnosticFilter( self, diags ):
|
def _ApplyDiagnosticFilter( self, diags, extra_predicate = None ):
|
||||||
filetypes = vimsupport.CurrentFiletypes()
|
filetypes = vimsupport.CurrentFiletypes()
|
||||||
diag_filter = self._diag_filter.SubsetForTypes( filetypes )
|
diag_filter = self._diag_filter.SubsetForTypes( filetypes )
|
||||||
return filter( diag_filter.IsAllowed, diags )
|
predicate = diag_filter.IsAllowed
|
||||||
|
if extra_predicate is not None:
|
||||||
|
def Filter( diag ):
|
||||||
|
return extra_predicate( diag ) and diag_filter.IsAllowed( diag )
|
||||||
|
|
||||||
|
predicate = Filter
|
||||||
|
|
||||||
|
return filter( predicate, diags )
|
||||||
|
|
||||||
|
|
||||||
def _EchoDiagnosticForLine( self, line_num ):
|
def _EchoDiagnosticForLine( self, line_num ):
|
||||||
@ -116,7 +123,8 @@ class DiagnosticInterface( object ):
|
|||||||
vim.current.buffer.number ]
|
vim.current.buffer.number ]
|
||||||
|
|
||||||
for diags in itervalues( line_to_diags ):
|
for diags in itervalues( line_to_diags ):
|
||||||
matched_diags.extend( list( filter( predicate, diags ) ) )
|
matched_diags.extend( list(
|
||||||
|
self._ApplyDiagnosticFilter( diags, predicate ) ) )
|
||||||
return matched_diags
|
return matched_diags
|
||||||
|
|
||||||
|
|
||||||
@ -247,12 +255,8 @@ def _ConvertDiagListToDict( diag_list ):
|
|||||||
return buffer_to_line_to_diags
|
return buffer_to_line_to_diags
|
||||||
|
|
||||||
|
|
||||||
def _DiagnosticIsError( diag ):
|
_DiagnosticIsError = CompileLevel( 'error' )
|
||||||
return diag[ 'kind' ] == 'ERROR'
|
_DiagnosticIsWarning = CompileLevel( 'warning' )
|
||||||
|
|
||||||
|
|
||||||
def _DiagnosticIsWarning( diag ):
|
|
||||||
return diag[ 'kind' ] == 'WARNING'
|
|
||||||
|
|
||||||
|
|
||||||
def _NormalizeDiagnostic( diag ):
|
def _NormalizeDiagnostic( diag ):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user