Allow for variable expansion in configuration
We expand environment variables, ~ and workspaceRoot. The latter is to match vscode and typical launch configs. As we don't know what the workspeace root might be, we use the location of the .vimspector.json.
This commit is contained in:
parent
3f9bc6f921
commit
79b25c0860
2 changed files with 32 additions and 0 deletions
|
|
@ -133,9 +133,17 @@ class DebugSession( object ):
|
|||
if not configuration:
|
||||
return
|
||||
|
||||
utils.ExpandReferencesInDict( launch_config[ configuration ], {
|
||||
'workspaceRoot': os.path.dirname( launch_config_file )
|
||||
} )
|
||||
|
||||
adapter = launch_config[ configuration ].get( 'adapter' )
|
||||
if isinstance( adapter, str ):
|
||||
adapter = adapters.get( adapter )
|
||||
utils.ExpandReferencesInDict( adapter, {
|
||||
'workspaceRoot': os.path.dirname( launch_config_file )
|
||||
} )
|
||||
|
||||
|
||||
self._StartWithConfiguration( launch_config[ configuration ],
|
||||
adapter )
|
||||
|
|
@ -144,6 +152,11 @@ class DebugSession( object ):
|
|||
self._configuration = configuration
|
||||
self._adapter = adapter
|
||||
|
||||
self._logger.info( 'Configuration: {0}'.format( json.dumps(
|
||||
self._configuration ) ) )
|
||||
self._logger.info( 'Adapter: {0}'.format( json.dumps(
|
||||
self._adapter ) ) )
|
||||
|
||||
def start():
|
||||
self._StartDebugAdapter()
|
||||
self._Initialise()
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ import os
|
|||
import contextlib
|
||||
import vim
|
||||
import json
|
||||
import string
|
||||
|
||||
_log_handler = logging.FileHandler( os.path.expanduser( '~/.vimspector.log' ) )
|
||||
_log_handler.setFormatter(
|
||||
|
|
@ -222,3 +223,21 @@ def ClearBuffer( buf ):
|
|||
|
||||
def IsCurrent( window, buf ):
|
||||
return vim.current.window == window and vim.current.window.buffer == buf
|
||||
|
||||
|
||||
def ExpandReferencesInDict( obj, mapping, **kwargs ):
|
||||
def expand_refs( s ):
|
||||
UserMessage( type( s ), persist=True )
|
||||
s = string.Template( s ).safe_substitute( mapping, **kwargs )
|
||||
s = os.path.expanduser( s )
|
||||
s = os.path.expandvars( s )
|
||||
return s
|
||||
|
||||
for k in obj.keys():
|
||||
if isinstance( obj[ k ], dict ):
|
||||
ExpandReferencesInDict( obj[ k ], mapping, **kwargs )
|
||||
elif isinstance( obj[ k ], list ):
|
||||
for i, _ in enumerate( obj[ k ] ):
|
||||
obj[ k ][ i ] = expand_refs( obj[ k ][ i ] )
|
||||
elif isinstance( obj[ k ], str ):
|
||||
obj[ k ] = expand_refs( obj[ k ] )
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue