settings: Make "auto" and "language_server" valid format steps (#40113)

Follow up for: #39983 and
https://github.com/zed-industries/zed/pull/40040#issuecomment-3393902691

Previously it was possible to have formatting done using prettier or
language server using `"formatter": "auto"` and specify code actions to
apply on format using the `"code_actions_on_format"` setting. However,
post #39983 this is no longer possible due to the removal of the
`"code_actions_on_format"` setting. To rectify this regression, this PR
makes it so that the `"auto"` and `"language_server"` strings that were
previously only allowed as top level values on the `"formatter"` key,
are now allowed as format steps like so:
```json
{
      "formatter": ["auto", "language_server"]
}
```

Therefore to replicate the previous behavior using `"auto"` and
`"code_actions_on_format"` you can use the following configuration:

```json
{
      "formatter": [{"code_action": ...}, "auto"]
}
```

Release Notes:

- N/A *or* Added/Fixed/Improved ...
This commit is contained in:
Ben Kunkle
2025-10-13 12:56:40 -04:00
committed by GitHub
parent 8dfbafd345
commit 997f6c6a19
10 changed files with 183 additions and 191 deletions
+11 -14
View File
@@ -27,7 +27,6 @@ use language::{
LanguageConfigOverride, LanguageMatcher, LanguageName, Override, Point,
language_settings::{
CompletionSettingsContent, FormatterList, LanguageSettingsContent, LspInsertMode,
SelectedFormatter,
},
tree_sitter_python,
};
@@ -11908,8 +11907,8 @@ async fn test_range_format_respects_language_tab_size_override(cx: &mut TestAppC
#[gpui::test]
async fn test_document_format_manual_trigger(cx: &mut TestAppContext) {
init_test(cx, |settings| {
settings.defaults.formatter = Some(SelectedFormatter::List(FormatterList::Single(
Formatter::LanguageServer { name: None },
settings.defaults.formatter = Some(FormatterList::Single(Formatter::LanguageServer(
settings::LanguageServerFormatterSpecifier::Current,
)))
});
@@ -12034,11 +12033,11 @@ async fn test_document_format_manual_trigger(cx: &mut TestAppContext) {
async fn test_multiple_formatters(cx: &mut TestAppContext) {
init_test(cx, |settings| {
settings.defaults.remove_trailing_whitespace_on_save = Some(true);
settings.defaults.formatter = Some(SelectedFormatter::List(FormatterList::Vec(vec![
Formatter::LanguageServer { name: None },
settings.defaults.formatter = Some(FormatterList::Vec(vec![
Formatter::LanguageServer(settings::LanguageServerFormatterSpecifier::Current),
Formatter::CodeAction("code-action-1".into()),
Formatter::CodeAction("code-action-2".into()),
])))
]))
});
let fs = FakeFs::new(cx.executor());
@@ -12293,9 +12292,9 @@ async fn test_multiple_formatters(cx: &mut TestAppContext) {
#[gpui::test]
async fn test_organize_imports_manual_trigger(cx: &mut TestAppContext) {
init_test(cx, |settings| {
settings.defaults.formatter = Some(SelectedFormatter::List(FormatterList::Vec(vec![
Formatter::LanguageServer { name: None },
])))
settings.defaults.formatter = Some(FormatterList::Vec(vec![Formatter::LanguageServer(
settings::LanguageServerFormatterSpecifier::Current,
)]))
});
let fs = FakeFs::new(cx.executor());
@@ -12498,7 +12497,7 @@ async fn test_concurrent_format_requests(cx: &mut TestAppContext) {
#[gpui::test]
async fn test_strip_whitespace_and_format_via_lsp(cx: &mut TestAppContext) {
init_test(cx, |settings| {
settings.defaults.formatter = Some(SelectedFormatter::Auto)
settings.defaults.formatter = Some(FormatterList::default())
});
let mut cx = EditorLspTestContext::new_rust(
@@ -18187,9 +18186,7 @@ fn completion_menu_entries(menu: &CompletionsMenu) -> Vec<String> {
#[gpui::test]
async fn test_document_format_with_prettier(cx: &mut TestAppContext) {
init_test(cx, |settings| {
settings.defaults.formatter = Some(SelectedFormatter::List(FormatterList::Single(
Formatter::Prettier,
)))
settings.defaults.formatter = Some(FormatterList::Single(Formatter::Prettier))
});
let fs = FakeFs::new(cx.executor());
@@ -18256,7 +18253,7 @@ async fn test_document_format_with_prettier(cx: &mut TestAppContext) {
);
update_test_language_settings(cx, |settings| {
settings.defaults.formatter = Some(SelectedFormatter::Auto)
settings.defaults.formatter = Some(FormatterList::default())
});
let format = editor.update_in(cx, |editor, window, cx| {
editor.perform_format(