diff --git a/python3/vimspector/variables.py b/python3/vimspector/variables.py index 1d62c04..4028722 100644 --- a/python3/vimspector/variables.py +++ b/python3/vimspector/variables.py @@ -84,6 +84,12 @@ class WatchResult( Expandable ): self.result = result +class WatchFailure( WatchResult ): + def __init__( self, reason ): + super().__init__( { 'result': reason } ) + self.changed = True + + class Variable( Expandable ): """Holds one level of an expanded value tree. Also itself expandable.""" def __init__( self, variable: dict ): @@ -296,11 +302,14 @@ class VariablesView( object ): def EvaluateWatches( self ): for watch in self._watches: - self._connection.DoRequest( partial( self._UpdateWatchExpression, - watch ), { - 'command': 'evaluate', - 'arguments': watch.expression, - } ) + self._connection.DoRequest( + partial( self._UpdateWatchExpression, watch ), + { + 'command': 'evaluate', + 'arguments': watch.expression, + }, + failure_handler = lambda reason, msg, watch=watch: + self._WatchExpressionFailed( reason, watch ) ) def _UpdateWatchExpression( self, watch: Watch, message: dict ): if watch.result is not None: @@ -321,6 +330,14 @@ class VariablesView( object ): self._DrawWatches() + def _WatchExpressionFailed( self, reason: str, watch: Watch ): + if watch.result is not None: + # We already have a result for this watch. Wut ? + return + + watch.result = WatchFailure( reason ) + self._DrawWatches() + def ExpandVariable( self ): if vim.current.buffer == self._vars.buf: view = self._vars diff --git a/tests/variables.test.vim b/tests/variables.test.vim index 155e1d9..9152875 100644 --- a/tests/variables.test.vim +++ b/tests/variables.test.vim @@ -557,3 +557,37 @@ function Test_EvaluatePromptConsole() call vimspector#test#setup#Reset() %bwipe! endfunction + +function! Test_EvaluateFailure() + call s:StartDebugging() + + " Add a wtch + call vimspector#AddWatch( 'test' ) + call WaitForAssert( {-> + \ AssertMatchist( + \ [ + \ 'Watches: ----', + \ 'Expression: test', + \ " *- Result: NameError: name 'test' is not defined", + \ ], + \ getbufline( winbufnr( g:vimspector_session_windows.watches ), + \ 1, + \ '$' ) + \ ) + \ } ) + + VimspectorEval test + call assert_equal( bufnr( 'vimspector.Console' ), + \ winbufnr( g:vimspector_session_windows.output ) ) + call WaitForAssert( {-> + \ assert_equal( + \ [ + \ "NameError: name 'test' is not defined" + \ ], + \ getbufline( bufnr( 'vimspector.Console' ), '$', '$' ) + \ ) + \ } ) + + call vimspector#test#setup#Reset() + %bwipe! +endfunction