From fbc0f956b310284d609f2c00a1f4c0da6bcac165 Mon Sep 17 00:00:00 2001 From: Michael Davis <mcarsondavis@gmail.com> Date: Tue, 4 Mar 2025 12:01:06 -0500 Subject: [PATCH] minor: Move json deserialization into text_document_hover future This follows a pattern used in the signature help request for example. Moving the json deserialization into the return future of `text_document_hover` makes the types easier for callers to work with. --- helix-lsp/src/client.rs | 5 +++-- helix-term/src/commands/lsp.rs | 6 +----- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/helix-lsp/src/client.rs b/helix-lsp/src/client.rs index d6308997..bf8a8695 100644 --- a/helix-lsp/src/client.rs +++ b/helix-lsp/src/client.rs @@ -1119,7 +1119,7 @@ impl Client { text_document: lsp::TextDocumentIdentifier, position: lsp::Position, work_done_token: Option<lsp::ProgressToken>, - ) -> Option<impl Future<Output = Result<Value>>> { + ) -> Option<impl Future<Output = Result<Option<lsp::Hover>>>> { let capabilities = self.capabilities.get().unwrap(); // Return early if the server does not support hover. @@ -1140,7 +1140,8 @@ impl Client { // lsp::SignatureHelpContext }; - Some(self.call::<lsp::request::HoverRequest>(params)) + let res = self.call::<lsp::request::HoverRequest>(params); + Some(async move { Ok(serde_json::from_value(res.await?)?) }) } // formatting diff --git a/helix-term/src/commands/lsp.rs b/helix-term/src/commands/lsp.rs index 1ef4d4bd..c5442924 100644 --- a/helix-term/src/commands/lsp.rs +++ b/helix-term/src/commands/lsp.rs @@ -1076,11 +1076,7 @@ pub fn hover(cx: &mut Context) { .text_document_hover(doc.identifier(), pos, None) .unwrap(); - async move { - let json = request.await?; - let response = serde_json::from_value::<Option<lsp::Hover>>(json)?; - anyhow::Ok((server_name, response)) - } + async move { anyhow::Ok((server_name, request.await?)) } }) .collect();