diff --git a/python/ycm/diagnostic_interface.py b/python/ycm/diagnostic_interface.py index e10cfd36..6c2b2a60 100644 --- a/python/ycm/diagnostic_interface.py +++ b/python/ycm/diagnostic_interface.py @@ -38,17 +38,15 @@ class DiagnosticInterface( object ): self._line_to_diags = defaultdict( list ) self._placed_signs = [] self._next_sign_id = 1 - self._previous_line_number = -1 + self._previous_diag_line_number = -1 self._diag_message_needs_clearing = False def OnCursorMoved( self ): - line, _ = vimsupport.CurrentLineAndColumn() - line += 1 # Convert to 1-based - if line != self._previous_line_number: - self._previous_line_number = line - - if self._user_options[ 'echo_current_diagnostic' ]: + if self._user_options[ 'echo_current_diagnostic' ]: + line, _ = vimsupport.CurrentLineAndColumn() + line += 1 # Convert to 1-based + if line != self._previous_diag_line_number: self._EchoDiagnosticForLine( line ) @@ -72,6 +70,9 @@ class DiagnosticInterface( object ): self._ApplyDiagnosticFilter( diags ) ] self._ConvertDiagListToDict() + if self._user_options[ 'echo_current_diagnostic' ]: + self._EchoDiagnostic() + if self._user_options[ 'enable_diagnostic_signs' ]: self._UpdateSigns() @@ -88,7 +89,15 @@ class DiagnosticInterface( object ): return filter( diag_filter.IsAllowed, diags ) + def _EchoDiagnostic( self ): + line, _ = vimsupport.CurrentLineAndColumn() + line += 1 # Convert to 1-based + self._EchoDiagnosticForLine( line ) + + def _EchoDiagnosticForLine( self, line_num ): + self._previous_diag_line_number = line_num + diags = self._line_to_diags[ line_num ] if not diags: if self._diag_message_needs_clearing: @@ -163,6 +172,9 @@ class DiagnosticInterface( object ): new_signs = [] obsolete_signs = list( self._placed_signs ) for line, diags in iteritems( self._line_to_diags ): + if not diags: + continue + # We always go for the first diagnostic on line, # because it is sorted giving priority to the Errors. diag = diags[ 0 ] diff --git a/python/ycm/tests/__init__.py b/python/ycm/tests/__init__.py index bc5090bb..7bfe8842 100644 --- a/python/ycm/tests/__init__.py +++ b/python/ycm/tests/__init__.py @@ -44,6 +44,7 @@ DEFAULT_CLIENT_OPTIONS = { 'keep_logfiles': 0, 'extra_conf_vim_data': [], 'show_diagnostics_ui': 1, + 'echo_current_diagnostic': 1, 'enable_diagnostic_signs': 1, 'enable_diagnostic_highlighting': 0, 'always_populate_location_list': 0, diff --git a/python/ycm/tests/youcompleteme_test.py b/python/ycm/tests/youcompleteme_test.py index 566d71ba..4c5ce539 100644 --- a/python/ycm/tests/youcompleteme_test.py +++ b/python/ycm/tests/youcompleteme_test.py @@ -551,6 +551,11 @@ def YouCompleteMe_UpdateDiagnosticInterface_PrioritizeErrorsOverWarnings_test( ycm.OnFileReadyToParse() ycm.HandleFileParseRequest( block = True ) + # The error on the current line is echoed, not the warning. + post_vim_message.assert_called_once_with( + "expected ';' after expression (FixIt)", + truncate = True, warning = False ) + # Error match is added after warning matches. assert_that( test_utils.VIM_MATCHES, @@ -566,13 +571,25 @@ def YouCompleteMe_UpdateDiagnosticInterface_PrioritizeErrorsOverWarnings_test( call( 'sign place 1 name=YcmError line=3 buffer=5' ), ] ) - # When moving the cursor on the diagnostics, the error is displayed to the - # user, not the warning. + # The error is not echoed again when moving the cursor along the line. + with MockVimBuffers( [ current_buffer ], current_buffer, ( 3, 2 ) ): + post_vim_message.reset_mock() ycm.OnCursorMoved() - post_vim_message.assert_has_exact_calls( [ - call( "expected ';' after expression (FixIt)", - truncate = True, warning = False ) - ] ) + post_vim_message.assert_not_called() + + # The error is cleared when moving the cursor to another line. + with MockVimBuffers( [ current_buffer ], current_buffer, ( 2, 2 ) ): + post_vim_message.reset_mock() + ycm.OnCursorMoved() + post_vim_message.assert_called_once_with( "", warning = False ) + + # The error is echoed when moving the cursor back. + with MockVimBuffers( [ current_buffer ], current_buffer, ( 3, 2 ) ): + post_vim_message.reset_mock() + ycm.OnCursorMoved() + post_vim_message.assert_called_once_with( + "expected ';' after expression (FixIt)", + truncate = True, warning = False ) vim_command.reset_mock() with patch( 'ycm.client.event_notification.EventNotification.Response',