From 163238992cc5f2656a135c35e63ca4c11325e803 Mon Sep 17 00:00:00 2001 From: Kenny Kaye Date: Fri, 4 Dec 2015 15:59:18 -0800 Subject: [PATCH] Document YcmGetErrorCount and YcmGetWarningCount functions --- README.md | 24 +++++++++++++++++++++++ doc/youcompleteme.txt | 31 ++++++++++++++++++++++++++++-- python/ycm/diagnostic_interface.py | 30 ++++++++++++----------------- 3 files changed, 65 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index cdaa37aa..4b2f6c39 100644 --- a/README.md +++ b/README.md @@ -1122,6 +1122,30 @@ provides a list of implementations to choose from. Supported in filetypes: `cs` +Functions +-------- + +### The `YcmGetErrorCount` function + +Get the number of YCM Diagnostic errors. If no errors are present, this function +returns 0. + +For example: +```viml + call YcmGetErrorCount() +``` + +### The `YcmGetWarningCount` function + +Get the number of YCM Diagnostic warnings. If no warnings are present, this +function returns 0. + +For example: +```viml + call YcmGetWarningCount() +``` + + Options ------- diff --git a/doc/youcompleteme.txt b/doc/youcompleteme.txt index 10dbce73..c7b4228d 100644 --- a/doc/youcompleteme.txt +++ b/doc/youcompleteme.txt @@ -55,7 +55,10 @@ Contents ~ 14. The |ReloadSolution| subcommand 15. The |GoToImplementation| subcommand 16. The |GoToImplementationElseDeclaration| subcommand - 8. Options |youcompleteme-options| + 8. Functions |youcompleteme-functions| + 1. The |YcmGetErrorCount| function + 2. The |YcmGetWarningCount| function + 9. Options |youcompleteme-options| 1. The |g:ycm_min_num_of_chars_for_completion| option 2. The |g:ycm_min_num_identifier_candidate_chars| option 3. The |g:ycm_auto_trigger| option @@ -101,7 +104,7 @@ Contents ~ 43. The |g:ycm_use_ultisnips_completer| option 44. The |g:ycm_goto_buffer_command| option 45. The |g:ycm_disable_for_files_larger_than_kb| option - 9. FAQ |youcompleteme-faq| + 10. FAQ |youcompleteme-faq| 1. I used to be able to 'import vim' in '.ycm_extra_conf.py', but now can't |import-vim| 2. On very rare occasions Vim crashes when I tab through the completion menu |youcompleteme-on-very-rare-occasions-vim-crashes-when-i-tab-through-completion-menu| 3. I get a linker warning regarding |libpython| on Mac when compiling YCM @@ -1346,6 +1349,30 @@ provides a list of implementations to choose from. Supported in filetypes: 'cs' +=============================================================================== + *youcompleteme-functions* +Functions ~ + +------------------------------------------------------------------------------- +The *YcmGetErrorCount* function + +Get the number of YCM Diagnostic errors. If no errors are present, this function +returns 0. + +For example: +> + call YcmGetErrorCount() +< +------------------------------------------------------------------------------- +The *YcmGetWarningCount* function + +Get the number of YCM Diagnostic warnings. If no warnings are present, this +function returns 0. + +For example: +> + call YcmGetWarningCount() +< =============================================================================== *youcompleteme-options* Options ~ diff --git a/python/ycm/diagnostic_interface.py b/python/ycm/diagnostic_interface.py index 1082a14f..317c6095 100644 --- a/python/ycm/diagnostic_interface.py +++ b/python/ycm/diagnostic_interface.py @@ -45,27 +45,11 @@ class DiagnosticInterface( object ): 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 + return len( self._FilterDiagnostics( _DiagnosticIsError ) ) 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 + return len( self._FilterDiagnostics( _DiagnosticIsWarning ) ) def UpdateWithNewDiagnostics( self, diags ): @@ -104,6 +88,16 @@ class DiagnosticInterface( object ): self._diag_message_needs_clearing = True + def _FilterDiagnostics( self, predicate ): + matched_diags = [] + line_to_diags = self._buffer_number_to_line_to_diags[ + vim.current.buffer.number ] + + for diags in line_to_diags.itervalues(): + matched_diags.extend( filter( predicate, diags ) ) + return matched_diags + + def _UpdateSquiggles( buffer_number_to_line_to_diags ): vimsupport.ClearYcmSyntaxMatches() line_to_diags = buffer_number_to_line_to_diags[ vim.current.buffer.number ]