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-view/src | |
parent | ffa2f2590bc679b3cf8529e9578860ad05b78148 (diff) |
Make Document's format API a little nicer.
Diffstat (limited to 'helix-view/src')
-rw-r--r-- | helix-view/src/document.rs | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/helix-view/src/document.rs b/helix-view/src/document.rs index 80ef54d5..0f1f3a8f 100644 --- a/helix-view/src/document.rs +++ b/helix-view/src/document.rs @@ -473,6 +473,18 @@ impl Document { Ok(doc) } + /// The same as [`format`], but only returns formatting changes if auto-formatting + /// is configured. + pub fn auto_format(&self) -> Option<impl Future<Output = LspFormatting> + 'static> { + if self.language_config().map(|c| c.auto_format) == Some(true) { + self.format() + } else { + None + } + } + + /// If supported, returns the changes that should be applied to this document in order + /// to format it nicely. pub fn format(&self) -> Option<impl Future<Output = LspFormatting> + 'static> { if let Some(language_server) = self.language_server.clone() { let text = self.text.clone(); |