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
|
|
@ -22,8 +22,9 @@ from vimspector import utils
|
|||
|
||||
|
||||
class CodeView( object ):
|
||||
def __init__( self, window ):
|
||||
def __init__( self, window, api_prefix ):
|
||||
self._window = window
|
||||
self._api_prefix = api_prefix
|
||||
|
||||
self._terminal_window = None
|
||||
self._terminal_buffer_number = None
|
||||
|
|
@ -214,7 +215,8 @@ class CodeView( object ):
|
|||
if self._terminal_window is not None:
|
||||
assert 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 ) ) ):
|
||||
window_for_start = self._terminal_window
|
||||
options[ 'curwin' ] = 1
|
||||
|
|
@ -224,9 +226,11 @@ class CodeView( object ):
|
|||
with utils.TemporaryVimOptions( { 'splitright': True,
|
||||
'equalalways': False } ):
|
||||
with utils.LetCurrentWindow( window_for_start ):
|
||||
buffer_number = int( utils.Call( 'vimspector#internal#term#Start',
|
||||
args,
|
||||
options ) )
|
||||
buffer_number = int(
|
||||
utils.Call(
|
||||
'vimspector#internal#{}term#Start'.format( self._api_prefix ),
|
||||
args,
|
||||
options ) )
|
||||
terminal_window = vim.current.window
|
||||
|
||||
if buffer_number is None or buffer_number <= 0:
|
||||
|
|
|
|||
|
|
@ -41,11 +41,14 @@ USER_CHOICES = {}
|
|||
|
||||
|
||||
class DebugSession( object ):
|
||||
def __init__( self ):
|
||||
def __init__( self, api_prefix ):
|
||||
self._logger = logging.getLogger( __name__ )
|
||||
utils.SetUpLogging( self._logger )
|
||||
|
||||
self._api_prefix = api_prefix
|
||||
|
||||
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( 'gadgetDir = %s',
|
||||
install.GetGadgetDir( VIMSPECTOR_HOME,
|
||||
|
|
@ -405,7 +408,7 @@ class DebugSession( object ):
|
|||
self._uiTab = vim.current.tabpage
|
||||
|
||||
# Code window
|
||||
self._codeView = code.CodeView( vim.current.window )
|
||||
self._codeView = code.CodeView( vim.current.window, self._api_prefix )
|
||||
|
||||
# Call stack
|
||||
with utils.TemporaryVimOptions( { 'splitright': False,
|
||||
|
|
@ -441,7 +444,8 @@ class DebugSession( object ):
|
|||
vim.command( '10spl' )
|
||||
vim.command( 'enew' )
|
||||
self._outputView = output.OutputView( self._connection,
|
||||
vim.current.window )
|
||||
vim.current.window,
|
||||
self._api_prefix )
|
||||
|
||||
def ClearCurrentFrame( self ):
|
||||
self.SetCurrentFrame( None )
|
||||
|
|
@ -482,6 +486,8 @@ class DebugSession( object ):
|
|||
port = utils.AskForInput( 'Enter port to connect to: ' )
|
||||
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?
|
||||
env = os.environ.copy()
|
||||
if 'env' in self._adapter:
|
||||
|
|
@ -795,11 +801,12 @@ class DebugSession( object ):
|
|||
self._logger.debug( 'Defaulting working directory to %s',
|
||||
params[ 'cwd' ] )
|
||||
|
||||
buffer_number = self._codeView.LaunchTerminal( params )
|
||||
term_id = self._codeView.LaunchTerminal( params )
|
||||
|
||||
response = {
|
||||
'processId': int( utils.Call( 'vimspector#internal#term#GetPID',
|
||||
buffer_number ) )
|
||||
'processId': int( utils.Call(
|
||||
'vimspector#internal#{}term#GetPID'.format( self._api_prefix ),
|
||||
term_id ) )
|
||||
}
|
||||
|
||||
self._connection.DoResponse( message, None, response )
|
||||
|
|
|
|||
|
|
@ -40,10 +40,11 @@ def CategoryToBuffer( category ):
|
|||
|
||||
|
||||
class OutputView( object ):
|
||||
def __init__( self, connection, window ):
|
||||
def __init__( self, connection, window, api_prefix ):
|
||||
self._window = window
|
||||
self._connection = connection
|
||||
self._buffers = {}
|
||||
self._api_prefix = api_prefix
|
||||
|
||||
for b in set( BUFFER_MAP.values() ):
|
||||
self._CreateBuffer( b )
|
||||
|
|
@ -95,7 +96,7 @@ class OutputView( object ):
|
|||
def Clear( self ):
|
||||
for category, tab_buffer in self._buffers.items():
|
||||
if tab_buffer.is_job:
|
||||
utils.CleanUpCommand( category )
|
||||
utils.CleanUpCommand( category, self._api_prefix )
|
||||
try:
|
||||
vim.command( 'bdelete! {0}'.format( tab_buffer.buf.number ) )
|
||||
except vim.error as e:
|
||||
|
|
@ -161,7 +162,7 @@ class OutputView( object ):
|
|||
cmd = [ 'tail', '-F', '-n', '+1', '--', file_name ]
|
||||
|
||||
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,
|
||||
len( self._buffers ) )
|
||||
self._buffers[ category + '-out' ].is_job = True
|
||||
|
|
|
|||
|
|
@ -56,9 +56,10 @@ def OpenFileInCurrentWindow( file_name ):
|
|||
return vim.buffers[ buffer_number ]
|
||||
|
||||
|
||||
def SetUpCommandBuffer( cmd, name ):
|
||||
def SetUpCommandBuffer( cmd, name, api_prefix ):
|
||||
bufs = vim.eval(
|
||||
'vimspector#internal#job#StartCommandWithLog( {}, "{}" )'.format(
|
||||
'vimspector#internal#{}job#StartCommandWithLog( {}, "{}" )'.format(
|
||||
api_prefix,
|
||||
json.dumps( cmd ),
|
||||
name ) )
|
||||
|
||||
|
|
@ -72,8 +73,9 @@ def SetUpCommandBuffer( cmd, name ):
|
|||
return [ vim.buffers[ int( b ) ] for b in bufs ]
|
||||
|
||||
|
||||
def CleanUpCommand( name ):
|
||||
return vim.eval( 'vimspector#internal#job#CleanUpCommand( "{}" )'.format(
|
||||
def CleanUpCommand( name, api_prefix ):
|
||||
return vim.eval( 'vimspector#internal#{}job#CleanUpCommand( "{}" )'.format(
|
||||
api_prefix,
|
||||
name ) )
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue