Skip to content

Commit

Permalink
Merge pull request puremourning#112 from puremourning/syntax-stack
Browse files Browse the repository at this point in the history
Set syntax in stack trace too
  • Loading branch information
mergify[bot] authored Feb 4, 2020
2 parents db95fe0 + 19cc58f commit ac56e3a
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 34 deletions.
1 change: 1 addition & 0 deletions python3/vimspector/debug_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,7 @@ def SetCurrentFrame( self, frame ):

if frame:
self._variablesView.SetSyntax( self._codeView.current_syntax )
self._stackTraceView.SetSyntax( self._codeView.current_syntax )
self._variablesView.LoadScopes( frame )
self._variablesView.EvaluateWatches()
else:
Expand Down
54 changes: 33 additions & 21 deletions python3/vimspector/stack_trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,20 @@ def __init__( self, session, connection, buf ):
self._session = session
self._connection = connection

self._currentThread = None
self._currentFrame = None
self._current_thread = None
self._current_frame = None
self._current_syntax = ""

self._threads = []
self._sources = {}

utils.SetUpScratchBuffer( self._buf, 'vimspector.StackTrace' )

vim.current.buffer = self._buf
# FIXME: Remove all usage of "Windown" and just use buffers to prevent all
# the bugs around the window being closed.
self._win = vim.current.window

vim.command( 'nnoremap <buffer> <CR> :call vimspector#GoToFrame()<CR>' )

self._line_to_frame = {}
Expand All @@ -53,14 +59,15 @@ def __init__( self, session, connection, buf ):


def GetCurrentThreadId( self ):
return self._currentThread
return self._current_thread

def GetCurrentFrame( self ):
return self._currentFrame
return self._current_frame

def Clear( self ):
self._currentFrame = None
self._currentThread = None
self._current_frame = None
self._current_thread = None
self._current_syntax = ""
self._threads = []
self._sources = {}
with utils.ModifiableScratchBuffer( self._buf ):
Expand Down Expand Up @@ -102,10 +109,10 @@ def consume_threads( message ):
for thread in message[ 'body' ][ 'threads' ]:
self._threads.append( thread )

if infer_current_frame and thread[ 'id' ] == self._currentThread:
if infer_current_frame and thread[ 'id' ] == self._current_thread:
self._LoadStackTrace( thread, True )
elif infer_current_frame and self._currentThread is None:
self._currentThread = thread[ 'id' ]
elif infer_current_frame and self._current_thread is None:
self._current_thread = thread[ 'id' ]
self._LoadStackTrace( thread, True )

self._DrawThreads()
Expand Down Expand Up @@ -170,8 +177,8 @@ def ExpandFrameOrThread( self ):
def _JumpToFrame( self, frame ):
def do_jump():
if 'line' in frame and frame[ 'line' ] > 0:
self._currentFrame = frame
return self._session.SetCurrentFrame( self._currentFrame )
self._current_frame = frame
return self._session.SetCurrentFrame( self._current_frame )
return False

source = frame.get( 'source' ) or {}
Expand All @@ -188,47 +195,47 @@ def handle_resolved_source( resolved_source ):

def OnStopped( self, event ):
if 'threadId' in event:
self._currentThread = event[ 'threadId' ]
self._current_thread = event[ 'threadId' ]
elif event.get( 'allThreadsStopped', False ) and self._threads:
self._currentThread = self._threads[ 0 ][ 'id' ]
self._current_thread = self._threads[ 0 ][ 'id' ]

if self._currentThread is not None:
if self._current_thread is not None:
for thread in self._threads:
if thread[ 'id' ] == self._currentThread:
if thread[ 'id' ] == self._current_thread:
self._LoadStackTrace( thread, True )
return

self.LoadThreads( True )

def OnThreadEvent( self, event ):
if event[ 'reason' ] == 'started' and self._currentThread is None:
self._currentThread = event[ 'threadId' ]
if event[ 'reason' ] == 'started' and self._current_thread is None:
self._current_thread = event[ 'threadId' ]
self.LoadThreads( True )

def Continue( self ):
if self._currentThread is None:
if self._current_thread is None:
utils.UserMessage( 'No current thread', persist = True )
return

self._session._connection.DoRequest( None, {
'command': 'continue',
'arguments': {
'threadId': self._currentThread,
'threadId': self._current_thread,
},
} )

self._session.ClearCurrentFrame()
self.LoadThreads( True )

def Pause( self ):
if self._currentThread is None:
if self._current_thread is None:
utils.UserMessage( 'No current thread', persist = True )
return

self._session._connection.DoRequest( None, {
'command': 'pause',
'arguments': {
'threadId': self._currentThread,
'threadId': self._current_thread,
},
} )

Expand Down Expand Up @@ -294,3 +301,8 @@ def consume_source( msg ):
'source': source
}
} )

def SetSyntax( self, syntax ):
self._current_syntax = utils.SetSyntax( self._current_syntax,
syntax,
self._win )
14 changes: 14 additions & 0 deletions python3/vimspector/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -501,3 +501,17 @@ def wrapper( *args, **kwargs ):
@memoize
def Exists( expr ):
return int( vim.eval( f'exists( "{ expr }" )' ) )


def SetSyntax( current_syntax, syntax, *args ):
if not syntax:
syntax = ''

if current_syntax == syntax:
return

for win in args:
with LetCurrentWindow( win ):
vim.command( 'set syntax={}'.format( Escape( syntax ) ) )

return syntax
17 changes: 4 additions & 13 deletions python3/vimspector/variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,18 +387,9 @@ def failure_handler( reason, message ):


def SetSyntax( self, syntax ):
if not syntax:
syntax = ''

if self._current_syntax == syntax:
return

self._current_syntax = syntax

with utils.LetCurrentWindow( self._vars.win ):
vim.command( 'set syntax={}'.format( utils.Escape( syntax ) ) )

with utils.LetCurrentWindow( self._watch.win ):
vim.command( 'set syntax={}'.format( utils.Escape( syntax ) ) )
self._current_syntax = utils.SetSyntax( self._current_syntax,
syntax,
self._vars.win,
self._watch.win )

# vim: sw=2

0 comments on commit ac56e3a

Please sign in to comment.