Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
editor: Add an option to disable the formatter (#48991)
Xin Zhao4a3f891c2fb0
diff --git a/crates/project/src/lsp_store.rs b/crates/project/src/lsp_store.rsindex 4673bc1df19..5709256984c 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.rsindex fba636ee28b..30a1e7a3179 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.mdindex 7248a5636a2..4af2d70de71 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 froHere `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.