Wrap the terminal API in vimscript layer
This commit is contained in:
parent
d1e3b648d3
commit
ee1bb009ea
5 changed files with 50 additions and 15 deletions
37
autoload/vimspector/internal/term.vim
Normal file
37
autoload/vimspector/internal/term.vim
Normal file
|
|
@ -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
|
||||||
|
" }}}
|
||||||
|
|
@ -214,7 +214,7 @@ class CodeView( object ):
|
||||||
if self._terminal_window is not None:
|
if self._terminal_window is not None:
|
||||||
assert self._terminal_buffer_number
|
assert self._terminal_buffer_number
|
||||||
if ( self._terminal_window.buffer.number == self._terminal_buffer_number
|
if ( self._terminal_window.buffer.number == self._terminal_buffer_number
|
||||||
and 'finished' in vim.eval( 'term_getstatus( {} )'.format(
|
and int( utils.Call( 'vimspector#internal#term#IsFinished',
|
||||||
self._terminal_buffer_number ) ) ):
|
self._terminal_buffer_number ) ) ):
|
||||||
window_for_start = self._terminal_window
|
window_for_start = self._terminal_window
|
||||||
options[ 'curwin' ] = 1
|
options[ 'curwin' ] = 1
|
||||||
|
|
@ -224,13 +224,9 @@ class CodeView( object ):
|
||||||
with utils.TemporaryVimOptions( { 'splitright': True,
|
with utils.TemporaryVimOptions( { 'splitright': True,
|
||||||
'equalalways': False } ):
|
'equalalways': False } ):
|
||||||
with utils.LetCurrentWindow( window_for_start ):
|
with utils.LetCurrentWindow( window_for_start ):
|
||||||
# TODO/FIXME: Do something about closing this when we reset ?
|
buffer_number = int( utils.Call( 'vimspector#internal#term#Start',
|
||||||
vim_cmd = 'term_start( {}, {} )'.format( json.dumps( args ),
|
args,
|
||||||
json.dumps( options ) )
|
options ) )
|
||||||
|
|
||||||
self._logger.debug( 'Start terminal: {}'.format( vim_cmd ) )
|
|
||||||
|
|
||||||
buffer_number = int( vim.eval( vim_cmd ) )
|
|
||||||
terminal_window = vim.current.window
|
terminal_window = vim.current.window
|
||||||
|
|
||||||
if buffer_number is None or buffer_number <= 0:
|
if buffer_number is None or buffer_number <= 0:
|
||||||
|
|
|
||||||
|
|
@ -798,8 +798,8 @@ class DebugSession( object ):
|
||||||
buffer_number = self._codeView.LaunchTerminal( params )
|
buffer_number = self._codeView.LaunchTerminal( params )
|
||||||
|
|
||||||
response = {
|
response = {
|
||||||
'processId': vim.eval( 'job_info( term_getjob( {} ) )'
|
'processId': int( utils.Call( 'vimspector#internal#term#GetPID',
|
||||||
'.process'.format( buffer_number ) )
|
buffer_number ) )
|
||||||
}
|
}
|
||||||
|
|
||||||
self._connection.DoResponse( message, None, response )
|
self._connection.DoResponse( message, None, response )
|
||||||
|
|
|
||||||
|
|
@ -455,11 +455,13 @@ def ToUnicode( b ):
|
||||||
def Call( vimscript_function, *args ):
|
def Call( vimscript_function, *args ):
|
||||||
call = vimscript_function + '('
|
call = vimscript_function + '('
|
||||||
for index, arg in enumerate( args ):
|
for index, arg in enumerate( args ):
|
||||||
|
if index > 0:
|
||||||
|
call += ', '
|
||||||
|
|
||||||
arg_name = 'vimspector_internal_arg_{}'.format( index )
|
arg_name = 'vimspector_internal_arg_{}'.format( index )
|
||||||
vim.vars[ arg_name ] = arg
|
vim.vars[ arg_name ] = arg
|
||||||
call += 'g:' + arg_name
|
call += 'g:' + arg_name
|
||||||
if index:
|
|
||||||
call += ','
|
|
||||||
|
|
||||||
call += ')'
|
call += ')'
|
||||||
vim.eval( call )
|
_logger.debug( 'Calling: {}'.format( call ) )
|
||||||
|
return vim.eval( call )
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue