Auto merge of #13980 - Veykril:checkOnSaveConfigPatch, r=Veykril

Fix checkOnSave to check config patching not always working

This early return was missed in the initial PR, so if we aren't patching the `completion_addCallArgumentSnippets` `completion_addCallParenthesis` configs we won't be patching the checkOnSave ones...
This commit is contained in:
bors 2023-01-18 19:31:21 +00:00
commit 760f2ff58d

View File

@ -114,6 +114,7 @@ pub(super) fn patch_json_for_outdated_configs(json: &mut Value) {
} }
// completion_addCallArgumentSnippets completion_addCallParenthesis -> completion_callable_snippets // completion_addCallArgumentSnippets completion_addCallParenthesis -> completion_callable_snippets
'completion: {
let res = match ( let res = match (
copy.pointer("/completion/addCallArgumentSnippets"), copy.pointer("/completion/addCallArgumentSnippets"),
copy.pointer("/completion/addCallParenthesis"), copy.pointer("/completion/addCallParenthesis"),
@ -121,9 +122,10 @@ pub(super) fn patch_json_for_outdated_configs(json: &mut Value) {
(Some(Value::Bool(true)), Some(Value::Bool(true))) => json!("fill_arguments"), (Some(Value::Bool(true)), Some(Value::Bool(true))) => json!("fill_arguments"),
(_, Some(Value::Bool(true))) => json!("add_parentheses"), (_, Some(Value::Bool(true))) => json!("add_parentheses"),
(Some(Value::Bool(false)), Some(Value::Bool(false))) => json!("none"), (Some(Value::Bool(false)), Some(Value::Bool(false))) => json!("none"),
(_, _) => return, (_, _) => break 'completion,
}; };
merge(json, json!({ "completion": { "callable": {"snippets": res }} })); merge(json, json!({ "completion": { "callable": {"snippets": res }} }));
}
// We need to do this due to the checkOnSave_enable -> checkOnSave change, as that key now can either be an object or a bool // We need to do this due to the checkOnSave_enable -> checkOnSave change, as that key now can either be an object or a bool
// checkOnSave_* -> check_* // checkOnSave_* -> check_*
@ -146,3 +148,23 @@ fn merge(dst: &mut Value, src: Value) {
(dst, src) => *dst = src, (dst, src) => *dst = src,
} }
} }
#[test]
fn check_on_save_patching() {
let mut json = json!({ "checkOnSave": { "overrideCommand": "foo" }});
patch_json_for_outdated_configs(&mut json);
assert_eq!(
json,
json!({ "checkOnSave": { "overrideCommand": "foo" }, "check": { "overrideCommand": "foo" }})
);
}
#[test]
fn check_on_save_patching_enable() {
let mut json = json!({ "checkOnSave": { "enable": true, "overrideCommand": "foo" }});
patch_json_for_outdated_configs(&mut json);
assert_eq!(
json,
json!({ "checkOnSave": true, "check": { "enable": true, "overrideCommand": "foo" }})
);
}