aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwojciechkepka2021-06-18 03:43:44 +0000
committerBlaž Hrastnik2021-06-18 08:42:38 +0000
commit612511dc9859cb232b6c84b8d50461f5d181c9dc (patch)
tree98cb8994b5a3ca93f5f3edfd0e25e49adcba6325
parente1109a5a010d02b34c2a8f68726fcdae47d44f2d (diff)
Handle workDoneProgress/create request
-rw-r--r--helix-term/src/application.rs100
1 files changed, 76 insertions, 24 deletions
diff --git a/helix-term/src/application.rs b/helix-term/src/application.rs
index 80b9655a..b2b49be5 100644
--- a/helix-term/src/application.rs
+++ b/helix-term/src/application.rs
@@ -253,45 +253,45 @@ impl Application {
let lsp::ProgressParamsValue::WorkDone(work) = value;
let parts = match &work {
- lsp::WorkDoneProgress::Begin(lsp::WorkDoneProgressBegin {
- title,
- message,
- percentage,
- ..
+ lsp::WorkDoneProgress::Begin(lsp::WorkDoneProgressBegin {
+ title,
+ message,
+ percentage,
+ ..
}) => (Some(title), message, percentage),
- lsp::WorkDoneProgress::Report(lsp::WorkDoneProgressReport {
- message,
- percentage,
- ..
+ lsp::WorkDoneProgress::Report(lsp::WorkDoneProgressReport {
+ message,
+ percentage,
+ ..
}) => (None, message, percentage),
lsp::WorkDoneProgress::End(lsp::WorkDoneProgressEnd { message }) => {
if message.is_some() {
(None, message, &None)
- } else {
+ } else {
self.lsp_progress.end_progress(server_id, &token);
- self.editor.clear_status();
- return;
- }
+ self.editor.clear_status();
+ return;
}
- };
+ }
+ };
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!("[{}] {}% {} - {}", token_d, percentage, title, message)
- }
- (Some(title), None, Some(percentage)) => {
+ }
+ (Some(title), None, Some(percentage)) => {
format!("[{}] {}% {}", token_d, percentage, title)
- }
- (Some(title), Some(message), None) => {
+ }
+ (Some(title), Some(message), None) => {
format!("[{}] {} - {}", token_d, title, message)
- }
- (None, Some(message), Some(percentage)) => {
+ }
+ (None, Some(message), Some(percentage)) => {
format!("[{}] {}% {}", token_d, percentage, message)
- }
+ }
(Some(title), None, None) => {
format!("[{}] {}", token_d, title)
}
@@ -316,9 +316,61 @@ impl Application {
_ => unreachable!(),
}
}
- Call::MethodCall(call) => {
- error!("Method not found {}", call.method);
+ Call::MethodCall(helix_lsp::jsonrpc::MethodCall {
+ method,
+ params,
+ jsonrpc,
+ id,
+ }) => {
+ let call = match MethodCall::parse(&method, params) {
+ Some(call) => call,
+ None => {
+ error!("Method not found {}", method);
+ return;
+ }
+ };
+ match call {
+ MethodCall::WorkDoneProgressCreate(params) => {
+ self.lsp_progress.create(server_id, params.token);
+
+ let doc = self.editor.documents().find(|doc| {
+ doc.language_server()
+ .map(|server| server.id() == server_id)
+ .unwrap_or_default()
+ });
+ match doc {
+ Some(doc) => {
+ // it's ok to unwrap, we check for the language server before
+ let server = doc.language_server().unwrap();
+ tokio::spawn(server.reply(id, Ok(serde_json::Value::Null)));
+ }
+ None => {
+ if let Some(server) =
+ self.editor.language_servers.get_by_id(server_id)
+ {
+ log::warn!(
+ "missing document with language server id `{}`",
+ server_id
+ );
+ tokio::spawn(server.reply(
+ id,
+ Err(helix_lsp::jsonrpc::Error {
+ code: helix_lsp::jsonrpc::ErrorCode::InternalError,
+ message: "document missing".to_string(),
+ data: None,
+ }),
+ ));
+ } else {
+ log::warn!(
+ "can't find language server with id `{}`",
+ server_id
+ );
+ }
+ }
+ }
+ }
+ }
// self.language_server.reply(
// call.id,
// // TODO: make a Into trait that can cast to Err(jsonrpc::Error)