FixUp: make sure that we copy templates rather than end up updating them
This commit is contained in:
parent
2fa6142c8f
commit
7e55563c8f
2 changed files with 15 additions and 11 deletions
|
|
@ -18,6 +18,7 @@ import logging
|
||||||
import json
|
import json
|
||||||
import glob
|
import glob
|
||||||
import shlex
|
import shlex
|
||||||
|
import copy
|
||||||
|
|
||||||
from vimspector import install, installer, utils, gadgets
|
from vimspector import install, installer, utils, gadgets
|
||||||
from vimspector.vendor.json_minify import minify
|
from vimspector.vendor.json_minify import minify
|
||||||
|
|
@ -132,7 +133,10 @@ def SuggestConfiguration( current_file, filetypes ):
|
||||||
|
|
||||||
for template in spec.get( 'templates', [] ):
|
for template in spec.get( 'templates', [] ):
|
||||||
if filetypes.intersection( template.get( 'filetypes', set() ) ):
|
if filetypes.intersection( template.get( 'filetypes', set() ) ):
|
||||||
templates.append( template )
|
# We _must_ copy the template as we end up taking bits out of it to
|
||||||
|
# assign to the resulting config. Python... references... mutabiliy..
|
||||||
|
# fun.
|
||||||
|
templates.append( copy.deepcopy( template ) )
|
||||||
|
|
||||||
if not templates:
|
if not templates:
|
||||||
return nothing
|
return nothing
|
||||||
|
|
@ -188,11 +192,14 @@ def SaveConfiguration( configuration ):
|
||||||
current_contents = {}
|
current_contents = {}
|
||||||
|
|
||||||
if os.path.exists( config_path ):
|
if os.path.exists( config_path ):
|
||||||
if utils.Confirm( 'File exists, overwrite?\n(NOTE: comments and '
|
if utils.Confirm( 'File exists, merge with this configuration?\n'
|
||||||
'formatting in the existing file will be LOST!!)',
|
'(NOTE: comments and formatting in the existing file '
|
||||||
'&Yes\n&No' ) == 1:
|
'will be LOST!!)',
|
||||||
with open( config_path, 'r' ) as f:
|
'&Yes\n&No' ) != 1:
|
||||||
current_contents = json.loads( minify( f.read() ) )
|
return
|
||||||
|
|
||||||
|
with open( config_path, 'r' ) as f:
|
||||||
|
current_contents = json.loads( minify( f.read() ) )
|
||||||
|
|
||||||
# TODO: how much of configuration is mangled at this point ?
|
# TODO: how much of configuration is mangled at this point ?
|
||||||
# TODO: how about the defaulted arguments? All the refs are replaced at this
|
# TODO: how about the defaulted arguments? All the refs are replaced at this
|
||||||
|
|
@ -203,7 +210,7 @@ def SaveConfiguration( configuration ):
|
||||||
with open( config_path, 'w' ) as f:
|
with open( config_path, 'w' ) as f:
|
||||||
json.dump( current_contents, f, indent=2 )
|
json.dump( current_contents, f, indent=2 )
|
||||||
|
|
||||||
utils.UserMessage( f'Wrote { config_path }.', persist = True )
|
utils.UserMessage( f'Wrote { config_path }', persist = True )
|
||||||
|
|
||||||
|
|
||||||
def SelectAdapter( api_prefix,
|
def SelectAdapter( api_prefix,
|
||||||
|
|
|
||||||
|
|
@ -536,10 +536,7 @@ def ExpandReferencesInString( orig_s,
|
||||||
|
|
||||||
# Parse any variables passed in in mapping, and ask for any that weren't,
|
# Parse any variables passed in in mapping, and ask for any that weren't,
|
||||||
# storing the result in mapping
|
# storing the result in mapping
|
||||||
bug_catcher = 0
|
while True:
|
||||||
while bug_catcher < 100:
|
|
||||||
++bug_catcher
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
s = _Substitute( s, mapping )
|
s = _Substitute( s, mapping )
|
||||||
break
|
break
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue