Skip to content

Commit

Permalink
minor: Move json deserialization into text_document_hover future
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
the-mikedavis committed Mar 4, 2025
1 parent 486f429 commit fbc0f95
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
5 changes: 3 additions & 2 deletions helix-lsp/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down
6 changes: 1 addition & 5 deletions helix-term/src/commands/lsp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down

0 comments on commit fbc0f95

Please sign in to comment.