mirror of
https://github.com/helix-editor/helix.git
synced 2025-04-02 02:17:44 +03:00
Track progress title an display in place of internal token (#13180)
Co-authored-by: Michael Davis <mcarsondavis@gmail.com>
This commit is contained in:
parent
68d7308e25
commit
7929c0719d
2 changed files with 77 additions and 48 deletions
|
@ -733,14 +733,17 @@ impl Registry {
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum ProgressStatus {
|
pub enum ProgressStatus {
|
||||||
Created,
|
Created,
|
||||||
Started(lsp::WorkDoneProgress),
|
Started {
|
||||||
|
title: String,
|
||||||
|
progress: lsp::WorkDoneProgress,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ProgressStatus {
|
impl ProgressStatus {
|
||||||
pub fn progress(&self) -> Option<&lsp::WorkDoneProgress> {
|
pub fn progress(&self) -> Option<&lsp::WorkDoneProgress> {
|
||||||
match &self {
|
match &self {
|
||||||
ProgressStatus::Created => None,
|
ProgressStatus::Created => None,
|
||||||
ProgressStatus::Started(progress) => Some(progress),
|
ProgressStatus::Started { title: _, progress } => Some(progress),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -777,6 +780,13 @@ impl LspProgressMap {
|
||||||
self.0.get(&id).and_then(|values| values.get(token))
|
self.0.get(&id).and_then(|values| values.get(token))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn title(&self, id: LanguageServerId, token: &lsp::ProgressToken) -> Option<&String> {
|
||||||
|
self.progress(id, token).and_then(|p| match p {
|
||||||
|
ProgressStatus::Created => None,
|
||||||
|
ProgressStatus::Started { title, .. } => Some(title),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
/// Checks if progress `token` for server with `id` is created.
|
/// Checks if progress `token` for server with `id` is created.
|
||||||
pub fn is_created(&mut self, id: LanguageServerId, token: &lsp::ProgressToken) -> bool {
|
pub fn is_created(&mut self, id: LanguageServerId, token: &lsp::ProgressToken) -> bool {
|
||||||
self.0
|
self.0
|
||||||
|
@ -801,17 +811,39 @@ impl LspProgressMap {
|
||||||
self.0.get_mut(&id).and_then(|vals| vals.remove(token))
|
self.0.get_mut(&id).and_then(|vals| vals.remove(token))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Updates the progress of `token` for server with `id` to `status`, returns the value replaced or `None`.
|
/// Updates the progress of `token` for server with `id` to begin state `status`
|
||||||
|
pub fn begin(
|
||||||
|
&mut self,
|
||||||
|
id: LanguageServerId,
|
||||||
|
token: lsp::ProgressToken,
|
||||||
|
status: lsp::WorkDoneProgressBegin,
|
||||||
|
) {
|
||||||
|
self.0.entry(id).or_default().insert(
|
||||||
|
token,
|
||||||
|
ProgressStatus::Started {
|
||||||
|
title: status.title.clone(),
|
||||||
|
progress: lsp::WorkDoneProgress::Begin(status),
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Updates the progress of `token` for server with `id` to report state `status`.
|
||||||
pub fn update(
|
pub fn update(
|
||||||
&mut self,
|
&mut self,
|
||||||
id: LanguageServerId,
|
id: LanguageServerId,
|
||||||
token: lsp::ProgressToken,
|
token: lsp::ProgressToken,
|
||||||
status: lsp::WorkDoneProgress,
|
status: lsp::WorkDoneProgressReport,
|
||||||
) -> Option<ProgressStatus> {
|
) {
|
||||||
self.0
|
self.0
|
||||||
.entry(id)
|
.entry(id)
|
||||||
.or_default()
|
.or_default()
|
||||||
.insert(token, ProgressStatus::Started(status))
|
.entry(token)
|
||||||
|
.and_modify(|e| match e {
|
||||||
|
ProgressStatus::Created => (),
|
||||||
|
ProgressStatus::Started { progress, .. } => {
|
||||||
|
*progress = lsp::WorkDoneProgress::Report(status)
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -756,10 +756,11 @@ impl Application {
|
||||||
.compositor
|
.compositor
|
||||||
.find::<ui::EditorView>()
|
.find::<ui::EditorView>()
|
||||||
.expect("expected at least one EditorView");
|
.expect("expected at least one EditorView");
|
||||||
let lsp::ProgressParams { token, value } = params;
|
let lsp::ProgressParams {
|
||||||
|
token,
|
||||||
let lsp::ProgressParamsValue::WorkDone(work) = value;
|
value: lsp::ProgressParamsValue::WorkDone(work),
|
||||||
let parts = match &work {
|
} = params;
|
||||||
|
let (title, message, percentage) = match &work {
|
||||||
lsp::WorkDoneProgress::Begin(lsp::WorkDoneProgressBegin {
|
lsp::WorkDoneProgress::Begin(lsp::WorkDoneProgressBegin {
|
||||||
title,
|
title,
|
||||||
message,
|
message,
|
||||||
|
@ -787,47 +788,43 @@ impl Application {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let token_d: &dyn std::fmt::Display = match &token {
|
if self.editor.config().lsp.display_progress_messages {
|
||||||
lsp::NumberOrString::Number(n) => n,
|
let title =
|
||||||
lsp::NumberOrString::String(s) => s,
|
title.or_else(|| self.lsp_progress.title(server_id, &token));
|
||||||
};
|
if title.is_some() || percentage.is_some() || message.is_some() {
|
||||||
|
use std::fmt::Write as _;
|
||||||
let status = match parts {
|
let mut status = format!("{}: ", language_server!().name());
|
||||||
(Some(title), Some(message), Some(percentage)) => {
|
if let Some(percentage) = percentage {
|
||||||
format!("[{}] {}% {} - {}", token_d, percentage, title, message)
|
write!(status, "{percentage:>2}% ").unwrap();
|
||||||
|
}
|
||||||
|
if let Some(title) = title {
|
||||||
|
status.push_str(title);
|
||||||
|
}
|
||||||
|
if title.is_some() && message.is_some() {
|
||||||
|
status.push_str(" ⋅ ");
|
||||||
|
}
|
||||||
|
if let Some(message) = message {
|
||||||
|
status.push_str(message);
|
||||||
|
}
|
||||||
|
self.editor.set_status(status);
|
||||||
}
|
}
|
||||||
(Some(title), None, Some(percentage)) => {
|
|
||||||
format!("[{}] {}% {}", token_d, percentage, title)
|
|
||||||
}
|
|
||||||
(Some(title), Some(message), None) => {
|
|
||||||
format!("[{}] {} - {}", token_d, title, message)
|
|
||||||
}
|
|
||||||
(None, Some(message), Some(percentage)) => {
|
|
||||||
format!("[{}] {}% {}", token_d, percentage, message)
|
|
||||||
}
|
|
||||||
(Some(title), None, None) => {
|
|
||||||
format!("[{}] {}", token_d, title)
|
|
||||||
}
|
|
||||||
(None, Some(message), None) => {
|
|
||||||
format!("[{}] {}", token_d, message)
|
|
||||||
}
|
|
||||||
(None, None, Some(percentage)) => {
|
|
||||||
format!("[{}] {}%", token_d, percentage)
|
|
||||||
}
|
|
||||||
(None, None, None) => format!("[{}]", token_d),
|
|
||||||
};
|
|
||||||
|
|
||||||
if let lsp::WorkDoneProgress::End(_) = work {
|
|
||||||
self.lsp_progress.end_progress(server_id, &token);
|
|
||||||
if !self.lsp_progress.is_progressing(server_id) {
|
|
||||||
editor_view.spinners_mut().get_or_create(server_id).stop();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
self.lsp_progress.update(server_id, token, work);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.config.load().editor.lsp.display_progress_messages {
|
match work {
|
||||||
self.editor.set_status(status);
|
lsp::WorkDoneProgress::Begin(begin_status) => {
|
||||||
|
self.lsp_progress
|
||||||
|
.begin(server_id, token.clone(), begin_status);
|
||||||
|
}
|
||||||
|
lsp::WorkDoneProgress::Report(report_status) => {
|
||||||
|
self.lsp_progress
|
||||||
|
.update(server_id, token.clone(), report_status);
|
||||||
|
}
|
||||||
|
lsp::WorkDoneProgress::End(_) => {
|
||||||
|
self.lsp_progress.end_progress(server_id, &token);
|
||||||
|
if !self.lsp_progress.is_progressing(server_id) {
|
||||||
|
editor_view.spinners_mut().get_or_create(server_id).stop();
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Notification::ProgressMessage(_params) => {
|
Notification::ProgressMessage(_params) => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue