From 039ef1ad5a932d57297a8242c55ff1d69c628271 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Thu, 25 Jan 2024 12:46:51 -0800 Subject: [PATCH] Put back Project's completion-documention handler (#6451) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This restores the ability for project guests to see documentation on autocomplete suggestions. @ForLoveOfCats This code might have gotten lost during the GPUI upgrade. I'm not sure what happened. I tested this locally, and it seems to fix completion docs for guests. Could you 👀 and see if there are any tests or any other code that got lost along with this during the upgrade? --- crates/project/src/project.rs | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/crates/project/src/project.rs b/crates/project/src/project.rs index 840f9b20db..9476463e33 100644 --- a/crates/project/src/project.rs +++ b/crates/project/src/project.rs @@ -590,6 +590,7 @@ impl Project { client.add_model_request_handler(Self::handle_delete_project_entry); client.add_model_request_handler(Self::handle_expand_project_entry); client.add_model_request_handler(Self::handle_apply_additional_edits_for_completion); + client.add_model_request_handler(Self::handle_resolve_completion_documentation); client.add_model_request_handler(Self::handle_apply_code_action); client.add_model_request_handler(Self::handle_on_type_formatting); client.add_model_request_handler(Self::handle_inlay_hints); @@ -7726,6 +7727,40 @@ impl Project { }) } + async fn handle_resolve_completion_documentation( + this: Model, + envelope: TypedEnvelope, + _: Arc, + mut cx: AsyncAppContext, + ) -> Result { + let lsp_completion = serde_json::from_slice(&envelope.payload.lsp_completion)?; + + let completion = this + .read_with(&mut cx, |this, _| { + let id = LanguageServerId(envelope.payload.language_server_id as usize); + let Some(server) = this.language_server_for_id(id) else { + return Err(anyhow!("No language server {id}")); + }; + + Ok(server.request::(lsp_completion)) + })?? + .await?; + + let mut is_markdown = false; + let text = match completion.documentation { + Some(lsp::Documentation::String(text)) => text, + + Some(lsp::Documentation::MarkupContent(lsp::MarkupContent { kind, value })) => { + is_markdown = kind == lsp::MarkupKind::Markdown; + value + } + + _ => String::new(), + }; + + Ok(proto::ResolveCompletionDocumentationResponse { text, is_markdown }) + } + async fn handle_apply_code_action( this: Model, envelope: TypedEnvelope,