diff --git a/autoload/vimspector/internal/channel.vim b/autoload/vimspector/internal/channel.vim index d0cb7d2..3e0d298 100644 --- a/autoload/vimspector/internal/channel.vim +++ b/autoload/vimspector/internal/channel.vim @@ -37,22 +37,11 @@ function! s:_OnClose( channel ) abort py3 _vimspector_session.OnServerExit( 0 ) endfunction -function! s:_Send( msg ) abort - call ch_sendraw( s:ch, a:msg ) - return 1 -endfunction - -function! vimspector#internal#channel#Timeout( id ) abort - py3 << EOF -_vimspector_session.OnRequestTimeout( vim.eval( 'a:id' ) ) -EOF -endfunction - function! vimspector#internal#channel#StartDebugSession( config ) abort if exists( 's:ch' ) echo 'Channel is already running' - return v:none + return v:false endif let l:addr = 'localhost:' . a:config[ 'port' ] @@ -70,10 +59,21 @@ function! vimspector#internal#channel#StartDebugSession( config ) abort if ch_status( s:ch ) !=# 'open' echom 'Unable to connect to debug adapter' redraw - return v:none + return v:false endif - return funcref( 's:_Send' ) + return v:true +endfunction + +function! vimspector#internal#channel#Send( msg ) abort + call ch_sendraw( s:ch, a:msg ) + return 1 +endfunction + +function! vimspector#internal#channel#Timeout( id ) abort + py3 << EOF +_vimspector_session.OnRequestTimeout( vim.eval( 'a:id' ) ) +EOF endfunction function! vimspector#internal#channel#StopDebugSession() abort diff --git a/autoload/vimspector/internal/job.vim b/autoload/vimspector/internal/job.vim index 26ba117..530acb3 100644 --- a/autoload/vimspector/internal/job.vim +++ b/autoload/vimspector/internal/job.vim @@ -39,35 +39,11 @@ function! s:_OnClose( channel ) abort redraw endfunction -function! s:_Send( msg ) abort - if ! exists( 's:job' ) - echom "Can't send message: Job was not initialised correctly" - redraw - return 0 - endif - - if job_status( s:job ) !=# 'run' - echom "Can't send message: Job is not running" - redraw - return 0 - endif - - let ch = job_getchannel( s:job ) - if ch ==# 'channel fail' - echom 'Channel was closed unexpectedly!' - redraw - return 0 - endif - - call ch_sendraw( ch, a:msg ) - return 1 -endfunction - function! vimspector#internal#job#StartDebugSession( config ) abort if exists( 's:job' ) echom 'Not starging: Job is already running' redraw - return v:none + return v:false endif let s:job = job_start( a:config[ 'command' ], @@ -91,10 +67,34 @@ function! vimspector#internal#job#StartDebugSession( config ) abort if job_status( s:job ) !=# 'run' echom 'Unable to start job, status is: ' . job_status( s:job ) redraw - return v:none + return v:false endif - return funcref( 's:_Send' ) + return v:true +endfunction + +function! vimspector#internal#job#Send( msg ) abort + if ! exists( 's:job' ) + echom "Can't send message: Job was not initialised correctly" + redraw + return 0 + endif + + if job_status( s:job ) !=# 'run' + echom "Can't send message: Job is not running" + redraw + return 0 + endif + + let ch = job_getchannel( s:job ) + if ch ==# 'channel fail' + echom 'Channel was closed unexpectedly!' + redraw + return 0 + endif + + call ch_sendraw( ch, a:msg ) + return 1 endfunction function! vimspector#internal#job#StopDebugSession() abort diff --git a/python3/vimspector/debug_session.py b/python3/vimspector/debug_session.py index 8eec9f4..edaf75c 100644 --- a/python3/vimspector/debug_session.py +++ b/python3/vimspector/debug_session.py @@ -492,19 +492,18 @@ class DebugSession( object ): self._adapter[ 'cwd' ] = os.getcwd() vim.vars[ '_vimspector_adapter_spec' ] = self._adapter - channel_send_func = vim.bindeval( - "vimspector#internal#{}#StartDebugSession( " - " g:_vimspector_adapter_spec " - ")".format( self._connection_type ) ) - - if channel_send_func is None: + if not vim.eval( "vimspector#internal#{}#StartDebugSession( " + " g:_vimspector_adapter_spec " + ")".format( self._connection_type ) ): self._logger.error( "Unable to start debug server" ) else: self._connection = debug_adapter_connection.DebugAdapterConnection( self, - channel_send_func ) + lambda msg: utils.Call( + "vimspector#internal#{}#Send".format( self._connection_type ), + msg ) ) - self._logger.info( 'Debug Adapter Started' ) + self._logger.info( 'Debug Adapter Started' ) def _StopDebugAdapter( self, callback = None ): def handler( *args ): diff --git a/python3/vimspector/utils.py b/python3/vimspector/utils.py index ba930ba..6fea1c5 100644 --- a/python3/vimspector/utils.py +++ b/python3/vimspector/utils.py @@ -449,3 +449,17 @@ def ToUnicode( b ): if isinstance( b, bytes ): return b.decode( 'utf-8' ) return b + + +# Call a vimscript function with suplied arguments. +def Call( vimscript_function, *args ): + call = vimscript_function + '(' + for index, arg in enumerate( args ): + arg_name = 'vimspector_internal_arg_{}'.format( index ) + vim.vars[ arg_name ] = arg + call += 'g:' + arg_name + if index: + call += ',' + + call += ')' + vim.eval( call )