Show status of LSP actions (#9818)

Fixes #4380

Parts im still unsure about:
- [x] where exactly I should call `on_lsp_start`/`on_lsp_end`
- [x] how to handle things better than `let is_references =
TypeId::of::<R>() == TypeId::of::<GetReferences>();`, which feels very
janky
- [x] I want to have the message be something like `"Finding references
to [...]"` instead of just `textDocument/references`, but I'm not sure
how to retrieve the name of the symbol that's being queried
- [ ] I think the bulk of the runtime is occupied by `let result =
language_server.request::<R::LspRequest>(lsp_params).await;`, but since
`ModelContext` isn't passed into it, I'm not sure how to update progress
from within that function
- [x] A good way to disambiguate between multiple calls to the same lsp
function; im currently using the function name itself as the unique
identifier for that request, which could create issues if multiple
`textDocument/references` requests are sent in parallel

Any help with these would be deeply appreciated!

Release Notes:

- Adds a status indicator for LSP actions

---------

Co-authored-by: Mikayla <mikayla@zed.dev>
This commit is contained in:
Daniel Zhu 2024-04-06 22:48:11 -04:00 committed by GitHub
parent c7961b9054
commit 4944dc9d78
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 99 additions and 22 deletions

View file

@ -55,7 +55,8 @@ use log::error;
use lsp::{
DiagnosticSeverity, DiagnosticTag, DidChangeWatchedFilesRegistrationOptions,
DocumentHighlightKind, LanguageServer, LanguageServerBinary, LanguageServerId,
MessageActionItem, OneOf, ServerCapabilities, ServerHealthStatus, ServerStatus,
LspRequestFuture, MessageActionItem, OneOf, ServerCapabilities, ServerHealthStatus,
ServerStatus,
};
use lsp_command::*;
use node_runtime::NodeRuntime;
@ -5697,7 +5698,7 @@ impl Project {
}
fn code_actions_impl(
&self,
&mut self,
buffer_handle: &Model<Buffer>,
range: Range<Anchor>,
cx: &mut ModelContext<Self>,
@ -5777,7 +5778,7 @@ impl Project {
}
pub fn code_actions<T: Clone + ToOffset>(
&self,
&mut self,
buffer_handle: &Model<Buffer>,
range: Range<T>,
cx: &mut ModelContext<Self>,
@ -6131,7 +6132,7 @@ impl Project {
}
fn prepare_rename_impl(
&self,
&mut self,
buffer: Model<Buffer>,
position: PointUtf16,
cx: &mut ModelContext<Self>,
@ -6144,7 +6145,7 @@ impl Project {
)
}
pub fn prepare_rename<T: ToPointUtf16>(
&self,
&mut self,
buffer: Model<Buffer>,
position: T,
cx: &mut ModelContext<Self>,
@ -6154,7 +6155,7 @@ impl Project {
}
fn perform_rename_impl(
&self,
&mut self,
buffer: Model<Buffer>,
position: PointUtf16,
new_name: String,
@ -6174,7 +6175,7 @@ impl Project {
)
}
pub fn perform_rename<T: ToPointUtf16>(
&self,
&mut self,
buffer: Model<Buffer>,
position: T,
new_name: String,
@ -6186,7 +6187,7 @@ impl Project {
}
pub fn on_type_format_impl(
&self,
&mut self,
buffer: Model<Buffer>,
position: PointUtf16,
trigger: String,
@ -6210,7 +6211,7 @@ impl Project {
}
pub fn on_type_format<T: ToPointUtf16>(
&self,
&mut self,
buffer: Model<Buffer>,
position: T,
trigger: String,
@ -6222,7 +6223,7 @@ impl Project {
}
pub fn inlay_hints<T: ToOffset>(
&self,
&mut self,
buffer_handle: Model<Buffer>,
range: Range<T>,
cx: &mut ModelContext<Self>,
@ -6232,7 +6233,7 @@ impl Project {
self.inlay_hints_impl(buffer_handle, range, cx)
}
fn inlay_hints_impl(
&self,
&mut self,
buffer_handle: Model<Buffer>,
range: Range<Anchor>,
cx: &mut ModelContext<Self>,
@ -6711,12 +6712,34 @@ impl Project {
let file = File::from_dyn(buffer.file()).and_then(File::as_local);
if let (Some(file), Some(language_server)) = (file, language_server) {
let lsp_params = request.to_lsp(&file.abs_path(cx), buffer, &language_server, cx);
let status = request.status();
return cx.spawn(move |this, cx| async move {
if !request.check_capabilities(language_server.capabilities()) {
return Ok(Default::default());
}
let result = language_server.request::<R::LspRequest>(lsp_params).await;
let lsp_request = language_server.request::<R::LspRequest>(lsp_params);
let id = lsp_request.id();
if status.is_some() {
cx.update(|cx| {
this.update(cx, |this, cx| {
this.on_lsp_work_start(
language_server.server_id(),
id.to_string(),
LanguageServerProgress {
message: status.clone(),
percentage: None,
last_update_at: Instant::now(),
},
cx,
);
})
})
.log_err();
}
let result = lsp_request.await;
let response = match result {
Ok(response) => response,
@ -6729,16 +6752,30 @@ impl Project {
return Err(err);
}
};
request
let result = request
.response_from_lsp(
response,
this.upgrade().ok_or_else(|| anyhow!("no app context"))?,
buffer_handle,
language_server.server_id(),
cx,
cx.clone(),
)
.await
.await;
if status.is_some() {
cx.update(|cx| {
this.update(cx, |this, cx| {
this.on_lsp_work_end(
language_server.server_id(),
id.to_string(),
cx,
);
})
})
.log_err();
}
result
});
}
} else if let Some(project_id) = self.remote_id() {