WIP: Make multi-session debugging sort of work

This passes the session id around everywhere and ensures that things
like buffer names are all unique.

We now have the _vimspector_session update to point to the active (or
last accessed tab). This feels fairly natural and mostly seems to work.

NOTE: in vscode there is no "multiple tabs" - they actually add the
subprocesses to the stack trace somehow and when you click on a frame in
that it switches to the session for that process. Each process PC is
visible in the editor. It's kind of confusing.

Things still broken:
 - vimspector_session_windows
 - breakpoints need to be project-wide
 - PC display (how to show "all" PCs, or just show the current one for
   the current tab ?)
 - it would be nice for the tterminal buffers to be visible on all tabs.
   not sure how to do that.
This commit is contained in:
Ben Jackson 2021-03-31 21:55:33 +01:00
commit 2f05a7f66a
16 changed files with 261 additions and 99 deletions

View file

@ -28,9 +28,8 @@ function! s:_OnServerData( session_id, channel, data ) abort
return
endif
py3 << EOF
_vimspector_session.OnChannelData( vim.eval( 'a:data' ) )
EOF
py3 _VimspectorSession( vim.eval( 'a:session_id' ) ).OnChannelData(
\ vim.eval( 'a:data' ) )
endfunction
function! s:_OnClose( session_id, channel ) abort
@ -42,7 +41,7 @@ function! s:_OnClose( session_id, channel ) abort
echom 'Channel closed'
redraw
unlet s:channels[ a:session_id ]
py3 _vimspector_session.OnServerExit( 0 )
py3 _VimspectorSession( vim.eval( 'a:session_id' ) ).OnServerExit( 0 )
endfunction
function! vimspector#internal#channel#StartDebugSession(
@ -99,9 +98,8 @@ function! vimspector#internal#channel#Send( session_id, msg ) abort
endfunction
function! vimspector#internal#channel#Timeout( session_id, id ) abort
py3 << EOF
_vimspector_session.OnRequestTimeout( vim.eval( 'a:id' ) )
EOF
py3 _VimspectorSession( vim.eval( 'a:session_id' ) ).OnRequestTimeout(
\ vim.eval( 'a:id' ) )
endfunction
function! s:_ChannelExists( session_id ) abort
@ -149,7 +147,7 @@ function! vimspector#internal#channel#StopDebugSession( session_id ) abort
call s:_OnServerData( s:channels[ a:session_id ], data )
endwhile
if has_key( s:channels, a:session_id )
call s:_OnClose( s:channels[ a:session_id ] )
call s:_OnClose( a:session_id, s:channels[ a:session_id ] )
endif
endfunction

View file

@ -29,7 +29,8 @@ function! s:_OnServerData( session_id, channel, data ) abort
return
endif
py3 _vimspector_session.OnChannelData( vim.eval( 'a:data' ) )
py3 _VimspectorSession( vim.eval( 'a:session_id' ) ).OnChannelData(
\ vim.eval( 'a:data' ) )
endfunction
function! s:_OnServerError( session_id, channel, data ) abort
@ -39,7 +40,8 @@ function! s:_OnServerError( session_id, channel, data ) abort
return
endif
py3 _vimspector_session.OnServerStderr( vim.eval( 'a:data' ) )
py3 _VimspectorSession( vim.eval( 'a:session_id' ) ).OnServerStderr(
\ vim.eval( 'a:data' ) )
endfunction
@ -58,7 +60,8 @@ function! s:_OnExit( session_id, channel, status ) abort
if has_key( s:jobs, a:session_id )
unlet s:jobs[ a:session_id ]
endif
py3 _vimspector_session.OnServerExit( vim.eval( 'a:status' ) )
py3 _VimspectorSession( vim.eval( 'a:session_id' ) ).OnServerExit(
\ vim.eval( 'a:status' ) )
endfunction
function! s:_OnClose( session_id, channel ) abort

View file

@ -26,11 +26,22 @@ endif
function! vimspector#internal#state#Reset() abort
try
py3 import vim
py3 _vimspector_session = __import__(
\ "vimspector",
\ fromlist=[ "session_manager" ] ).session_manager.Get().NewSession(
\ vim.eval( 's:prefix' ) )
py3 <<EOF
import vim
_vimspector_session_man = __import__(
"vimspector",
fromlist=[ "session_manager" ] ).session_manager.Get()
# Deprecated
_vimspector_session = _vimspector_session_man.NewSession(
vim.eval( 's:prefix' ) )
def _VimspectorSession( session_id ):
return _vimspector_session_man.GetSession( int( session_id ) )
EOF
catch /.*/
echohl WarningMsg
echom 'Exception while loading vimspector:' v:exception
@ -47,6 +58,22 @@ function! vimspector#internal#state#GetAPIPrefix() abort
return s:prefix
endfunction
function! vimspector#internal#state#SwitchToSession( id ) abort
py3 _vimspector_session = _VimspectorSession( vim.eval( 'a:id' ) )
endfunction
function! vimspector#internal#state#OnTabEnter() abort
py3 <<EOF
session = _vimspector_session_man.SessionForTab(
int( vim.eval( 'tabpagenr()' ) ) )
if session is not None:
_vimspector_session = session
EOF
endfunction
" Boilerplate {{{
let &cpoptions=s:save_cpo
unlet s:save_cpo