aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBlaž Hrastnik2021-09-01 05:54:11 +0000
committerBlaž Hrastnik2021-09-06 06:25:46 +0000
commit800d79b584cd09020488b8a614e5214b929d8f5d (patch)
treee3c1ae49995f071a183aa8591716c87ad1bd4e41
parent184637c55acca49380372ca118f13b3390bcb003 (diff)
ls: Refactor textDocument/didSave in a similar vein
-rw-r--r--helix-lsp/src/client.rs19
-rw-r--r--helix-view/src/document.rs8
2 files changed, 14 insertions, 13 deletions
diff --git a/helix-lsp/src/client.rs b/helix-lsp/src/client.rs
index fdff553f..b8fbfddb 100644
--- a/helix-lsp/src/client.rs
+++ b/helix-lsp/src/client.rs
@@ -490,11 +490,11 @@ impl Client {
// will_save / will_save_wait_until
- pub async fn text_document_did_save(
+ pub fn text_document_did_save(
&self,
text_document: lsp::TextDocumentIdentifier,
text: &Rope,
- ) -> Result<()> {
+ ) -> Option<impl Future<Output = Result<()>>> {
let capabilities = self.capabilities.get().unwrap();
let include_text = match &capabilities.text_document_sync {
@@ -507,17 +507,18 @@ impl Client {
include_text,
}) => include_text.unwrap_or(false),
// Supported(false)
- _ => return Ok(()),
+ _ => return None,
},
// unsupported
- _ => return Ok(()),
+ _ => return None,
};
- self.notify::<lsp::notification::DidSaveTextDocument>(lsp::DidSaveTextDocumentParams {
- text_document,
- text: include_text.then(|| text.into()),
- })
- .await
+ Some(self.notify::<lsp::notification::DidSaveTextDocument>(
+ lsp::DidSaveTextDocumentParams {
+ text_document,
+ text: include_text.then(|| text.into()),
+ },
+ ))
}
pub fn completion(
diff --git a/helix-view/src/document.rs b/helix-view/src/document.rs
index a27be8e6..5677eb44 100644
--- a/helix-view/src/document.rs
+++ b/helix-view/src/document.rs
@@ -471,10 +471,10 @@ impl Document {
let mut file = File::create(path).await?;
to_writer(&mut file, encoding, &text).await?;
- if let Some(language_server) = language_server {
- language_server
- .text_document_did_save(identifier, &text)
- .await?;
+ if let Some(notification) = language_server.and_then(|language_server| {
+ language_server.text_document_did_save(identifier, &text)
+ }) {
+ notification.await?;
}
Ok(())