From 1905556edd00ca78a723c4d8ad45fc9d9e02db39 Mon Sep 17 00:00:00 2001 From: Ben Jackson Date: Sat, 2 Feb 2019 10:25:14 +0000 Subject: [PATCH] Allow mappings to specify variables --- autoload/vimspector.vim | 5 ++++- python3/vimspector/debug_session.py | 26 ++++++++++++-------------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/autoload/vimspector.vim b/autoload/vimspector.vim index 036e55e..44b8ea0 100644 --- a/autoload/vimspector.vim +++ b/autoload/vimspector.vim @@ -22,11 +22,14 @@ set cpo&vim call vimspector#internal#state#Reset() -" TODO: Test function function! vimspector#Launch() abort py3 _vimspector_session.Start() endfunction +function! vimspector#LaunchWithSettings( settings ) abort + py3 _vimspector_session.Start( launch_variables = vim.eval( 'a:settings' ) ) +endfunction + function! vimspector#Reset() abort py3 _vimspector_session.Reset() endfunction diff --git a/python3/vimspector/debug_session.py b/python3/vimspector/debug_session.py index 312de93..f2f3c70 100644 --- a/python3/vimspector/debug_session.py +++ b/python3/vimspector/debug_session.py @@ -106,7 +106,7 @@ class DebugSession( object ): # have a UI list of them we should update that at this point self._UpdateUIBreakpoints() - def Start( self, configuration = None ): + def Start( self, launch_variables = {} ): self._configuration = None self._adapter = None @@ -123,29 +123,27 @@ class DebugSession( object ): launch_config = database.get( 'configurations' ) adapters = database.get( 'adapters' ) - if not configuration: - if len( launch_config ) == 1: - configuration = next( iter( launch_config.keys() ) ) - else: - configuration = utils.SelectFromList( 'Which launch configuration?', - list( launch_config.keys() ) ) - + if len( launch_config ) == 1: + configuration = next( iter( launch_config.keys() ) ) + else: + configuration = utils.SelectFromList( 'Which launch configuration?', + list( launch_config.keys() ) ) if not configuration: return self._workspace_root = os.path.dirname( launch_config_file ) - utils.ExpandReferencesInDict( launch_config[ configuration ], { + variables = { + 'dollar': '$', # HAAACK: work around not having a way to include a literal 'workspaceRoot': self._workspace_root - } ) + } + variables.update( launch_variables ) + utils.ExpandReferencesInDict( launch_config[ configuration ], variables ) adapter = launch_config[ configuration ].get( 'adapter' ) if isinstance( adapter, str ): adapter = adapters.get( adapter ) - utils.ExpandReferencesInDict( adapter, { - 'workspaceRoot': os.path.dirname( launch_config_file ) - } ) - + utils.ExpandReferencesInDict( adapter, variables ) self._StartWithConfiguration( launch_config[ configuration ], adapter )