Skip to content

Commit fe00b6c

Browse files
probably-nebcole-millermikayla-makiHactarCE
committed
Revert deprecate code actions on format (#40409)
Closes #40334 This reverts the change made in #39983, and includes a replacement migration that will transform formatter settings values consisting of only `code_action` format steps into the previously deprecated `code_actions_on_format` in an attempt to restore the behavior to what it was before the migration that deprecated `code_actions_on_format`. This PR will result in a modified order in the `code_actions_on_format` setting if it existed, however the decision was made to explicitly ignore this for now, as this PR is primarily targeting users who have already had the deprecation migration run, and no longer have the `code_actions_on_format` key Release Notes: - Fixed an issue with a settings migration that deprecated the `code_actions_on_format` setting. The `code_actions_on_format` setting has been un-deprecated, and affected users will have the bad migration rolled back with an updated migration --------- Co-authored-by: Cole Miller <cole@zed.dev> Co-authored-by: Mikayla Maki <mikayla.c.maki@gmail.com> Co-authored-by: HactarCE <6060305+HactarCE@users.noreply.github.com>
1 parent 70d1978 commit fe00b6c

File tree

12 files changed

+216
-326
lines changed

12 files changed

+216
-326
lines changed

assets/settings/default.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1527,6 +1527,7 @@
15271527
// A value of 45 preserves colorful themes while ensuring legibility.
15281528
"minimum_contrast": 45
15291529
},
1530+
"code_actions_on_format": {},
15301531
// Settings related to running tasks.
15311532
"tasks": {
15321533
"variables": {},
@@ -1696,7 +1697,9 @@
16961697
"preferred_line_length": 72
16971698
},
16981699
"Go": {
1699-
"formatter": [{ "code_action": "source.organizeImports" }, "language_server"],
1700+
"code_actions_on_format": {
1701+
"source.organizeImports": true
1702+
},
17001703
"debuggers": ["Delve"]
17011704
},
17021705
"GraphQL": {

crates/language/src/language_settings.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@ pub struct LanguageSettings {
142142
pub auto_indent_on_paste: bool,
143143
/// Controls how the editor handles the autoclosed characters.
144144
pub always_treat_brackets_as_autoclosed: bool,
145+
/// Which code actions to run on save
146+
pub code_actions_on_format: HashMap<String, bool>,
145147
/// Whether to perform linked edits
146148
pub linked_edits: bool,
147149
/// Task configuration for this language.
@@ -576,6 +578,7 @@ impl settings::Settings for AllLanguageSettings {
576578
always_treat_brackets_as_autoclosed: settings
577579
.always_treat_brackets_as_autoclosed
578580
.unwrap(),
581+
code_actions_on_format: settings.code_actions_on_format.unwrap(),
579582
linked_edits: settings.linked_edits.unwrap(),
580583
tasks: LanguageTaskSettings {
581584
variables: tasks.variables.unwrap_or_default(),

crates/migrator/src/migrations.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ pub(crate) mod m_2025_10_03 {
118118
pub(crate) use settings::SETTINGS_PATTERNS;
119119
}
120120

121-
pub(crate) mod m_2025_10_10 {
121+
pub(crate) mod m_2025_10_16 {
122122
mod settings;
123123

124-
pub(crate) use settings::remove_code_actions_on_format;
124+
pub(crate) use settings::restore_code_actions_on_format;
125125
}

crates/migrator/src/migrations/m_2025_10_10/settings.rs

Lines changed: 0 additions & 70 deletions
This file was deleted.
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
use anyhow::Result;
2+
use serde_json::Value;
3+
4+
use crate::patterns::migrate_language_setting;
5+
6+
pub fn restore_code_actions_on_format(value: &mut Value) -> Result<()> {
7+
migrate_language_setting(value, restore_code_actions_on_format_inner)
8+
}
9+
10+
fn restore_code_actions_on_format_inner(value: &mut Value, path: &[&str]) -> Result<()> {
11+
let Some(obj) = value.as_object_mut() else {
12+
return Ok(());
13+
};
14+
let code_actions_on_format = obj
15+
.get("code_actions_on_format")
16+
.cloned()
17+
.unwrap_or_else(|| Value::Object(Default::default()));
18+
19+
fn fmt_path(path: &[&str], key: &str) -> String {
20+
let mut path = path.to_vec();
21+
path.push(key);
22+
path.join(".")
23+
}
24+
25+
let Some(mut code_actions_map) = code_actions_on_format.as_object().cloned() else {
26+
anyhow::bail!(
27+
r#"The `code_actions_on_format` is in an invalid state and cannot be migrated at {}. Please ensure the code_actions_on_format setting is a Map<String, bool>"#,
28+
fmt_path(path, "code_actions_on_format"),
29+
);
30+
};
31+
32+
let Some(formatter) = obj.get("formatter") else {
33+
return Ok(());
34+
};
35+
let formatter_array = if let Some(array) = formatter.as_array() {
36+
array.clone()
37+
} else {
38+
vec![formatter.clone()]
39+
};
40+
let mut code_action_formatters = Vec::new();
41+
for formatter in formatter_array {
42+
let Some(code_action) = formatter.get("code_action") else {
43+
return Ok(());
44+
};
45+
let Some(code_action_name) = code_action.as_str() else {
46+
anyhow::bail!(
47+
r#"The `code_action` is in an invalid state and cannot be migrated at {}. Please ensure the code_action setting is a String"#,
48+
fmt_path(path, "formatter"),
49+
);
50+
};
51+
code_action_formatters.push(code_action_name.to_string());
52+
}
53+
54+
code_actions_map.extend(
55+
code_action_formatters
56+
.into_iter()
57+
.rev()
58+
.map(|code_action| (code_action, Value::Bool(true))),
59+
);
60+
61+
obj.remove("formatter");
62+
obj.insert(
63+
"code_actions_on_format".into(),
64+
Value::Object(code_actions_map),
65+
);
66+
67+
Ok(())
68+
}

0 commit comments

Comments
 (0)