1
0
Эх сурвалжийг харах

Expose functions to get error and warning counts

Kenny Kaye 9 жил өмнө
parent
commit
dafc36ba37

+ 10 - 0
autoload/youcompleteme.vim

@@ -870,6 +870,16 @@ function! s:ShowDiagnostics()
 endfunction
 
 
+function! g:YcmGetErrorCount()
+  return pyeval( 'ycm_state.GetErrorCount()' )
+endfunction
+
+
+function! g:YcmGetWarningCount()
+  return pyeval( 'ycm_state.GetWarningCount()' )
+endfunction
+
+
 " This is basic vim plugin boilerplate
 let &cpo = s:save_cpo
 unlet s:save_cpo

+ 29 - 0
python/ycm/diagnostic_interface.py

@@ -43,6 +43,31 @@ class DiagnosticInterface( object ):
       if self._user_options[ 'echo_current_diagnostic' ]:
         self._EchoDiagnosticForLine( line )
 
+
+  def GetErrorCount( self ):
+    errors = 0
+    line_to_diags = self._buffer_number_to_line_to_diags[
+      vim.current.buffer.number ]
+
+    for diags in line_to_diags.itervalues():
+      for diag in diags:
+        if _DiagnosticIsError( diag ):
+          errors += 1
+    return errors
+
+
+  def GetWarningCount( self ):
+    warnings = 0
+    line_to_diags = self._buffer_number_to_line_to_diags[
+      vim.current.buffer.number ]
+
+    for diags in line_to_diags.itervalues():
+      for diag in diags:
+        if _DiagnosticIsWarning( diag ):
+          warnings += 1
+    return warnings
+
+
   def UpdateWithNewDiagnostics( self, diags ):
     normalized_diags = [ _NormalizeDiagnostic( x ) for x in diags ]
     self._buffer_number_to_line_to_diags = _ConvertDiagListToDict(
@@ -209,6 +234,10 @@ def _DiagnosticIsError( diag ):
   return diag[ 'kind' ] == 'ERROR'
 
 
+def _DiagnosticIsWarning( diag ):
+  return diag[ 'kind' ] == 'WARNING'
+
+
 def _NormalizeDiagnostic( diag ):
   def ClampToOne( value ):
     return value if value > 0 else 1

+ 5 - 0
python/ycm/youcompleteme.py

@@ -451,6 +451,11 @@ class YouCompleteMe( object ):
       return None
     return completion[ "extra_data" ][ "required_namespace_import" ]
 
+  def GetErrorCount( self ):
+    return self._diag_interface.GetErrorCount()
+
+  def GetWarningCount( self ):
+    return self._diag_interface.GetWarningCount()
 
   def DiagnosticsForCurrentFileReady( self ):
     return bool( self._latest_file_parse_request and