Skip to content

Commit

Permalink
Resolve completions properly remotely
Browse files Browse the repository at this point in the history
  • Loading branch information
SomeoneToIgnore committed Sep 23, 2024
1 parent 3685b6d commit db8fc7c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
26 changes: 23 additions & 3 deletions crates/project/src/lsp_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1759,7 +1759,6 @@ impl LspStore {
buffer_id: buffer_id.into(),
};

// TODO kb this has to return the entire LSP completion instead, not just the docs
let Some(response) = client
.request(request)
.await
Expand All @@ -1768,6 +1767,10 @@ impl LspStore {
else {
return;
};
let Some(lsp_completion) = serde_json::from_slice(&response.lsp_completion).log_err()
else {
return;
};

let documentation = if response.documentation.is_empty() {
Documentation::Undocumented
Expand All @@ -1784,6 +1787,7 @@ impl LspStore {
let mut completions = completions.write();
let completion = &mut completions[completion_index];
completion.documentation = Some(documentation);
completion.lsp_completion = lsp_completion;

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

let completion = this
.read_with(&cx, |this, _| {
.read_with(&cx, |this, cx| {
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::request::ResolveCompletionItem>(lsp_completion))
Ok(cx.background_executor().spawn(async move {
let can_resolve = server
.capabilities()
.completion_provider
.as_ref()
.and_then(|options| options.resolve_provider)
.unwrap_or(false);
if can_resolve {
server
.request::<lsp::request::ResolveCompletionItem>(lsp_completion)
.await
} else {
anyhow::Ok(lsp_completion)
}
}))
})??
.await?;

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

Expand Down Expand Up @@ -4241,6 +4260,7 @@ impl LspStore {
old_start,
old_end,
new_text,
lsp_completion,
})
}

Expand Down
1 change: 1 addition & 0 deletions crates/proto/proto/zed.proto
Original file line number Diff line number Diff line change
Expand Up @@ -1219,6 +1219,7 @@ message ResolveCompletionDocumentationResponse {
Anchor old_start = 3;
Anchor old_end = 4;
string new_text = 5;
bytes lsp_completion = 6;
}

message ResolveInlayHint {
Expand Down

0 comments on commit db8fc7c

Please sign in to comment.