Support jumping up/down the stack
Split out stack trace view into its own thing. Support jumping to code location.
This commit is contained in:
parent
2c5caf9cf5
commit
fa627712e2
3 changed files with 84 additions and 35 deletions
69
python3/vimspector/stack_trace.py
Normal file
69
python3/vimspector/stack_trace.py
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
# vimspector - A multi-language debugging system for Vim
|
||||
# Copyright 2018 Ben Jackson
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import logging
|
||||
import vim
|
||||
|
||||
from vimspector import utils
|
||||
|
||||
_logger = logging.getLogger( __name__ )
|
||||
|
||||
|
||||
class StackTraceView( object ):
|
||||
def __init__( self, session, connection, buf ):
|
||||
self._buf = buf
|
||||
self._session = session
|
||||
self._connection = connection
|
||||
|
||||
utils.SetUpScratchBuffer( self._buf )
|
||||
vim.current.buffer = self._buf
|
||||
vim.command( 'nnoremap <buffer> <CR> :call vimspector#GoToFrame()<CR>' )
|
||||
|
||||
self._line_to_frame = {}
|
||||
|
||||
def LoadStackTrace( self, thread_id ):
|
||||
self._connection.DoRequest( self._PrintStackTrace, {
|
||||
'command': 'stackTrace',
|
||||
'arguments': {
|
||||
'threadId': thread_id,
|
||||
}
|
||||
} )
|
||||
|
||||
def GoToFrame( self ):
|
||||
if vim.current.buffer != self._buf:
|
||||
return
|
||||
|
||||
current_line = vim.current.window.cursor[ 0 ]
|
||||
if current_line not in self._line_to_frame:
|
||||
return
|
||||
|
||||
self._session.SetCurrentFrame( self._line_to_frame[ current_line ] )
|
||||
|
||||
def _PrintStackTrace( self, message ):
|
||||
with utils.ModifiableScratchBuffer( self._buf ):
|
||||
self._buf[:] = None
|
||||
self._buf.append( 'Stack trace' )
|
||||
|
||||
stackFrames = message[ 'body' ][ 'stackFrames' ]
|
||||
|
||||
for frame in stackFrames:
|
||||
self._buf.append(
|
||||
'{0}: {1}@{2}:{3}'.format( frame[ 'id' ],
|
||||
frame[ 'name' ],
|
||||
frame[ 'source' ][ 'name' ],
|
||||
frame[ 'line' ] ) )
|
||||
self._line_to_frame[ len( self._buf ) ] = frame
|
||||
|
||||
self._session.SetCurrentFrame( stackFrames[ 0 ] )
|
||||
Loading…
Add table
Add a link
Reference in a new issue