Add a way to have multiple vim API layers
This commit is contained in:
parent
5aa33c19f7
commit
18627b9244
6 changed files with 35 additions and 20 deletions
|
|
@ -127,7 +127,7 @@ function! vimspector#internal#job#StartCommandWithLog( cmd, category ) abort
|
||||||
let l:index = len( s:commands[ a:category ] )
|
let l:index = len( s:commands[ a:category ] )
|
||||||
|
|
||||||
call add( s:commands[ a:category ], job_start(
|
call add( s:commands[ a:category ], job_start(
|
||||||
\ a:cmd,
|
\ a:cmd,
|
||||||
\ {
|
\ {
|
||||||
\ 'out_io': 'buffer',
|
\ 'out_io': 'buffer',
|
||||||
\ 'in_io': 'null',
|
\ 'in_io': 'null',
|
||||||
|
|
|
||||||
|
|
@ -20,9 +20,10 @@ set cpoptions&vim
|
||||||
" }}}
|
" }}}
|
||||||
|
|
||||||
function! vimspector#internal#state#Reset() abort
|
function! vimspector#internal#state#Reset() abort
|
||||||
|
let prefix = ''
|
||||||
py3 << EOF
|
py3 << EOF
|
||||||
from vimspector import debug_session
|
from vimspector import debug_session
|
||||||
_vimspector_session = debug_session.DebugSession()
|
_vimspector_session = debug_session.DebugSession( vim.eval( 'prefix' ) )
|
||||||
EOF
|
EOF
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -22,8 +22,9 @@ from vimspector import utils
|
||||||
|
|
||||||
|
|
||||||
class CodeView( object ):
|
class CodeView( object ):
|
||||||
def __init__( self, window ):
|
def __init__( self, window, api_prefix ):
|
||||||
self._window = window
|
self._window = window
|
||||||
|
self._api_prefix = api_prefix
|
||||||
|
|
||||||
self._terminal_window = None
|
self._terminal_window = None
|
||||||
self._terminal_buffer_number = None
|
self._terminal_buffer_number = None
|
||||||
|
|
@ -214,7 +215,8 @@ 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 int( utils.Call( 'vimspector#internal#term#IsFinished',
|
and int( utils.Call( 'vimspector#internal#{}term#IsFinished'.format(
|
||||||
|
self._api_prefix ),
|
||||||
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,9 +226,11 @@ 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 ):
|
||||||
buffer_number = int( utils.Call( 'vimspector#internal#term#Start',
|
buffer_number = int(
|
||||||
args,
|
utils.Call(
|
||||||
options ) )
|
'vimspector#internal#{}term#Start'.format( self._api_prefix ),
|
||||||
|
args,
|
||||||
|
options ) )
|
||||||
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:
|
||||||
|
|
|
||||||
|
|
@ -41,11 +41,14 @@ USER_CHOICES = {}
|
||||||
|
|
||||||
|
|
||||||
class DebugSession( object ):
|
class DebugSession( object ):
|
||||||
def __init__( self ):
|
def __init__( self, api_prefix ):
|
||||||
self._logger = logging.getLogger( __name__ )
|
self._logger = logging.getLogger( __name__ )
|
||||||
utils.SetUpLogging( self._logger )
|
utils.SetUpLogging( self._logger )
|
||||||
|
|
||||||
|
self._api_prefix = api_prefix
|
||||||
|
|
||||||
self._logger.info( "**** INITIALISING NEW VIMSPECTOR SESSION ****" )
|
self._logger.info( "**** INITIALISING NEW VIMSPECTOR SESSION ****" )
|
||||||
|
self._logger.info( "API is: {}".format( api_prefix ) )
|
||||||
self._logger.info( 'VIMSPECTOR_HOME = %s', VIMSPECTOR_HOME )
|
self._logger.info( 'VIMSPECTOR_HOME = %s', VIMSPECTOR_HOME )
|
||||||
self._logger.info( 'gadgetDir = %s',
|
self._logger.info( 'gadgetDir = %s',
|
||||||
install.GetGadgetDir( VIMSPECTOR_HOME,
|
install.GetGadgetDir( VIMSPECTOR_HOME,
|
||||||
|
|
@ -405,7 +408,7 @@ class DebugSession( object ):
|
||||||
self._uiTab = vim.current.tabpage
|
self._uiTab = vim.current.tabpage
|
||||||
|
|
||||||
# Code window
|
# Code window
|
||||||
self._codeView = code.CodeView( vim.current.window )
|
self._codeView = code.CodeView( vim.current.window, self._api_prefix )
|
||||||
|
|
||||||
# Call stack
|
# Call stack
|
||||||
with utils.TemporaryVimOptions( { 'splitright': False,
|
with utils.TemporaryVimOptions( { 'splitright': False,
|
||||||
|
|
@ -441,7 +444,8 @@ class DebugSession( object ):
|
||||||
vim.command( '10spl' )
|
vim.command( '10spl' )
|
||||||
vim.command( 'enew' )
|
vim.command( 'enew' )
|
||||||
self._outputView = output.OutputView( self._connection,
|
self._outputView = output.OutputView( self._connection,
|
||||||
vim.current.window )
|
vim.current.window,
|
||||||
|
self._api_prefix )
|
||||||
|
|
||||||
def ClearCurrentFrame( self ):
|
def ClearCurrentFrame( self ):
|
||||||
self.SetCurrentFrame( None )
|
self.SetCurrentFrame( None )
|
||||||
|
|
@ -482,6 +486,8 @@ class DebugSession( object ):
|
||||||
port = utils.AskForInput( 'Enter port to connect to: ' )
|
port = utils.AskForInput( 'Enter port to connect to: ' )
|
||||||
self._adapter[ 'port' ] = port
|
self._adapter[ 'port' ] = port
|
||||||
|
|
||||||
|
self._connection_type = self._api_prefix + self._connection_type
|
||||||
|
|
||||||
# TODO: Do we actually need to copy and update or does Vim do that?
|
# TODO: Do we actually need to copy and update or does Vim do that?
|
||||||
env = os.environ.copy()
|
env = os.environ.copy()
|
||||||
if 'env' in self._adapter:
|
if 'env' in self._adapter:
|
||||||
|
|
@ -795,11 +801,12 @@ class DebugSession( object ):
|
||||||
self._logger.debug( 'Defaulting working directory to %s',
|
self._logger.debug( 'Defaulting working directory to %s',
|
||||||
params[ 'cwd' ] )
|
params[ 'cwd' ] )
|
||||||
|
|
||||||
buffer_number = self._codeView.LaunchTerminal( params )
|
term_id = self._codeView.LaunchTerminal( params )
|
||||||
|
|
||||||
response = {
|
response = {
|
||||||
'processId': int( utils.Call( 'vimspector#internal#term#GetPID',
|
'processId': int( utils.Call(
|
||||||
buffer_number ) )
|
'vimspector#internal#{}term#GetPID'.format( self._api_prefix ),
|
||||||
|
term_id ) )
|
||||||
}
|
}
|
||||||
|
|
||||||
self._connection.DoResponse( message, None, response )
|
self._connection.DoResponse( message, None, response )
|
||||||
|
|
|
||||||
|
|
@ -40,10 +40,11 @@ def CategoryToBuffer( category ):
|
||||||
|
|
||||||
|
|
||||||
class OutputView( object ):
|
class OutputView( object ):
|
||||||
def __init__( self, connection, window ):
|
def __init__( self, connection, window, api_prefix ):
|
||||||
self._window = window
|
self._window = window
|
||||||
self._connection = connection
|
self._connection = connection
|
||||||
self._buffers = {}
|
self._buffers = {}
|
||||||
|
self._api_prefix = api_prefix
|
||||||
|
|
||||||
for b in set( BUFFER_MAP.values() ):
|
for b in set( BUFFER_MAP.values() ):
|
||||||
self._CreateBuffer( b )
|
self._CreateBuffer( b )
|
||||||
|
|
@ -95,7 +96,7 @@ class OutputView( object ):
|
||||||
def Clear( self ):
|
def Clear( self ):
|
||||||
for category, tab_buffer in self._buffers.items():
|
for category, tab_buffer in self._buffers.items():
|
||||||
if tab_buffer.is_job:
|
if tab_buffer.is_job:
|
||||||
utils.CleanUpCommand( category )
|
utils.CleanUpCommand( category, self._api_prefix )
|
||||||
try:
|
try:
|
||||||
vim.command( 'bdelete! {0}'.format( tab_buffer.buf.number ) )
|
vim.command( 'bdelete! {0}'.format( tab_buffer.buf.number ) )
|
||||||
except vim.error as e:
|
except vim.error as e:
|
||||||
|
|
@ -161,7 +162,7 @@ class OutputView( object ):
|
||||||
cmd = [ 'tail', '-F', '-n', '+1', '--', file_name ]
|
cmd = [ 'tail', '-F', '-n', '+1', '--', file_name ]
|
||||||
|
|
||||||
if cmd is not None:
|
if cmd is not None:
|
||||||
out, err = utils.SetUpCommandBuffer( cmd, category )
|
out, err = utils.SetUpCommandBuffer( cmd, category, self._api_prefix )
|
||||||
self._buffers[ category + '-out' ] = TabBuffer( out,
|
self._buffers[ category + '-out' ] = TabBuffer( out,
|
||||||
len( self._buffers ) )
|
len( self._buffers ) )
|
||||||
self._buffers[ category + '-out' ].is_job = True
|
self._buffers[ category + '-out' ].is_job = True
|
||||||
|
|
|
||||||
|
|
@ -56,9 +56,10 @@ def OpenFileInCurrentWindow( file_name ):
|
||||||
return vim.buffers[ buffer_number ]
|
return vim.buffers[ buffer_number ]
|
||||||
|
|
||||||
|
|
||||||
def SetUpCommandBuffer( cmd, name ):
|
def SetUpCommandBuffer( cmd, name, api_prefix ):
|
||||||
bufs = vim.eval(
|
bufs = vim.eval(
|
||||||
'vimspector#internal#job#StartCommandWithLog( {}, "{}" )'.format(
|
'vimspector#internal#{}job#StartCommandWithLog( {}, "{}" )'.format(
|
||||||
|
api_prefix,
|
||||||
json.dumps( cmd ),
|
json.dumps( cmd ),
|
||||||
name ) )
|
name ) )
|
||||||
|
|
||||||
|
|
@ -72,8 +73,9 @@ def SetUpCommandBuffer( cmd, name ):
|
||||||
return [ vim.buffers[ int( b ) ] for b in bufs ]
|
return [ vim.buffers[ int( b ) ] for b in bufs ]
|
||||||
|
|
||||||
|
|
||||||
def CleanUpCommand( name ):
|
def CleanUpCommand( name, api_prefix ):
|
||||||
return vim.eval( 'vimspector#internal#job#CleanUpCommand( "{}" )'.format(
|
return vim.eval( 'vimspector#internal#{}job#CleanUpCommand( "{}" )'.format(
|
||||||
|
api_prefix,
|
||||||
name ) )
|
name ) )
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue