lsp: Display LSP progress messages (#216)
This commit is contained in:
parent
c0d32707d0
commit
098806ce2a
4 changed files with 70 additions and 4 deletions
|
@ -228,6 +228,10 @@ impl Client {
|
||||||
}),
|
}),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}),
|
}),
|
||||||
|
window: Some(lsp::WindowClientCapabilities {
|
||||||
|
work_done_progress: Some(true),
|
||||||
|
..Default::default()
|
||||||
|
}),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
trace: None,
|
trace: None,
|
||||||
|
|
|
@ -134,6 +134,7 @@ pub enum Notification {
|
||||||
PublishDiagnostics(lsp::PublishDiagnosticsParams),
|
PublishDiagnostics(lsp::PublishDiagnosticsParams),
|
||||||
ShowMessage(lsp::ShowMessageParams),
|
ShowMessage(lsp::ShowMessageParams),
|
||||||
LogMessage(lsp::LogMessageParams),
|
LogMessage(lsp::LogMessageParams),
|
||||||
|
ProgressMessage(lsp::ProgressParams),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Notification {
|
impl Notification {
|
||||||
|
@ -151,17 +152,20 @@ impl Notification {
|
||||||
}
|
}
|
||||||
|
|
||||||
lsp::notification::ShowMessage::METHOD => {
|
lsp::notification::ShowMessage::METHOD => {
|
||||||
let params: lsp::ShowMessageParams =
|
let params: lsp::ShowMessageParams = params.parse().ok()?;
|
||||||
params.parse().expect("Failed to parse ShowMessage params");
|
|
||||||
|
|
||||||
Self::ShowMessage(params)
|
Self::ShowMessage(params)
|
||||||
}
|
}
|
||||||
lsp::notification::LogMessage::METHOD => {
|
lsp::notification::LogMessage::METHOD => {
|
||||||
let params: lsp::LogMessageParams =
|
let params: lsp::LogMessageParams = params.parse().ok()?;
|
||||||
params.parse().expect("Failed to parse ShowMessage params");
|
|
||||||
|
|
||||||
Self::LogMessage(params)
|
Self::LogMessage(params)
|
||||||
}
|
}
|
||||||
|
lsp::notification::Progress::METHOD => {
|
||||||
|
let params: lsp::ProgressParams = params.parse().ok()?;
|
||||||
|
|
||||||
|
Self::ProgressMessage(params)
|
||||||
|
}
|
||||||
_ => {
|
_ => {
|
||||||
log::error!("unhandled LSP notification: {}", method);
|
log::error!("unhandled LSP notification: {}", method);
|
||||||
return None;
|
return None;
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
use helix_lsp::lsp;
|
||||||
use helix_view::{document::Mode, Document, Editor, Theme, View};
|
use helix_view::{document::Mode, Document, Editor, Theme, View};
|
||||||
|
|
||||||
use crate::{args::Args, compositor::Compositor, ui};
|
use crate::{args::Args, compositor::Compositor, ui};
|
||||||
|
@ -228,6 +229,59 @@ impl Application {
|
||||||
Notification::LogMessage(params) => {
|
Notification::LogMessage(params) => {
|
||||||
log::warn!("unhandled window/logMessage: {:?}", params);
|
log::warn!("unhandled window/logMessage: {:?}", params);
|
||||||
}
|
}
|
||||||
|
Notification::ProgressMessage(params) => {
|
||||||
|
let token = match params.token {
|
||||||
|
lsp::NumberOrString::Number(n) => n.to_string(),
|
||||||
|
lsp::NumberOrString::String(s) => s,
|
||||||
|
};
|
||||||
|
let msg = {
|
||||||
|
let lsp::ProgressParamsValue::WorkDone(work) = params.value;
|
||||||
|
let parts = match work {
|
||||||
|
lsp::WorkDoneProgress::Begin(lsp::WorkDoneProgressBegin {
|
||||||
|
title,
|
||||||
|
message,
|
||||||
|
percentage,
|
||||||
|
..
|
||||||
|
}) => (Some(title), message, percentage.map(|n| n.to_string())),
|
||||||
|
lsp::WorkDoneProgress::Report(lsp::WorkDoneProgressReport {
|
||||||
|
message,
|
||||||
|
percentage,
|
||||||
|
..
|
||||||
|
}) => (None, message, percentage.map(|n| n.to_string())),
|
||||||
|
lsp::WorkDoneProgress::End(lsp::WorkDoneProgressEnd {
|
||||||
|
message,
|
||||||
|
}) => {
|
||||||
|
if let Some(message) = message {
|
||||||
|
(None, Some(message), None)
|
||||||
|
} else {
|
||||||
|
self.editor.clear_status();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
match parts {
|
||||||
|
(Some(title), Some(message), Some(percentage)) => {
|
||||||
|
format!("{}% {} - {}", percentage, title, message)
|
||||||
|
}
|
||||||
|
(Some(title), None, Some(percentage)) => {
|
||||||
|
format!("{}% {}", percentage, title)
|
||||||
|
}
|
||||||
|
(Some(title), Some(message), None) => {
|
||||||
|
format!("{} - {}", title, message)
|
||||||
|
}
|
||||||
|
(None, Some(message), Some(percentage)) => {
|
||||||
|
format!("{}% {}", percentage, message)
|
||||||
|
}
|
||||||
|
(Some(title), None, None) => title,
|
||||||
|
(None, Some(message), None) => message,
|
||||||
|
(None, None, Some(percentage)) => format!("{}%", percentage),
|
||||||
|
(None, None, None) => "".into(),
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let status = format!("[{}] {}", token, msg);
|
||||||
|
self.editor.set_status(status);
|
||||||
|
self.render();
|
||||||
|
}
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,6 +66,10 @@ impl Editor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn clear_status(&mut self) {
|
||||||
|
self.status_msg = None;
|
||||||
|
}
|
||||||
|
|
||||||
pub fn set_status(&mut self, status: String) {
|
pub fn set_status(&mut self, status: String) {
|
||||||
self.status_msg = Some((status, Severity::Info));
|
self.status_msg = Some((status, Severity::Info));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue