From b322a2e89cd95c95b9610713f84a74449ea5bd9d Mon Sep 17 00:00:00 2001 From: Ben Jackson Date: Fri, 3 Jul 2020 13:18:17 +0100 Subject: [PATCH] Allow 'channel' based transports to also start a job --- autoload/vimspector/internal/channel.vim | 28 +++++++++++++++++++----- autoload/vimspector/internal/job.vim | 4 ++-- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/autoload/vimspector/internal/channel.vim b/autoload/vimspector/internal/channel.vim index 05cf26c..0100f08 100644 --- a/autoload/vimspector/internal/channel.vim +++ b/autoload/vimspector/internal/channel.vim @@ -39,6 +39,21 @@ function! vimspector#internal#channel#StartDebugSession( config ) abort return v:false endif + " If we _also_ have a command line, then start the actual job. This allows for + " servers which start up and listen on some port + if has_key( a:config, 'command' ) + let s:job = job_start( a:config[ 'command' ], + \ { + \ 'in_mode': 'raw', + \ 'out_mode': 'raw', + \ 'err_mode': 'raw', + \ 'stoponexit': 'term', + \ 'env': a:config[ 'env' ], + \ 'cwd': a:config[ 'cwd' ], + \ } + \ ) + endif + let l:addr = get( a:config, 'host', 'localhost' ) . ':' . a:config[ 'port' ] echo 'Connecting to ' . l:addr . '... (waiting fo up to 10 seconds)' @@ -72,11 +87,7 @@ EOF endfunction function! vimspector#internal#channel#StopDebugSession() abort - if !exists( 's:ch' ) - return - endif - - if ch_status( s:ch ) ==# 'open' + if exists( 's:ch' ) && ch_status( s:ch ) ==# 'open' " channel is open, close it and trigger the callback. The callback is _not_ " triggered when manually calling ch_close. if we get here and the channel " is not open, then we there is a _OnClose callback waiting for us, so do @@ -84,10 +95,15 @@ function! vimspector#internal#channel#StopDebugSession() abort call ch_close( s:ch ) call s:_OnClose( s:ch ) endif + + if exists( 's:job' ) && job_status( s:job ) ==# 'run' + call job_stop( s:job, 'kill' ) + unlet s:job + endif endfunction function! vimspector#internal#channel#Reset() abort - if exists( 's:ch' ) + if exists( 's:ch' ) || exists( 's:job' ) call vimspector#internal#channel#StopDebugSession() endif endfunction diff --git a/autoload/vimspector/internal/job.vim b/autoload/vimspector/internal/job.vim index 88c63cd..a93a004 100644 --- a/autoload/vimspector/internal/job.vim +++ b/autoload/vimspector/internal/job.vim @@ -128,8 +128,8 @@ function! vimspector#internal#job#StopDebugSession() abort endif if job_status( s:job ) ==# 'run' - echom 'Terminating job' - redraw + echom 'Terminating job' + redraw call job_stop( s:job, 'kill' ) endif endfunction