diff options
author | Blaž Hrastnik | 2021-06-12 01:20:37 +0000 |
---|---|---|
committer | Blaž Hrastnik | 2021-06-12 01:20:37 +0000 |
commit | 278361a08627240e47503e21a88b81a40f4a1caf (patch) | |
tree | 28b9f3053f68da2f8c0331ce123ed72c212bf9e3 | |
parent | 69fe46a122f728b4bb6cb218fd410544097b0dcd (diff) |
Only auto-format for certain languages
Fixes #53
Fixes #207
-rw-r--r-- | helix-core/src/syntax.rs | 4 | ||||
-rw-r--r-- | helix-term/src/commands.rs | 8 | ||||
-rw-r--r-- | 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 ec21719b..5c4c95b9 100644 --- a/helix-core/src/syntax.rs +++ b/helix-core/src/syntax.rs @@ -28,8 +28,8 @@ pub struct LanguageConfiguration { pub file_types: Vec<String>, // filename ends_with? <Gemfile, rb, etc> pub roots: Vec<String>, // 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 3cb1288e..edc3dcfd 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 93cd653e..b93bcb8b 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? |