Skip to content

Commit

Permalink
Wrap the terminal API in vimscript layer
Browse files Browse the repository at this point in the history
  • Loading branch information
puremourning committed Jan 8, 2020
1 parent d8acbbf commit bf2718f
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 15 deletions.
2 changes: 1 addition & 1 deletion autoload/vimspector/internal/job.vim
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ endfunction
function! s:_OnExit( channel, status ) abort
echom 'Channel exit with status ' . a:status
redraw
unlet s:job
unlet s:job
py3 _vimspector_session.OnServerExit( vim.eval( 'a:status' ) )
endfunction

Expand Down
37 changes: 37 additions & 0 deletions autoload/vimspector/internal/term.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
" vimspector - A multi-language debugging system for Vim
" Copyright 2018 Ben Jackson
"
" Licensed under the Apache License, Version 2.0 (the "License");
" you may not use this file except in compliance with the License.
" You may obtain a copy of the License at
"
" http://www.apache.org/licenses/LICENSE-2.0
"
" Unless required by applicable law or agreed to in writing, software
" distributed under the License is distributed on an "AS IS" BASIS,
" WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
" See the License for the specific language governing permissions and
" limitations under the License.


" Boilerplate {{{
let s:save_cpo = &cpoptions
set cpoptions&vim
" }}}

function! vimspector#internal#term#Start( cmd, opts ) abort
return term_start( a:cmd, a:opts )
endfunction

function! vimspector#internal#term#IsFinished( bufno ) abort
return index( split( term_getstatus( a:bufno ), ',' ), 'finished' ) >= 0
endfunction

function! vimspector#internal#term#GetPID( bufno ) abort
return job_info( term_getjob( a:bufno ) ).process
endfunction

" Boilerplate {{{
let &cpoptions=s:save_cpo
unlet s:save_cpo
" }}}
14 changes: 5 additions & 9 deletions python3/vimspector/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,8 @@ def LaunchTerminal( self, params ):
if self._terminal_window is not None:
assert self._terminal_buffer_number
if ( self._terminal_window.buffer.number == self._terminal_buffer_number
and 'finished' in vim.eval( 'term_getstatus( {} )'.format(
self._terminal_buffer_number ) ) ):
and int( utils.Call( 'vimspector#internal#term#IsFinished',
self._terminal_buffer_number ) ) ):
window_for_start = self._terminal_window
options[ 'curwin' ] = 1

Expand All @@ -224,13 +224,9 @@ def LaunchTerminal( self, params ):
with utils.TemporaryVimOptions( { 'splitright': True,
'equalalways': False } ):
with utils.LetCurrentWindow( window_for_start ):
# TODO/FIXME: Do something about closing this when we reset ?
vim_cmd = 'term_start( {}, {} )'.format( json.dumps( args ),
json.dumps( options ) )

self._logger.debug( 'Start terminal: {}'.format( vim_cmd ) )

buffer_number = int( vim.eval( vim_cmd ) )
buffer_number = int( utils.Call( 'vimspector#internal#term#Start',
args,
options ) )
terminal_window = vim.current.window

if buffer_number is None or buffer_number <= 0:
Expand Down
4 changes: 2 additions & 2 deletions python3/vimspector/debug_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -773,8 +773,8 @@ def OnRequest_runInTerminal( self, message ):
buffer_number = self._codeView.LaunchTerminal( params )

response = {
'processId': vim.eval( 'job_info( term_getjob( {} ) )'
'.process'.format( buffer_number ) )
'processId': int( utils.Call( 'vimspector#internal#term#GetPID',
buffer_number ) )
}

self._connection.DoResponse( message, None, response )
Expand Down
8 changes: 5 additions & 3 deletions python3/vimspector/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,11 +446,13 @@ def ToUnicode( b ):
def Call( vimscript_function, *args ):
call = vimscript_function + '('
for index, arg in enumerate( args ):
if index > 0:
call += ', '

arg_name = 'vimspector_internal_arg_{}'.format( index )
vim.vars[ arg_name ] = arg
call += 'g:' + arg_name
if index:
call += ','

call += ')'
vim.eval( call )
_logger.debug( 'Calling: {}'.format( call ) )
return vim.eval( call )

0 comments on commit bf2718f

Please sign in to comment.