on master help sign in
ls: Refactor textDocument/didSave in a similar vein
800d79bBlaž Hrastnik
helix-lsp/src/client.rs+10−9
@@ -490,11 +490,11 @@ impl Client {
490
490
491 // will_save / will_save_wait_until
491 // will_save / will_save_wait_until
492
492
493− pub async fn text_document_did_save(
493+ pub fn text_document_did_save(
494 &self,
494 &self,
495 text_document: lsp::TextDocumentIdentifier,
495 text_document: lsp::TextDocumentIdentifier,
496 text: &Rope,
496 text: &Rope,
497− ) -> Result<()> {
497+ ) -> Option<impl Future<Output = Result<()>>> {
498 let capabilities = self.capabilities.get().unwrap();
498 let capabilities = self.capabilities.get().unwrap();
499
499
500 let include_text = match &capabilities.text_document_sync {
500 let include_text = match &capabilities.text_document_sync {
@@ -507,17 +507,18 @@ impl Client {
507 include_text,
507 include_text,
508 }) => include_text.unwrap_or(false),
508 }) => include_text.unwrap_or(false),
509 // Supported(false)
509 // Supported(false)
510− _ => return Ok(()),
510+ _ => return None,
511 },
511 },
512 // unsupported
512 // unsupported
513− _ => return Ok(()),
513+ _ => return None,
514 };
514 };
515
515
516− self.notify::<lsp::notification::DidSaveTextDocument>(lsp::DidSaveTextDocumentParams {
516+ Some(self.notify::<lsp::notification::DidSaveTextDocument>(
517+ lsp::DidSaveTextDocumentParams {
517− text_document,
518+ text_document,
518− text: include_text.then(|| text.into()),
519+ text: include_text.then(|| text.into()),
519− })
520+ },
520− .await
521+ ))
521 }
522 }
522
523
523 pub fn completion(
524 pub fn completion(
helix-view/src/document.rs+4−4
@@ -471,10 +471,10 @@ impl Document {
471 let mut file = File::create(path).await?;
471 let mut file = File::create(path).await?;
472 to_writer(&mut file, encoding, &text).await?;
472 to_writer(&mut file, encoding, &text).await?;
473
473
474− if let Some(language_server) = language_server {
474+ if let Some(notification) = language_server.and_then(|language_server| {
475− language_server
476− .text_document_did_save(identifier, &text)
475+ language_server.text_document_did_save(identifier, &text)
476+ }) {
477− .await?;
477+ notification.await?;
478 }
478 }
479
479
480 Ok(())
480 Ok(())