on master help sign in
ls: Refactor textDocument/didSave in a similar vein
commit800d79b584cd09020488b8a614e5214b929d8f5d authorBlaž Hrastnik <blaz@mxxn.io> dateWed 1 Sep 2021, 14:54 (5 years ago) parent184637c
2 files changed+14−13
helix-lsp/src/client.rs+10−9 helix-view/src/document.rs+4−4
helix-lsp/src/client.rs+10−9
@@ -490,11 +490,11 @@ impl Client {
490490
491491 // will_save / will_save_wait_until
492492
493− pub async fn text_document_did_save(
493+ pub fn text_document_did_save(
494494 &self,
495495 text_document: lsp::TextDocumentIdentifier,
496496 text: &Rope,
497− ) -> Result<()> {
497+ ) -> Option<impl Future<Output = Result<()>>> {
498498 let capabilities = self.capabilities.get().unwrap();
499499
500500 let include_text = match &capabilities.text_document_sync {
@@ -507,17 +507,18 @@ impl Client {
507507 include_text,
508508 }) => include_text.unwrap_or(false),
509509 // Supported(false)
510− _ => return Ok(()),
510+ _ => return None,
511511 },
512512 // unsupported
513− _ => return Ok(()),
513+ _ => return None,
514514 };
515515
516− self.notify::<lsp::notification::DidSaveTextDocument>(lsp::DidSaveTextDocumentParams {
517− text_document,
518− text: include_text.then(|| text.into()),
519− })
520− .await
516+ Some(self.notify::<lsp::notification::DidSaveTextDocument>(
517+ lsp::DidSaveTextDocumentParams {
518+ text_document,
519+ text: include_text.then(|| text.into()),
520+ },
521+ ))
521522 }
522523
523524 pub fn completion(
helix-view/src/document.rs+4−4
@@ -471,10 +471,10 @@ impl Document {
471471 let mut file = File::create(path).await?;
472472 to_writer(&mut file, encoding, &text).await?;
473473
474− if let Some(language_server) = language_server {
475− language_server
476− .text_document_did_save(identifier, &text)
477− .await?;
474+ if let Some(notification) = language_server.and_then(|language_server| {
475+ language_server.text_document_did_save(identifier, &text)
476+ }) {
477+ notification.await?;
478478 }
479479
480480 Ok(())