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