Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 760f2ff

Browse files
committed
Auto merge of rust-lang#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...
2 parents 3a72713 + 1e4a182 commit 760f2ff

File tree

1 file changed

+32
-10
lines changed

1 file changed

+32
-10
lines changed

crates/rust-analyzer/src/config/patch_old_style.rs

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -114,16 +114,18 @@ pub(super) fn patch_json_for_outdated_configs(json: &mut Value) {
114114
}
115115

116116
// completion_addCallArgumentSnippets completion_addCallParenthesis -> completion_callable_snippets
117-
let res = match (
118-
copy.pointer("/completion/addCallArgumentSnippets"),
119-
copy.pointer("/completion/addCallParenthesis"),
120-
) {
121-
(Some(Value::Bool(true)), Some(Value::Bool(true))) => json!("fill_arguments"),
122-
(_, Some(Value::Bool(true))) => json!("add_parentheses"),
123-
(Some(Value::Bool(false)), Some(Value::Bool(false))) => json!("none"),
124-
(_, _) => return,
125-
};
126-
merge(json, json!({ "completion": { "callable": {"snippets": res }} }));
117+
'completion: {
118+
let res = match (
119+
copy.pointer("/completion/addCallArgumentSnippets"),
120+
copy.pointer("/completion/addCallParenthesis"),
121+
) {
122+
(Some(Value::Bool(true)), Some(Value::Bool(true))) => json!("fill_arguments"),
123+
(_, Some(Value::Bool(true))) => json!("add_parentheses"),
124+
(Some(Value::Bool(false)), Some(Value::Bool(false))) => json!("none"),
125+
(_, _) => break 'completion,
126+
};
127+
merge(json, json!({ "completion": { "callable": {"snippets": res }} }));
128+
}
127129

128130
// We need to do this due to the checkOnSave_enable -> checkOnSave change, as that key now can either be an object or a bool
129131
// checkOnSave_* -> check_*
@@ -146,3 +148,23 @@ fn merge(dst: &mut Value, src: Value) {
146148
(dst, src) => *dst = src,
147149
}
148150
}
151+
152+
#[test]
153+
fn check_on_save_patching() {
154+
let mut json = json!({ "checkOnSave": { "overrideCommand": "foo" }});
155+
patch_json_for_outdated_configs(&mut json);
156+
assert_eq!(
157+
json,
158+
json!({ "checkOnSave": { "overrideCommand": "foo" }, "check": { "overrideCommand": "foo" }})
159+
);
160+
}
161+
162+
#[test]
163+
fn check_on_save_patching_enable() {
164+
let mut json = json!({ "checkOnSave": { "enable": true, "overrideCommand": "foo" }});
165+
patch_json_for_outdated_configs(&mut json);
166+
assert_eq!(
167+
json,
168+
json!({ "checkOnSave": true, "check": { "enable": true, "overrideCommand": "foo" }})
169+
);
170+
}

0 commit comments

Comments
 (0)