Skip to content

Commit fe8e7a6

Browse files
probably-nebcole-millermikayla-makiHactarCE
authored andcommitted
Revert deprecate code actions on format (zed-industries#40409)
Closes zed-industries#40334 This reverts the change made in zed-industries#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 <[email protected]> Co-authored-by: Mikayla Maki <[email protected]> Co-authored-by: HactarCE <[email protected]>
1 parent d5679e2 commit fe8e7a6

File tree

10 files changed

+191
-366
lines changed

10 files changed

+191
-366
lines changed

assets/settings/default.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1529,6 +1529,7 @@
15291529
// A value of 45 preserves colorful themes while ensuring legibility.
15301530
"minimum_contrast": 45
15311531
},
1532+
"code_actions_on_format": {},
15321533
// Settings related to running tasks.
15331534
"tasks": {
15341535
"variables": {},
@@ -1698,7 +1699,9 @@
16981699
"preferred_line_length": 72
16991700
},
17001701
"Go": {
1701-
"formatter": [{ "code_action": "source.organizeImports" }, "language_server"],
1702+
"code_actions_on_format": {
1703+
"source.organizeImports": true
1704+
},
17021705
"debuggers": ["Delve"]
17031706
},
17041707
"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 & 61 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)