Merge pull request #229 from puremourning/variables-coerce-type

Ability to coerce types in the vimspector config
This commit is contained in:
mergify[bot] 2020-08-13 14:04:35 +00:00 • committed by GitHub
commit 9a9d43cb82
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 4 deletions

View file

@ -24,6 +24,7 @@ import subprocess
import shlex import shlex
import collections import collections
import re import re
import typing
LOG_FILE = os.path.expanduser( os.path.join( '~', '.vimspector.log' ) ) LOG_FILE = os.path.expanduser( os.path.join( '~', '.vimspector.log' ) )
@ -540,14 +541,31 @@ def ExpandReferencesInString( orig_s,
return s return s
def CoerceType( mapping: typing.Dict[ str, typing.Any ], key: str ):
DICT_TYPES = {
'json': json.loads,
's': str
}
parts = key.split( '#' )
if len( parts ) > 1 and parts[ -1 ] in DICT_TYPES.keys():
value = mapping.pop( key )
new_type = parts[ -1 ]
key = '#'.join( parts[ 0 : -1 ] )
mapping[ key ] = DICT_TYPES[ new_type ]( value )
# TODO: Should we just run the substitution on the whole JSON string instead? # TODO: Should we just run the substitution on the whole JSON string instead?
# That woul dallow expansion in bool and number values, such as ports etc. ? # That woul dallow expansion in bool and number values, such as ports etc. ?
def ExpandReferencesInDict( obj, mapping, calculus, user_choices ): def ExpandReferencesInDict( obj, mapping, calculus, user_choices ):
for k in obj.keys(): for k in list( obj.keys() ):
obj[ k ] = ExpandReferencesInObject( obj[ k ], obj[ k ] = ExpandReferencesInObject( obj[ k ],
mapping, mapping,
calculus, calculus,
user_choices ) user_choices )
CoerceType( obj, k )
def ParseVariables( variables_list, def ParseVariables( variables_list,
@ -560,9 +578,10 @@ def ParseVariables( variables_list,
if not isinstance( variables_list, list ): if not isinstance( variables_list, list ):
variables_list = [ variables_list ] variables_list = [ variables_list ]
variables: typing.Dict[ str, typing.Any ]
for variables in variables_list: for variables in variables_list:
new_mapping.update( new_variables ) new_mapping.update( new_variables )
for n, v in variables.items(): for n, v in list( variables.items() ):
if isinstance( v, dict ): if isinstance( v, dict ):
if 'shell' in v: if 'shell' in v:
new_v = v.copy() new_v = v.copy()
@ -597,6 +616,8 @@ def ParseVariables( variables_list,
calculus, calculus,
user_choices ) user_choices )
CoerceType( new_variables, n )
return new_variables return new_variables

View file

@ -57,8 +57,11 @@
"type": "python", "type": "python",
"cwd": "${workspaceRoot}", "cwd": "${workspaceRoot}",
"program": "${program:${file\\}}", "program": "${program:${file\\}}",
"stopOnEntry": false, "stopOnEntry#json": "${StopOnEntry:true}",
"console": "integratedTerminal" "console": "integratedTerminal",
"args#json": "${args:[]}",
"env#json": "${env:{\\}}",
"igored#json#s": "string not json"
}, },
"breakpoints": { "breakpoints": {
"exception": { "exception": {