From 0ed10960402352990ab084449898919a3572a4a4 Mon Sep 17 00:00:00 2001 From: Val Markovic Date: Tue, 1 Mar 2016 18:53:02 -0800 Subject: [PATCH] Support multiline exception message Also stopped adding the "ycmd exception:" prefix to error messages because it lies; some exceptions hitting this may not come from ycmd. --- python/ycm/client/base_request.py | 3 +-- python/ycm/tests/event_notification_test.py | 17 ++++++++++++----- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/python/ycm/client/base_request.py b/python/ycm/client/base_request.py index 7afc4052..c5742771 100644 --- a/python/ycm/client/base_request.py +++ b/python/ycm/client/base_request.py @@ -42,7 +42,6 @@ _EXECUTOR = UnsafeThreadPoolExecutor( max_workers = 30 ) _DEFAULT_TIMEOUT_SEC = 30 _HMAC_HEADER = 'x-ycm-hmac' -YCMD_ERROR_PREFIX = 'ycmd exception: ' class BaseRequest( object ): def __init__( self ): @@ -191,7 +190,7 @@ def HandleServerException( exception ): # up often and isn't something that's actionable by the user. if 'already being parsed' in serialized_exception: return - vimsupport.PostVimMessage( YCMD_ERROR_PREFIX + serialized_exception ) + vimsupport.PostMultiLineNotice( serialized_exception ) def _ToUtf8Json( data ): diff --git a/python/ycm/tests/event_notification_test.py b/python/ycm/tests/event_notification_test.py index 741f7124..52ca0bac 100644 --- a/python/ycm/tests/event_notification_test.py +++ b/python/ycm/tests/event_notification_test.py @@ -30,7 +30,6 @@ import contextlib import os from ycm.youcompleteme import YouCompleteMe -from ycm.client.base_request import YCMD_ERROR_PREFIX from ycmd import user_options_store from ycmd.responses import ( BuildDiagnosticData, Diagnostic, Location, Range, UnknownExtraConf, ServerError ) @@ -60,6 +59,14 @@ def PostVimMessage_Call( message ): '\' | echohl None' ) +def PostMultiLineNotice_Call( message ): + """Return a mock.call object for a call to vimsupport.PostMultiLineNotice with + the supplied message""" + return call( 'echohl WarningMsg | echo \'' + + message + + '\' | echohl None' ) + + def PresentDialog_Confirm_Call( message ): """Return a mock.call object for a call to vimsupport.PresentDialog, as called why vimsupport.Confirm with the supplied confirmation message""" @@ -193,13 +200,13 @@ class EventNotification_test( object ): # The first call raises a warning vim_command.assert_has_exact_calls( [ - PostVimMessage_Call( YCMD_ERROR_PREFIX + ERROR_TEXT ), + PostMultiLineNotice_Call( ERROR_TEXT ), ] ) # Subsequent calls don't re-raise the warning self.server_state.HandleFileParseRequest() vim_command.assert_has_exact_calls( [ - PostVimMessage_Call( YCMD_ERROR_PREFIX + ERROR_TEXT ), + PostMultiLineNotice_Call( ERROR_TEXT ), ] ) # But it does if a subsequent event raises again @@ -207,8 +214,8 @@ class EventNotification_test( object ): assert self.server_state.FileParseRequestReady() self.server_state.HandleFileParseRequest() vim_command.assert_has_exact_calls( [ - PostVimMessage_Call( YCMD_ERROR_PREFIX + ERROR_TEXT ), - PostVimMessage_Call( YCMD_ERROR_PREFIX + ERROR_TEXT ), + PostMultiLineNotice_Call( ERROR_TEXT ), + PostMultiLineNotice_Call( ERROR_TEXT ), ] )