Allow setting the current thread, use a sign to highlight the line with the current thread
This commit is contained in:
parent
8e3a734141
commit
53b1d12447
6 changed files with 110 additions and 50 deletions
|
|
@ -171,11 +171,18 @@ function! vimspector#Pause() abort
|
||||||
py3 _vimspector_session.Pause()
|
py3 _vimspector_session.Pause()
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! vimspector#PauseThread() abort
|
function! vimspector#PauseContinueThread() abort
|
||||||
if !s:Enabled()
|
if !s:Enabled()
|
||||||
return
|
return
|
||||||
endif
|
endif
|
||||||
py3 _vimspector_session.PauseThread()
|
py3 _vimspector_session.PauseContinueThread()
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! vimspector#SetCurrentThread() abort
|
||||||
|
if !s:Enabled()
|
||||||
|
return
|
||||||
|
endif
|
||||||
|
py3 _vimspector_session.SetCurrentThread()
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! vimspector#Stop() abort
|
function! vimspector#Stop() abort
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,7 @@ class CodeView( object ):
|
||||||
self._logger = logging.getLogger( __name__ )
|
self._logger = logging.getLogger( __name__ )
|
||||||
utils.SetUpLogging( self._logger )
|
utils.SetUpLogging( self._logger )
|
||||||
|
|
||||||
|
# FIXME: This ID is by group, so should be module scope
|
||||||
self._next_sign_id = 1
|
self._next_sign_id = 1
|
||||||
self._breakpoints = defaultdict( list )
|
self._breakpoints = defaultdict( list )
|
||||||
self._signs = {
|
self._signs = {
|
||||||
|
|
|
||||||
|
|
@ -492,18 +492,12 @@ class DebugSession( object ):
|
||||||
} )
|
} )
|
||||||
|
|
||||||
@IfConnected()
|
@IfConnected()
|
||||||
def PauseThread( self ):
|
def PauseContinueThread( self ):
|
||||||
threadId = self._stackTraceView.GetSelectedThreadId()
|
self._stackTraceView.PauseContinueThread()
|
||||||
if threadId is None:
|
|
||||||
utils.UserMessage( 'No thread selected' )
|
|
||||||
return
|
|
||||||
|
|
||||||
self._connection.DoRequest( None, {
|
@IfConnected()
|
||||||
'command': 'pause',
|
def SetCurrentThread( self ):
|
||||||
'arguments': {
|
self._stackTraceView.SetCurrentThread()
|
||||||
'threadId': threadId,
|
|
||||||
},
|
|
||||||
} )
|
|
||||||
|
|
||||||
@IfConnected()
|
@IfConnected()
|
||||||
def ExpandVariable( self ):
|
def ExpandVariable( self ):
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,7 @@ DEFAULTS = {
|
||||||
'vimspectorBP': 9,
|
'vimspectorBP': 9,
|
||||||
'vimspectorBPCond': 9,
|
'vimspectorBPCond': 9,
|
||||||
'vimspectorBPDisabled': 9,
|
'vimspectorBPDisabled': 9,
|
||||||
|
'vimspectorCurrentThread': 200
|
||||||
},
|
},
|
||||||
|
|
||||||
# Installer
|
# Installer
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ import os
|
||||||
import logging
|
import logging
|
||||||
import typing
|
import typing
|
||||||
|
|
||||||
from vimspector import utils
|
from vimspector import utils, signs
|
||||||
|
|
||||||
|
|
||||||
class Thread:
|
class Thread:
|
||||||
|
|
@ -100,6 +100,9 @@ class StackTraceView( object ):
|
||||||
self._sources = {}
|
self._sources = {}
|
||||||
self._scratch_buffers = []
|
self._scratch_buffers = []
|
||||||
|
|
||||||
|
# FIXME: This ID is by group, so should be module scope
|
||||||
|
self._next_sign_id = 1
|
||||||
|
|
||||||
utils.SetUpHiddenBuffer( self._buf, 'vimspector.StackTrace' )
|
utils.SetUpHiddenBuffer( self._buf, 'vimspector.StackTrace' )
|
||||||
utils.SetUpUIWindow( win )
|
utils.SetUpUIWindow( win )
|
||||||
|
|
||||||
|
|
@ -110,11 +113,22 @@ class StackTraceView( object ):
|
||||||
':<C-U>call vimspector#GoToFrame()<CR>' )
|
':<C-U>call vimspector#GoToFrame()<CR>' )
|
||||||
|
|
||||||
if utils.UseWinBar():
|
if utils.UseWinBar():
|
||||||
vim.command( 'nnoremenu 1.2 WinBar.Open '
|
vim.command( 'nnoremenu 1.1 WinBar.Pause/Continue '
|
||||||
|
':call vimspector#PauseContinueThread()<CR>' )
|
||||||
|
vim.command( 'nnoremenu 1.2 WinBar.Expand/Collapse '
|
||||||
':call vimspector#GoToFrame()<CR>' )
|
':call vimspector#GoToFrame()<CR>' )
|
||||||
vim.command( 'nnoremenu 1.1 WinBar.Pause '
|
vim.command( 'nnoremenu 1.3 WinBar.Focus '
|
||||||
':call vimspector#PauseThread()<CR>' )
|
':call vimspector#SetCurrentThread()<CR>' )
|
||||||
|
|
||||||
|
win.options[ 'cursorline' ] = False
|
||||||
|
|
||||||
|
|
||||||
|
if not signs.SignDefined( 'vimspectorCurrentThread' ):
|
||||||
|
signs.DefineSign( 'vimspectorCurrentThread',
|
||||||
|
text = '▶ ',
|
||||||
|
double_text = '▶',
|
||||||
|
texthl = 'MatchParen',
|
||||||
|
linehl = 'CursorLine' )
|
||||||
|
|
||||||
self._line_to_frame = {}
|
self._line_to_frame = {}
|
||||||
self._line_to_thread = {}
|
self._line_to_thread = {}
|
||||||
|
|
@ -137,6 +151,10 @@ class StackTraceView( object ):
|
||||||
self._sources = {}
|
self._sources = {}
|
||||||
self._requesting_threads = StackTraceView.ThreadRequestState.NO
|
self._requesting_threads = StackTraceView.ThreadRequestState.NO
|
||||||
self._pending_thread_request = None
|
self._pending_thread_request = None
|
||||||
|
if self._next_sign_id:
|
||||||
|
signs.UnplaceSign( self._next_sign_id, 'VimspectorStackTrace' )
|
||||||
|
self._next_sign_id = 0
|
||||||
|
|
||||||
with utils.ModifiableScratchBuffer( self._buf ):
|
with utils.ModifiableScratchBuffer( self._buf ):
|
||||||
utils.ClearBuffer( self._buf )
|
utils.ClearBuffer( self._buf )
|
||||||
|
|
||||||
|
|
@ -241,20 +259,28 @@ class StackTraceView( object ):
|
||||||
self._line_to_frame.clear()
|
self._line_to_frame.clear()
|
||||||
self._line_to_thread.clear()
|
self._line_to_thread.clear()
|
||||||
|
|
||||||
|
if self._next_sign_id:
|
||||||
|
signs.UnplaceSign( self._next_sign_id, 'VimspectorStackTrace' )
|
||||||
|
else:
|
||||||
|
self._next_sign_id = 1
|
||||||
|
|
||||||
with ( utils.ModifiableScratchBuffer( self._buf ),
|
with ( utils.ModifiableScratchBuffer( self._buf ),
|
||||||
utils.RestoreCursorPosition() ):
|
utils.RestoreCursorPosition() ):
|
||||||
utils.ClearBuffer( self._buf )
|
utils.ClearBuffer( self._buf )
|
||||||
|
|
||||||
for thread in self._threads:
|
for thread in self._threads:
|
||||||
if self._current_thread == thread.id:
|
|
||||||
icon = '^' if not thread.IsExpanded() else '>'
|
|
||||||
else:
|
|
||||||
icon = '+' if not thread.IsExpanded() else '-'
|
icon = '+' if not thread.IsExpanded() else '-'
|
||||||
|
|
||||||
line = utils.AppendToBuffer(
|
line = utils.AppendToBuffer(
|
||||||
self._buf,
|
self._buf,
|
||||||
f'{icon} Thread: {thread.thread["name"]} ({thread.State()})' )
|
f'{icon} Thread: {thread.thread["name"]} ({thread.State()})' )
|
||||||
|
|
||||||
|
if self._current_thread == thread.id:
|
||||||
|
signs.PlaceSign( self._next_sign_id,
|
||||||
|
'VimspectorStackTrace',
|
||||||
|
'vimspectorCurrentThread',
|
||||||
|
self._buf.name,
|
||||||
|
line )
|
||||||
|
|
||||||
self._line_to_thread[ line ] = thread
|
self._line_to_thread[ line ] = thread
|
||||||
self._DrawStackTrace( thread )
|
self._DrawStackTrace( thread )
|
||||||
|
|
||||||
|
|
@ -280,27 +306,32 @@ class StackTraceView( object ):
|
||||||
} )
|
} )
|
||||||
|
|
||||||
|
|
||||||
def GetSelectedThreadId( self ):
|
def _GetSelectedThread( self ) -> Thread:
|
||||||
if vim.current.buffer != self._buf:
|
if vim.current.buffer != self._buf:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
thread = self._line_to_thread.get( vim.current.window.cursor[ 0 ] )
|
return self._line_to_thread.get( vim.current.window.cursor[ 0 ] )
|
||||||
if not thread:
|
|
||||||
return None
|
|
||||||
|
|
||||||
return thread.id
|
|
||||||
|
def GetSelectedThreadId( self ):
|
||||||
|
thread = self._GetSelectedThread()
|
||||||
|
return thread.id if thread else thread
|
||||||
|
|
||||||
|
|
||||||
|
def SetCurrentThread( self ):
|
||||||
|
thread = self._GetSelectedThread()
|
||||||
|
if not thread:
|
||||||
|
utils.UserMessage( "No thread selected" )
|
||||||
|
else:
|
||||||
|
self._current_thread = thread.id
|
||||||
|
|
||||||
|
self._DrawThreads()
|
||||||
|
|
||||||
|
|
||||||
def ExpandFrameOrThread( self ):
|
def ExpandFrameOrThread( self ):
|
||||||
if vim.current.buffer != self._buf:
|
thread = self._GetSelectedThread()
|
||||||
return
|
|
||||||
|
|
||||||
current_line = vim.current.window.cursor[ 0 ]
|
if thread:
|
||||||
|
|
||||||
if current_line in self._line_to_frame:
|
|
||||||
self._JumpToFrame( self._line_to_frame[ current_line ] )
|
|
||||||
elif current_line in self._line_to_thread:
|
|
||||||
thread = self._line_to_thread[ current_line ]
|
|
||||||
if thread.IsExpanded():
|
if thread.IsExpanded():
|
||||||
thread.Collapse()
|
thread.Collapse()
|
||||||
self._DrawThreads()
|
self._DrawThreads()
|
||||||
|
|
@ -308,6 +339,10 @@ class StackTraceView( object ):
|
||||||
self._LoadStackTrace( thread, False )
|
self._LoadStackTrace( thread, False )
|
||||||
else:
|
else:
|
||||||
utils.UserMessage( "Thread is not stopped" )
|
utils.UserMessage( "Thread is not stopped" )
|
||||||
|
elif vim.current.buffer != self._buf:
|
||||||
|
return
|
||||||
|
elif vim.current.window.cursor[ 0 ] in self._line_to_frame:
|
||||||
|
self._JumpToFrame( self._line_to_frame[ vim.current.window.cursor[ 0 ] ] )
|
||||||
|
|
||||||
|
|
||||||
def _JumpToFrame( self, frame, reason = '' ):
|
def _JumpToFrame( self, frame, reason = '' ):
|
||||||
|
|
@ -329,6 +364,31 @@ class StackTraceView( object ):
|
||||||
else:
|
else:
|
||||||
return do_jump()
|
return do_jump()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def PauseContinueThread( self ):
|
||||||
|
thread = self._GetSelectedThread()
|
||||||
|
if thread is None:
|
||||||
|
utils.UserMessage( 'No thread selected' )
|
||||||
|
elif thread.state == Thread.PAUSED:
|
||||||
|
self._session._connection.DoRequest( None, {
|
||||||
|
'command': 'continue',
|
||||||
|
'arguments': {
|
||||||
|
'threadId': thread.id,
|
||||||
|
},
|
||||||
|
} )
|
||||||
|
elif thread.state == Thread.RUNNING:
|
||||||
|
self._session._connection.DoRequest( None, {
|
||||||
|
'command': 'pause',
|
||||||
|
'arguments': {
|
||||||
|
'threadId': thread.id,
|
||||||
|
},
|
||||||
|
} )
|
||||||
|
else:
|
||||||
|
utils.UserMessage(
|
||||||
|
f'Thread cannot be modified in state {thread.State()}' )
|
||||||
|
|
||||||
|
|
||||||
def OnContinued( self, event = None ):
|
def OnContinued( self, event = None ):
|
||||||
threadId = None
|
threadId = None
|
||||||
allThreadsContinued = True
|
allThreadsContinued = True
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,6 @@ function! s:StartDebugging()
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! Test_Multiple_Threads_Continue()
|
function! Test_Multiple_Threads_Continue()
|
||||||
|
|
||||||
let thread_l = 67
|
let thread_l = 67
|
||||||
let notify_l = 74
|
let notify_l = 74
|
||||||
|
|
||||||
|
|
@ -33,7 +32,7 @@ function! Test_Multiple_Threads_Continue()
|
||||||
call WaitForAssert( {->
|
call WaitForAssert( {->
|
||||||
\ AssertMatchist(
|
\ AssertMatchist(
|
||||||
\ [
|
\ [
|
||||||
\ '> Thread: Thread #1 (paused)',
|
\ '- Thread: Thread #1 (paused)',
|
||||||
\ ' .*: threads!main@threads.cpp:' . string( thread_l )
|
\ ' .*: threads!main@threads.cpp:' . string( thread_l )
|
||||||
\ ],
|
\ ],
|
||||||
\ GetBufLine( winbufnr( g:vimspector_session_windows.stack_trace ),
|
\ GetBufLine( winbufnr( g:vimspector_session_windows.stack_trace ),
|
||||||
|
|
@ -48,7 +47,7 @@ function! Test_Multiple_Threads_Continue()
|
||||||
call WaitForAssert( {->
|
call WaitForAssert( {->
|
||||||
\ AssertMatchist(
|
\ AssertMatchist(
|
||||||
\ [
|
\ [
|
||||||
\ '> Thread: Thread #1 (paused)',
|
\ '- Thread: Thread #1 (paused)',
|
||||||
\ ' .*: threads!main@threads.cpp:' . string( thread_l )
|
\ ' .*: threads!main@threads.cpp:' . string( thread_l )
|
||||||
\ ],
|
\ ],
|
||||||
\ GetBufLine( winbufnr( g:vimspector_session_windows.stack_trace ),
|
\ GetBufLine( winbufnr( g:vimspector_session_windows.stack_trace ),
|
||||||
|
|
@ -73,7 +72,7 @@ function! Test_Multiple_Threads_Continue()
|
||||||
call WaitForAssert( {->
|
call WaitForAssert( {->
|
||||||
\ AssertMatchist(
|
\ AssertMatchist(
|
||||||
\ [
|
\ [
|
||||||
\ '> Thread: Thread #1 (paused)',
|
\ '- Thread: Thread #1 (paused)',
|
||||||
\ ' .*: threads!main@threads.cpp:' . string( thread_l )
|
\ ' .*: threads!main@threads.cpp:' . string( thread_l )
|
||||||
\ ],
|
\ ],
|
||||||
\ GetBufLine( winbufnr( g:vimspector_session_windows.stack_trace ),
|
\ GetBufLine( winbufnr( g:vimspector_session_windows.stack_trace ),
|
||||||
|
|
@ -98,7 +97,7 @@ function! Test_Multiple_Threads_Continue()
|
||||||
call WaitForAssert( {->
|
call WaitForAssert( {->
|
||||||
\ AssertMatchist(
|
\ AssertMatchist(
|
||||||
\ [
|
\ [
|
||||||
\ '> Thread: Thread #1 (paused)',
|
\ '- Thread: Thread #1 (paused)',
|
||||||
\ ' .*: threads!main@threads.cpp:' . string( thread_l )
|
\ ' .*: threads!main@threads.cpp:' . string( thread_l )
|
||||||
\ ],
|
\ ],
|
||||||
\ GetBufLine( winbufnr( g:vimspector_session_windows.stack_trace ),
|
\ GetBufLine( winbufnr( g:vimspector_session_windows.stack_trace ),
|
||||||
|
|
@ -124,7 +123,7 @@ function! Test_Multiple_Threads_Continue()
|
||||||
call WaitForAssert( {->
|
call WaitForAssert( {->
|
||||||
\ AssertMatchist(
|
\ AssertMatchist(
|
||||||
\ [
|
\ [
|
||||||
\ '> Thread: Thread #1 (paused)',
|
\ '- Thread: Thread #1 (paused)',
|
||||||
\ ' .*: threads!main@threads.cpp:' . string( thread_l )
|
\ ' .*: threads!main@threads.cpp:' . string( thread_l )
|
||||||
\ ],
|
\ ],
|
||||||
\ GetBufLine( winbufnr( g:vimspector_session_windows.stack_trace ),
|
\ GetBufLine( winbufnr( g:vimspector_session_windows.stack_trace ),
|
||||||
|
|
@ -149,7 +148,7 @@ function! Test_Multiple_Threads_Continue()
|
||||||
call WaitForAssert( {->
|
call WaitForAssert( {->
|
||||||
\ AssertMatchist(
|
\ AssertMatchist(
|
||||||
\ [
|
\ [
|
||||||
\ '> Thread: Thread #1 (paused)',
|
\ '- Thread: Thread #1 (paused)',
|
||||||
\ ' .*: threads!main@threads.cpp:' . string( notify_l )
|
\ ' .*: threads!main@threads.cpp:' . string( notify_l )
|
||||||
\ ],
|
\ ],
|
||||||
\ GetBufLine( winbufnr( g:vimspector_session_windows.stack_trace ),
|
\ GetBufLine( winbufnr( g:vimspector_session_windows.stack_trace ),
|
||||||
|
|
@ -189,7 +188,7 @@ function! Test_Multiple_Threads_Step()
|
||||||
call WaitForAssert( {->
|
call WaitForAssert( {->
|
||||||
\ AssertMatchist(
|
\ AssertMatchist(
|
||||||
\ [
|
\ [
|
||||||
\ '> Thread: Thread #1 (paused)',
|
\ '- Thread: Thread #1 (paused)',
|
||||||
\ ' .*: threads!main@threads.cpp:' . string( thread_l )
|
\ ' .*: threads!main@threads.cpp:' . string( thread_l )
|
||||||
\ ],
|
\ ],
|
||||||
\ GetBufLine( winbufnr( g:vimspector_session_windows.stack_trace ),
|
\ GetBufLine( winbufnr( g:vimspector_session_windows.stack_trace ),
|
||||||
|
|
@ -347,5 +346,3 @@ function! Test_Multiple_Threads_Step()
|
||||||
call vimspector#test#setup#Reset()
|
call vimspector#test#setup#Reset()
|
||||||
%bwipe!
|
%bwipe!
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" TODO: Set current frame while thread is running sets the PC
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue