Only auto-format for certain languages

Fixes #53
Fixes #207
This commit is contained in:
Blaž Hrastnik 2021-06-12 10:20:37 +09:00
parent 69fe46a122
commit 278361a086
3 changed files with 11 additions and 3 deletions

View File

@ -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

View File

@ -966,7 +966,13 @@ fn write(editor: &mut Editor, args: &[&str], event: PromptEvent) {
editor.set_error("cannot write a buffer without a filename".to_string());
return;
}
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());
}

View File

@ -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?