diff --git a/crates/project/src/lsp_store.rs b/crates/project/src/lsp_store.rs index 4673bc1df19b72a60be7197af9ae364acd0933c2..5709256984c3232a317427b25cf857cad9f9791d 100644 --- a/crates/project/src/lsp_store.rs +++ b/crates/project/src/lsp_store.rs @@ -1703,6 +1703,10 @@ impl LocalLspStore { formatter }; match formatter { + Formatter::None => { + zlog::trace!(logger => "skipping formatter 'none'"); + continue; + } Formatter::Auto => unreachable!("Auto resolved above"), Formatter::Prettier => { let logger = zlog::scoped!(logger => "prettier"); diff --git a/crates/settings_content/src/language.rs b/crates/settings_content/src/language.rs index fba636ee28be121a15da4b3d50046c53c0bdd5b3..30a1e7a3179988071784e94a8a9b8b60b13df468 100644 --- a/crates/settings_content/src/language.rs +++ b/crates/settings_content/src/language.rs @@ -955,6 +955,8 @@ pub enum Formatter { /// or falling back to formatting via language server. #[default] Auto, + /// Do not format code. + None, /// Format code using Zed's Prettier integration. Prettier, /// Format code using an external command. @@ -1148,6 +1150,12 @@ mod test { settings.formatter, Some(FormatterList::Single(Formatter::Auto)) ); + let raw_none = "{\"formatter\": \"none\"}"; + let settings: LanguageSettingsContent = serde_json::from_str(raw_none).unwrap(); + assert_eq!( + settings.formatter, + Some(FormatterList::Single(Formatter::None)) + ); let raw = "{\"formatter\": \"language_server\"}"; let settings: LanguageSettingsContent = serde_json::from_str(raw).unwrap(); assert_eq!( diff --git a/docs/src/reference/all-settings.md b/docs/src/reference/all-settings.md index 7248a5636a29339ec2ca93481cfa4056b2527d30..4af2d70de71b6372f68931826e0192ff5f218602 100644 --- a/docs/src/reference/all-settings.md +++ b/docs/src/reference/all-settings.md @@ -1908,6 +1908,14 @@ WARNING: `{buffer_path}` should not be used to direct your formatter to read fro Here `rust-analyzer` will be used first to format the code, followed by a call of sed. If any of the formatters fails, the subsequent ones will still be executed. +6. To disable the formatter, use `"none"`. This setting disables the configured formatter, but any actions in `code_actions_on_format` will still be executed: + +```json [settings] +{ + "formatter": "none" +} +``` + ## Auto close - Description: Whether to automatically add matching closing characters when typing opening parenthesis, bracket, brace, single or double quote characters.