diff options
author | Joe Neeman | 2021-06-30 03:36:33 +0000 |
---|---|---|
committer | Blaž Hrastnik | 2021-06-30 08:08:50 +0000 |
commit | 2902a10a3eb07af7df9f04184000ad75c6b38532 (patch) | |
tree | 4f12a15c25207152331944d0f7999aadc3f79ff6 /helix-term | |
parent | ffa2f2590bc679b3cf8529e9578860ad05b78148 (diff) |
Make Document's format API a little nicer.
Diffstat (limited to 'helix-term')
-rw-r--r-- | helix-term/src/commands.rs | 23 |
1 files changed, 9 insertions, 14 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 5df52855..93d01aa7 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -1160,20 +1160,12 @@ mod cmd { if doc.path().is_none() { return Err(anyhow!("cannot write a buffer without a filename")); } - let autofmt = doc - .language_config() - .map(|config| config.auto_format) - .unwrap_or_default(); - let fmt = if autofmt { - doc.format().map(|fmt| { - let shared = fmt.shared(); - let callback = make_format_callback(doc.id(), doc.version(), true, shared.clone()); - jobs.callback(callback); - shared - }) - } else { - None - }; + let fmt = doc.auto_format().map(|fmt| { + let shared = fmt.shared(); + let callback = make_format_callback(doc.id(), doc.version(), true, shared.clone()); + jobs.callback(callback); + shared + }); Ok(tokio::spawn(doc.format_and_save(fmt))) } @@ -1917,6 +1909,9 @@ fn append_to_line(cx: &mut Context) { // Creates an LspCallback that waits for formatting changes to be computed. When they're done, // it applies them, but only if the doc hasn't changed. +// +// TODO: provide some way to cancel this, probably as part of a more general job cancellation +// scheme async fn make_format_callback( doc_id: DocumentId, doc_version: i32, |