aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWojciech Kępka2021-06-11 03:42:16 +0000
committerGitHub2021-06-11 03:42:16 +0000
commit098806ce2ab78155e102067c170fec42cd552e4a (patch)
tree49af62b4e3c2a086a4017c6d1569ceac75743f66
parentc0d32707d03d71434c290e18d6db18b3b2de3875 (diff)
lsp: Display LSP progress messages (#216)
-rw-r--r--helix-lsp/src/client.rs4
-rw-r--r--helix-lsp/src/lib.rs12
-rw-r--r--helix-term/src/application.rs54
-rw-r--r--helix-view/src/editor.rs4
4 files changed, 70 insertions, 4 deletions
diff --git a/helix-lsp/src/client.rs b/helix-lsp/src/client.rs
index c2ea11b8..fde9b018 100644
--- a/helix-lsp/src/client.rs
+++ b/helix-lsp/src/client.rs
@@ -228,6 +228,10 @@ impl Client {
}),
..Default::default()
}),
+ window: Some(lsp::WindowClientCapabilities {
+ work_done_progress: Some(true),
+ ..Default::default()
+ }),
..Default::default()
},
trace: None,
diff --git a/helix-lsp/src/lib.rs b/helix-lsp/src/lib.rs
index 6d40cf0a..08676066 100644
--- a/helix-lsp/src/lib.rs
+++ b/helix-lsp/src/lib.rs
@@ -134,6 +134,7 @@ pub enum Notification {
PublishDiagnostics(lsp::PublishDiagnosticsParams),
ShowMessage(lsp::ShowMessageParams),
LogMessage(lsp::LogMessageParams),
+ ProgressMessage(lsp::ProgressParams),
}
impl Notification {
@@ -151,17 +152,20 @@ impl Notification {
}
lsp::notification::ShowMessage::METHOD => {
- let params: lsp::ShowMessageParams =
- params.parse().expect("Failed to parse ShowMessage params");
+ let params: lsp::ShowMessageParams = params.parse().ok()?;
Self::ShowMessage(params)
}
lsp::notification::LogMessage::METHOD => {
- let params: lsp::LogMessageParams =
- params.parse().expect("Failed to parse ShowMessage params");
+ let params: lsp::LogMessageParams = params.parse().ok()?;
Self::LogMessage(params)
}
+ lsp::notification::Progress::METHOD => {
+ let params: lsp::ProgressParams = params.parse().ok()?;
+
+ Self::ProgressMessage(params)
+ }
_ => {
log::error!("unhandled LSP notification: {}", method);
return None;
diff --git a/helix-term/src/application.rs b/helix-term/src/application.rs
index 60c81607..bf829f2c 100644
--- a/helix-term/src/application.rs
+++ b/helix-term/src/application.rs
@@ -1,3 +1,4 @@
+use helix_lsp::lsp;
use helix_view::{document::Mode, Document, Editor, Theme, View};
use crate::{args::Args, compositor::Compositor, ui};
@@ -228,6 +229,59 @@ impl Application {
Notification::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!(),
}
}
diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs
index df71e2d6..bd53c53b 100644
--- a/helix-view/src/editor.rs
+++ b/helix-view/src/editor.rs
@@ -66,6 +66,10 @@ impl Editor {
}
}
+ pub fn clear_status(&mut self) {
+ self.status_msg = None;
+ }
+
pub fn set_status(&mut self, status: String) {
self.status_msg = Some((status, Severity::Info));
}