Update handling of progress notification

pull/297/head
wojciechkepka 3 years ago committed by Blaž Hrastnik
parent 38cb934d8f
commit e1109a5a01

@ -1,4 +1,4 @@
use helix_lsp::lsp; use helix_lsp::{lsp, LspProgressMap};
use helix_view::{document::Mode, Document, Editor, Theme, View}; use helix_view::{document::Mode, Document, Editor, Theme, View};
use crate::{args::Args, compositor::Compositor, config::Config, keymap::Keymaps, ui}; use crate::{args::Args, compositor::Compositor, config::Config, keymap::Keymaps, ui};
@ -9,6 +9,7 @@ use std::{
future::Future, future::Future,
io::{self, stdout, Stdout, Write}, io::{self, stdout, Stdout, Write},
path::PathBuf, path::PathBuf,
pin::Pin,
sync::Arc, sync::Arc,
time::Duration, time::Duration,
}; };
@ -23,7 +24,6 @@ use crossterm::{
use tui::layout::Rect; use tui::layout::Rect;
use futures_util::stream::FuturesUnordered; use futures_util::stream::FuturesUnordered;
use std::pin::Pin;
type BoxFuture<T> = Pin<Box<dyn Future<Output = T> + Send>>; type BoxFuture<T> = Pin<Box<dyn Future<Output = T> + Send>>;
pub type LspCallback = pub type LspCallback =
@ -37,6 +37,8 @@ pub struct Application {
editor: Editor, editor: Editor,
callbacks: LspCallbacks, callbacks: LspCallbacks,
lsp_progress: LspProgressMap,
} }
impl Application { impl Application {
@ -74,6 +76,7 @@ impl Application {
editor, editor,
callbacks: FuturesUnordered::new(), callbacks: FuturesUnordered::new(),
lsp_progress: LspProgressMap::new(),
}; };
Ok(app) Ok(app)
@ -246,55 +249,67 @@ impl Application {
log::warn!("unhandled window/logMessage: {:?}", params); log::warn!("unhandled window/logMessage: {:?}", params);
} }
Notification::ProgressMessage(params) => { Notification::ProgressMessage(params) => {
let token = match params.token { let lsp::ProgressParams { token, value } = params;
lsp::NumberOrString::Number(n) => n.to_string(),
lsp::NumberOrString::String(s) => s, let lsp::ProgressParamsValue::WorkDone(work) = value;
}; let parts = match &work {
let msg = {
let lsp::ProgressParamsValue::WorkDone(work) = params.value;
let parts = match work {
lsp::WorkDoneProgress::Begin(lsp::WorkDoneProgressBegin { lsp::WorkDoneProgress::Begin(lsp::WorkDoneProgressBegin {
title, title,
message, message,
percentage, percentage,
.. ..
}) => (Some(title), message, percentage.map(|n| n.to_string())), }) => (Some(title), message, percentage),
lsp::WorkDoneProgress::Report(lsp::WorkDoneProgressReport { lsp::WorkDoneProgress::Report(lsp::WorkDoneProgressReport {
message, message,
percentage, percentage,
.. ..
}) => (None, message, percentage.map(|n| n.to_string())), }) => (None, message, percentage),
lsp::WorkDoneProgress::End(lsp::WorkDoneProgressEnd { lsp::WorkDoneProgress::End(lsp::WorkDoneProgressEnd { message }) => {
message, if message.is_some() {
}) => { (None, message, &None)
if let Some(message) = message {
(None, Some(message), None)
} else { } else {
self.lsp_progress.end_progress(server_id, &token);
self.editor.clear_status(); self.editor.clear_status();
return; return;
} }
} }
}; };
match parts { let token_d: &dyn std::fmt::Display = match &token {
lsp::NumberOrString::Number(n) => n,
lsp::NumberOrString::String(s) => s,
};
let status = match parts {
(Some(title), Some(message), Some(percentage)) => { (Some(title), Some(message), Some(percentage)) => {
format!("{}% {} - {}", percentage, title, message) format!("[{}] {}% {} - {}", token_d, percentage, title, message)
} }
(Some(title), None, Some(percentage)) => { (Some(title), None, Some(percentage)) => {
format!("{}% {}", percentage, title) format!("[{}] {}% {}", token_d, percentage, title)
} }
(Some(title), Some(message), None) => { (Some(title), Some(message), None) => {
format!("{} - {}", title, message) format!("[{}] {} - {}", token_d, title, message)
} }
(None, Some(message), Some(percentage)) => { (None, Some(message), Some(percentage)) => {
format!("{}% {}", percentage, message) format!("[{}] {}% {}", token_d, percentage, message)
} }
(Some(title), None, None) => title, (Some(title), None, None) => {
(None, Some(message), None) => message, format!("[{}] {}", token_d, title)
(None, None, Some(percentage)) => format!("{}%", percentage), }
(None, None, None) => "".into(), (None, Some(message), None) => {
format!("[{}] {}", token_d, message)
}
(None, None, Some(percentage)) => {
format!("[{}] {}%", token_d, percentage)
} }
(None, None, None) => format!("[{}]", token_d),
}; };
let status = format!("[{}] {}", token, msg);
if let lsp::WorkDoneProgress::End(_) = work {
self.lsp_progress.end_progress(server_id, &token);
} else {
self.lsp_progress.update(server_id, token, work);
}
self.editor.set_status(status); self.editor.set_status(status);
self.render(); self.render();
} }

Loading…
Cancel
Save