on master help sign in
Only auto-format for certain languages
278361aBlaž Hrastnik
helix-core/src/syntax.rs+2−2
@@ -28,8 +28,8 @@ pub struct LanguageConfiguration {
28 pub file_types: Vec<String>, // filename ends_with? <Gemfile, rb, etc>
28 pub file_types: Vec<String>, // filename ends_with? <Gemfile, rb, etc>
29 pub roots: Vec<String>, // these indicate project roots <.git, Cargo.toml>
29 pub roots: Vec<String>, // these indicate project roots <.git, Cargo.toml>
30
30
31− // pub path: PathBuf,
31+ #[serde(default)]
32− // root_path for tree-sitter (^)
32+ pub auto_format: bool,
33
33
34 // content_regex
34 // content_regex
35 // injection_regex
35 // injection_regex
helix-term/src/commands.rs+7−1
@@ -966,7 +966,13 @@ mod cmd {
966 editor.set_error("cannot write a buffer without a filename".to_string());
966 editor.set_error("cannot write a buffer without a filename".to_string());
967 return;
967 return;
968 }
968 }
969+ let autofmt = doc
970+ .language_config()
971+ .map(|config| config.auto_format)
972+ .unwrap_or_default();
973+ if autofmt {
969− doc.format(view.id); // TODO: merge into save
974+ doc.format(view.id); // TODO: merge into save
975+ }
970 tokio::spawn(doc.save());
976 tokio::spawn(doc.save());
971 }
977 }
972
978
languages.toml+2
@@ -4,6 +4,7 @@ scope = "source.rust"
4injection-regex = "rust"
4injection-regex = "rust"
5file-types = ["rs"]
5file-types = ["rs"]
6roots = []
6roots = []
7+auto-format = true
7
8
8language-server = { command = "rust-analyzer" }
9language-server = { command = "rust-analyzer" }
9indent = { tab-width = 4, unit = " " }
10indent = { tab-width = 4, unit = " " }
@@ -61,6 +62,7 @@ scope = "source.go"
61injection-regex = "go"
62injection-regex = "go"
62file-types = ["go"]
63file-types = ["go"]
63roots = ["Gopkg.toml", "go.mod"]
64roots = ["Gopkg.toml", "go.mod"]
65+auto-format = true
64
66
65language-server = { command = "gopls" }
67language-server = { command = "gopls" }
66# TODO: gopls needs utf-8 offsets?
68# TODO: gopls needs utf-8 offsets?