on master help sign in
Only auto-format for certain languages

Fixes #53 Fixes #207

commit278361a08627240e47503e21a88b81a40f4a1caf authorBlaž Hrastnik <blaz@mxxn.io> dateSat 12 Jun 2021, 10:20 (5 years ago) parent69fe46a
3 files changed+11−3
helix-core/src/syntax.rs+2−2 helix-term/src/commands.rs+7−1 languages.toml+2
helix-core/src/syntax.rs+2−2
@@ -28,8 +28,8 @@ pub struct LanguageConfiguration {
2828 pub file_types: Vec<String>, // filename ends_with? <Gemfile, rb, etc>
2929 pub roots: Vec<String>, // these indicate project roots <.git, Cargo.toml>
3030
31− // pub path: PathBuf,
32− // root_path for tree-sitter (^)
31+ #[serde(default)]
32+ pub auto_format: bool,
3333
3434 // content_regex
3535 // injection_regex
helix-term/src/commands.rs+7−1
@@ -966,7 +966,13 @@ mod cmd {
966966 editor.set_error("cannot write a buffer without a filename".to_string());
967967 return;
968968 }
969− doc.format(view.id); // TODO: merge into save
969+ let autofmt = doc
970+ .language_config()
971+ .map(|config| config.auto_format)
972+ .unwrap_or_default();
973+ if autofmt {
974+ doc.format(view.id); // TODO: merge into save
975+ }
970976 tokio::spawn(doc.save());
971977 }
972978
languages.toml+2
@@ -4,6 +4,7 @@ scope = "source.rust"
44injection-regex = "rust"
55file-types = ["rs"]
66roots = []
7+auto-format = true
78
89language-server = { command = "rust-analyzer" }
910indent = { tab-width = 4, unit = " " }
@@ -61,6 +62,7 @@ scope = "source.go"
6162injection-regex = "go"
6263file-types = ["go"]
6364roots = ["Gopkg.toml", "go.mod"]
65+auto-format = true
6466
6567language-server = { command = "gopls" }
6668# TODO: gopls needs utf-8 offsets?