aboutsummaryrefslogtreecommitdiff
path: root/helix-view/src/document.rs
diff options
context:
space:
mode:
Diffstat (limited to 'helix-view/src/document.rs')
-rw-r--r--helix-view/src/document.rs12
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();