From 278361a08627240e47503e21a88b81a40f4a1caf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bla=C5=BE=20Hrastnik?= Date: Sat, 12 Jun 2021 10:20:37 +0900 Subject: [PATCH] Only auto-format for certain languages Fixes #53 Fixes #207 --- helix-core/src/syntax.rs | 4 ++-- helix-term/src/commands.rs | 8 +++++++- languages.toml | 2 ++ 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/helix-core/src/syntax.rs b/helix-core/src/syntax.rs index ec21719b9..5c4c95b97 100644 --- a/helix-core/src/syntax.rs +++ b/helix-core/src/syntax.rs @@ -28,8 +28,8 @@ pub struct LanguageConfiguration { pub file_types: Vec, // filename ends_with? pub roots: Vec, // these indicate project roots <.git, Cargo.toml> - // pub path: PathBuf, - // root_path for tree-sitter (^) + #[serde(default)] + pub auto_format: bool, // content_regex // injection_regex diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 3cb1288ec..edc3dcfdc 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -966,7 +966,13 @@ mod cmd { editor.set_error("cannot write a buffer without a filename".to_string()); return; } - doc.format(view.id); // TODO: merge into save + let autofmt = doc + .language_config() + .map(|config| config.auto_format) + .unwrap_or_default(); + if autofmt { + doc.format(view.id); // TODO: merge into save + } tokio::spawn(doc.save()); } diff --git a/languages.toml b/languages.toml index 93cd653e7..b93bcb8b6 100644 --- a/languages.toml +++ b/languages.toml @@ -4,6 +4,7 @@ scope = "source.rust" injection-regex = "rust" file-types = ["rs"] roots = [] +auto-format = true language-server = { command = "rust-analyzer" } indent = { tab-width = 4, unit = " " } @@ -61,6 +62,7 @@ scope = "source.go" injection-regex = "go" file-types = ["go"] roots = ["Gopkg.toml", "go.mod"] +auto-format = true language-server = { command = "gopls" } # TODO: gopls needs utf-8 offsets?