From 63f8543d8faff8ae7fd9e52f67e5716dbd2282e8 Mon Sep 17 00:00:00 2001 From: Ben Jackson Date: Sun, 6 Oct 2019 21:56:36 +0100 Subject: [PATCH] The chrome debugger doesn't return 'line' in some stack frames. Fix a bug for expensive scopes --- python3/vimspector/code.py | 10 +++++++++- python3/vimspector/stack_trace.py | 26 ++++++++++++++++++-------- python3/vimspector/variables.py | 2 ++ support/test/chrome/www/js/test.js | 1 + 4 files changed, 30 insertions(+), 9 deletions(-) diff --git a/python3/vimspector/code.py b/python3/vimspector/code.py index 2e60a0e..f28a1b5 100644 --- a/python3/vimspector/code.py +++ b/python3/vimspector/code.py @@ -73,7 +73,15 @@ class CodeView( object ): return False # SIC: column is 0-based, line is 1-based in vim. Why? Nobody knows. - self._window.cursor = ( frame[ 'line' ], frame[ 'column' ] - 1 ) + try: + self._window.cursor = ( frame[ 'line' ], frame[ 'column' ] - 1 ) + except vim.error: + self._logger.exception( "Unable to jump to %s:%s in %s, maybe the file " + "doesn't exist", + frame[ 'line' ], + frame[ 'column' ], + frame[ 'source' ][ 'path' ] ) + return False self._signs[ 'vimspectorPC' ] = self._next_sign_id self._next_sign_id += 1 diff --git a/python3/vimspector/stack_trace.py b/python3/vimspector/stack_trace.py index 9849131..d68e6e9 100644 --- a/python3/vimspector/stack_trace.py +++ b/python3/vimspector/stack_trace.py @@ -162,8 +162,9 @@ class StackTraceView( object ): self._LoadStackTrace( thread, False ) def _JumpToFrame( self, frame ): - self._currentFrame = frame - return self._session.SetCurrentFrame( self._currentFrame ) + if 'line' in frame and frame[ 'line' ]: + self._currentFrame = frame + return self._session.SetCurrentFrame( self._currentFrame ) def OnStopped( self, event ): if 'threadId' in event: @@ -226,10 +227,19 @@ class StackTraceView( object ): if 'name' not in source: source[ 'name' ] = os.path.basename( source[ 'path' ] ) - line = utils.AppendToBuffer( - self._buf, - ' {0}: {1}@{2}:{3}'.format( frame[ 'id' ], - frame[ 'name' ], - source[ 'name' ], - frame[ 'line' ] ) ) + if frame.get( 'presentationHint' ) == 'label': + # Sigh. FOr some reason, it's OK for debug adapters to completely ignore + # the protocol; it seems that the chrome adapter sets 'label' and + # doesn't set 'line' + line = utils.AppendToBuffer( + self._buf, + ' {0}: {1}'.format( frame[ 'id' ], frame[ 'name' ] ) ) + else: + line = utils.AppendToBuffer( + self._buf, + ' {0}: {1}@{2}:{3}'.format( frame[ 'id' ], + frame[ 'name' ], + source[ 'name' ], + frame[ 'line' ] ) ) + self._line_to_frame[ line ] = frame diff --git a/python3/vimspector/variables.py b/python3/vimspector/variables.py index 73ceb1c..d9882c8 100644 --- a/python3/vimspector/variables.py +++ b/python3/vimspector/variables.py @@ -116,6 +116,8 @@ class VariablesView( object ): elif not scope.get( 'expensive' ): # Expand any non-expensive scope unless manually collapsed scope[ '_expanded' ] = True + else: + scope[ '_expanded' ] = False self._scopes.append( scope ) if scope[ '_expanded' ]: diff --git a/support/test/chrome/www/js/test.js b/support/test/chrome/www/js/test.js index cc39af5..273804e 100644 --- a/support/test/chrome/www/js/test.js +++ b/support/test/chrome/www/js/test.js @@ -2,6 +2,7 @@ $( document ).ready( function() { var getMessage = function() { var msg = 'this is '; msg += 'a test'; + msg += ' message'; return msg; };