From 2902a10a3eb07af7df9f04184000ad75c6b38532 Mon Sep 17 00:00:00 2001 From: Joe Neeman Date: Tue, 29 Jun 2021 22:36:33 -0500 Subject: Make Document's format API a little nicer. --- helix-view/src/document.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'helix-view/src/document.rs') 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 + '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 + 'static> { if let Some(language_server) = self.language_server.clone() { let text = self.text.clone(); -- cgit v1.2.3-70-g09d2