Skip to content

Commit db8fc7c

Browse files
Resolve completions properly remotely
1 parent 3685b6d commit db8fc7c

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

crates/project/src/lsp_store.rs

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1759,7 +1759,6 @@ impl LspStore {
17591759
buffer_id: buffer_id.into(),
17601760
};
17611761

1762-
// TODO kb this has to return the entire LSP completion instead, not just the docs
17631762
let Some(response) = client
17641763
.request(request)
17651764
.await
@@ -1768,6 +1767,10 @@ impl LspStore {
17681767
else {
17691768
return;
17701769
};
1770+
let Some(lsp_completion) = serde_json::from_slice(&response.lsp_completion).log_err()
1771+
else {
1772+
return;
1773+
};
17711774

17721775
let documentation = if response.documentation.is_empty() {
17731776
Documentation::Undocumented
@@ -1784,6 +1787,7 @@ impl LspStore {
17841787
let mut completions = completions.write();
17851788
let completion = &mut completions[completion_index];
17861789
completion.documentation = Some(documentation);
1790+
completion.lsp_completion = lsp_completion;
17871791

17881792
let old_range = response
17891793
.old_start
@@ -4189,17 +4193,32 @@ impl LspStore {
41894193
let lsp_completion = serde_json::from_slice(&envelope.payload.lsp_completion)?;
41904194

41914195
let completion = this
4192-
.read_with(&cx, |this, _| {
4196+
.read_with(&cx, |this, cx| {
41934197
let id = LanguageServerId(envelope.payload.language_server_id as usize);
41944198
let Some(server) = this.language_server_for_id(id) else {
41954199
return Err(anyhow!("No language server {id}"));
41964200
};
41974201

4198-
Ok(server.request::<lsp::request::ResolveCompletionItem>(lsp_completion))
4202+
Ok(cx.background_executor().spawn(async move {
4203+
let can_resolve = server
4204+
.capabilities()
4205+
.completion_provider
4206+
.as_ref()
4207+
.and_then(|options| options.resolve_provider)
4208+
.unwrap_or(false);
4209+
if can_resolve {
4210+
server
4211+
.request::<lsp::request::ResolveCompletionItem>(lsp_completion)
4212+
.await
4213+
} else {
4214+
anyhow::Ok(lsp_completion)
4215+
}
4216+
}))
41994217
})??
42004218
.await?;
42014219

42024220
let mut documentation_is_markdown = false;
4221+
let lsp_completion = serde_json::to_string(&completion)?.into_bytes();
42034222
let documentation = match completion.documentation {
42044223
Some(lsp::Documentation::String(text)) => text,
42054224

@@ -4241,6 +4260,7 @@ impl LspStore {
42414260
old_start,
42424261
old_end,
42434262
new_text,
4263+
lsp_completion,
42444264
})
42454265
}
42464266

crates/proto/proto/zed.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1219,6 +1219,7 @@ message ResolveCompletionDocumentationResponse {
12191219
Anchor old_start = 3;
12201220
Anchor old_end = 4;
12211221
string new_text = 5;
1222+
bytes lsp_completion = 6;
12221223
}
12231224

12241225
message ResolveInlayHint {

0 commit comments

Comments
 (0)