diff --git a/autoload/youcompleteme.vim b/autoload/youcompleteme.vim index 0714cdae..586e9584 100644 --- a/autoload/youcompleteme.vim +++ b/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 diff --git a/python/ycm/diagnostic_interface.py b/python/ycm/diagnostic_interface.py index 52afae28..1082a14f 100644 --- a/python/ycm/diagnostic_interface.py +++ b/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 diff --git a/python/ycm/youcompleteme.py b/python/ycm/youcompleteme.py index 77b81a0a..78544a8c 100644 --- a/python/ycm/youcompleteme.py +++ b/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