Route completion requests through remote protocol, if needed
This commit is contained in:
parent
5bc5831032
commit
e682db7101
1 changed files with 71 additions and 58 deletions
|
@ -4496,10 +4496,10 @@ impl Project {
|
||||||
position: T,
|
position: T,
|
||||||
cx: &mut ModelContext<Self>,
|
cx: &mut ModelContext<Self>,
|
||||||
) -> Task<Result<Vec<Completion>>> {
|
) -> Task<Result<Vec<Completion>>> {
|
||||||
|
let position = position.to_point_utf16(buffer.read(cx));
|
||||||
|
if self.is_local() {
|
||||||
let snapshot = buffer.read(cx).snapshot();
|
let snapshot = buffer.read(cx).snapshot();
|
||||||
let offset = position.to_offset(&snapshot);
|
let offset = position.to_offset(&snapshot);
|
||||||
let position = position.to_point_utf16(buffer.read(cx));
|
|
||||||
|
|
||||||
let scope = snapshot.language_scope_at(offset);
|
let scope = snapshot.language_scope_at(offset);
|
||||||
|
|
||||||
let server_ids: Vec<_> = self
|
let server_ids: Vec<_> = self
|
||||||
|
@ -4537,6 +4537,11 @@ impl Project {
|
||||||
|
|
||||||
Ok(completions)
|
Ok(completions)
|
||||||
})
|
})
|
||||||
|
} else if let Some(project_id) = self.remote_id() {
|
||||||
|
self.send_lsp_proto_request(buffer.clone(), project_id, GetCompletions { position }, cx)
|
||||||
|
} else {
|
||||||
|
Task::ready(Ok(Default::default()))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn apply_additional_edits_for_completion(
|
pub fn apply_additional_edits_for_completion(
|
||||||
|
@ -5587,16 +5592,27 @@ impl Project {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else if let Some(project_id) = self.remote_id() {
|
} else if let Some(project_id) = self.remote_id() {
|
||||||
|
return self.send_lsp_proto_request(buffer_handle, project_id, request, cx);
|
||||||
|
}
|
||||||
|
|
||||||
|
Task::ready(Ok(Default::default()))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn send_lsp_proto_request<R: LspCommand>(
|
||||||
|
&self,
|
||||||
|
buffer: ModelHandle<Buffer>,
|
||||||
|
project_id: u64,
|
||||||
|
request: R,
|
||||||
|
cx: &mut ModelContext<'_, Project>,
|
||||||
|
) -> Task<anyhow::Result<<R as LspCommand>::Response>> {
|
||||||
let rpc = self.client.clone();
|
let rpc = self.client.clone();
|
||||||
let message = request.to_proto(project_id, buffer);
|
let message = request.to_proto(project_id, buffer.read(cx));
|
||||||
return cx.spawn_weak(|this, cx| async move {
|
cx.spawn_weak(|this, cx| async move {
|
||||||
// Ensure the project is still alive by the time the task
|
// Ensure the project is still alive by the time the task
|
||||||
// is scheduled.
|
// is scheduled.
|
||||||
this.upgrade(&cx)
|
this.upgrade(&cx)
|
||||||
.ok_or_else(|| anyhow!("project dropped"))?;
|
.ok_or_else(|| anyhow!("project dropped"))?;
|
||||||
|
|
||||||
let response = rpc.request(message).await?;
|
let response = rpc.request(message).await?;
|
||||||
|
|
||||||
let this = this
|
let this = this
|
||||||
.upgrade(&cx)
|
.upgrade(&cx)
|
||||||
.ok_or_else(|| anyhow!("project dropped"))?;
|
.ok_or_else(|| anyhow!("project dropped"))?;
|
||||||
|
@ -5604,13 +5620,10 @@ impl Project {
|
||||||
Err(anyhow!("disconnected before completing request"))
|
Err(anyhow!("disconnected before completing request"))
|
||||||
} else {
|
} else {
|
||||||
request
|
request
|
||||||
.response_from_proto(response, this, buffer_handle, cx)
|
.response_from_proto(response, this, buffer, cx)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
}
|
|
||||||
|
|
||||||
Task::ready(Ok(Default::default()))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn sort_candidates_and_open_buffers(
|
fn sort_candidates_and_open_buffers(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue