Show the last in-progress task from language servers

This commit is contained in:
Antonio Scandurra 2022-03-11 09:59:13 +01:00
parent 5157b42896
commit 7a454003fe
4 changed files with 20 additions and 7 deletions

1
Cargo.lock generated
View file

@ -5852,6 +5852,7 @@ dependencies = [
"postage",
"project",
"serde_json",
"smallvec",
"theme",
"util",
]

View file

@ -136,10 +136,11 @@ pub struct LanguageServerStatus {
pending_diagnostic_updates: isize,
}
#[derive(Clone, Default)]
#[derive(Clone, Debug)]
pub struct LanguageServerProgress {
pub message: Option<String>,
pub percentage: Option<usize>,
pub last_update_at: Instant,
}
#[derive(Clone, Debug, Eq, PartialEq, Hash, PartialOrd, Ord)]
@ -1253,6 +1254,7 @@ impl Project {
percentage: report
.percentage
.map(|p| p as usize),
last_update_at: Instant::now(),
},
})
.ok();
@ -1494,6 +1496,7 @@ impl Project {
LanguageServerProgress {
message: None,
percentage: None,
last_update_at: Instant::now(),
},
);
cx.notify();
@ -1541,7 +1544,9 @@ impl Project {
}
}
pub fn language_server_statuses(&self) -> impl Iterator<Item = &LanguageServerStatus> {
pub fn language_server_statuses(
&self,
) -> impl DoubleEndedIterator<Item = &LanguageServerStatus> {
self.language_server_statuses.values()
}
@ -3332,6 +3337,7 @@ impl Project {
LanguageServerProgress {
message: payload.message,
percentage: payload.percentage.map(|p| p as usize),
last_update_at: Instant::now(),
},
cx,
);

View file

@ -24,6 +24,7 @@ futures = "0.3"
log = "0.4"
parking_lot = "0.11.1"
postage = { version = "0.4.1", features = ["futures-traits"] }
smallvec = { version = "1.6", features = ["union"] }
[dev-dependencies]
client = { path = "../client", features = ["test-support"] }

View file

@ -8,6 +8,8 @@ use gpui::{
use language::{LanguageRegistry, LanguageServerBinaryStatus};
use postage::watch;
use project::{LanguageServerProgress, Project};
use smallvec::SmallVec;
use std::cmp::Reverse;
use std::fmt::Write;
use std::sync::Arc;
@ -90,15 +92,18 @@ impl LspStatus {
self.project
.read(cx)
.language_server_statuses()
.rev()
.filter_map(|status| {
if status.pending_work.is_empty() {
None
} else {
Some(
status.pending_work.iter().map(|(token, progress)| {
(status.name.as_str(), token.as_str(), progress)
}),
)
let mut pending_work = status
.pending_work
.iter()
.map(|(token, progress)| (status.name.as_str(), token.as_str(), progress))
.collect::<SmallVec<[_; 4]>>();
pending_work.sort_by_key(|(_, _, progress)| Reverse(progress.last_update_at));
Some(pending_work)
}
})
.flatten()