Very basic support for launch configuration

This change refactors the way we launch the job and puts it all in an
internal namespace. Having done that, we are able to launch the job from
the python side. This allows us to neatly load a json file, simlar in
format to .vscode's launch.json, but sufficiently different that users
won't just expect the launch.json to work.

This change allows selecting between 2 different adapters to debug the
same c program.
This commit is contained in:
Ben Jackson 2018-05-21 23:44:06 +01:00
commit 269d09b73e
8 changed files with 302 additions and 189 deletions

View file

@ -19,109 +19,11 @@ let s:save_cpo = &cpo
set cpo&vim
" }}}
let s:plugin_base = expand( '<sfile>:p:h' ) . '/../'
let s:command = [
\ 'node',
\ '/Users/ben/.vscode/extensions/webfreak.debug-0.22.0/out/src/lldb.js'
\ ]
" let s:command = [
" \ '/Users/ben/.vscode/extensions/ms-vscode.cpptools-0.17.1/'
" \ 'debugAdapters/OpenDebugAD7'
" \ ]
"
" \ 'node',
" \ '/Users/ben/Development/debugger/vscode-mock-debug/out/debugAdapter.js'
" \ ]
function! s:_OnServerData( channel, data ) abort
py3 << EOF
_vimspector_session.OnChannelData( vim.eval( 'a:data' ) )
EOF
endfunction
function! s:_OnServerError( channel, data ) abort
echom "Channel received error: " . a:data
endfunction
function! s:_OnExit( channel, status ) abort
echom "Channel exit with status " . a:status
endfunction
function! s:_OnClose( channel ) abort
echom "Channel closed"
endfunction
function! vimspector#StartDebugSession() abort
" TODO:
" - Work out the debug configuration (e.g. using RemoteDebug)
" - Start a job running the server in raw mode
" - Start up the python thread to communicate
" - Set up the UI:
" - Signs?
" - Console?
"
" For now, lets:
" - start up an echo process
" - get python talking to it
if exists( 's:job' )
echo "Job is already running"
return
endif
let s:job = job_start( s:command,
\ {
\ 'in_mode': 'raw',
\ 'out_mode': 'raw',
\ 'err_mode': 'raw',
\ 'exit_cb': function( 's:_OnExit' ),
\ 'close_cb': function( 's:_OnClose' ),
\ 'out_cb': function( 's:_OnServerData' ),
\ 'err_cb': function( 's:_OnServerError' )
\ }
\ )
if job_status( s:job ) != 'run'
echom 'Fail whale. Job is ' . job_status( s:job )
return
endif
endfunction
function! s:_Send( msg ) abort
if job_status( s:job ) != 'run'
echom "Server isnt running"
return
endif
let ch = job_getchannel( s:job )
if ch == 'channel fail'
echom "Channel was closed unexpectedly!"
return
endif
call ch_sendraw( ch, a:msg )
endfunction
function! vimspector#StopDebugSession() abort
py3 _vimspector_session.Stop()
if job_status( s:job ) == 'run'
job_stop( s:job, 'term' )
endif
unlet s:job
endfunction
" TODO: Test function
function! vimspector#Launch() abort
call vimspector#StartDebugSession()
" call vimspector#WriteMessageToServer( 'test' )
let ch = job_getchannel( s:job )
py3 << EOF
from vimspector import debug_session
_vimspector_session = debug_session.DebugSession( vim.Function( 's:_Send' ) )
_vimspector_session = debug_session.DebugSession()
_vimspector_session.Start()
EOF
endfunction
@ -146,6 +48,10 @@ function! vimspector#Pause() abort
py3 _vimspector_session.Pause()
endfunction
function! vimspector#Stop() abort
py3 _vimspector_session.Stop()
endfunction
function! vimspector#ExpandVariable() abort
py3 _vimspector_session.ExpandVariable()
endfunction
@ -154,6 +60,7 @@ function! vimspector#GoToFrame() abort
py3 _vimspector_session.GoToFrame()
endfunction
" Boilerplate {{{
" Boilerplate {{{
let &cpo=s:save_cpo
unlet s:save_cpo
" }}}