Skip to content

Commit

Permalink
No need for a macro
Browse files Browse the repository at this point in the history
  • Loading branch information
vv9k committed Jun 16, 2021
1 parent 577e178 commit 5bc5816
Showing 1 changed file with 13 additions and 26 deletions.
39 changes: 13 additions & 26 deletions helix-term/src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,18 +250,6 @@ impl Application {
Notification::ProgressMessage(params) => {
let lsp::ProgressParams { token, value } = params;

// helper macro so that we don't have to allocate a string for the inner
// value
macro_rules! unwrap_token {
($tok:ident) => {{
let x: &dyn std::fmt::Display = match &$tok {
lsp::NumberOrString::Number(n) => n,
lsp::NumberOrString::String(s) => s,
};
x
}};
}

let lsp::ProgressParamsValue::WorkDone(work) = value;
let parts = match &work {
lsp::WorkDoneProgress::Begin(lsp::WorkDoneProgressBegin {
Expand All @@ -285,35 +273,34 @@ impl Application {
}
}
};
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)) => {
format!(
"[{}] {}% {} - {}",
unwrap_token!(token),
percentage,
title,
message
)
format!("[{}] {}% {} - {}", token_d, percentage, title, message)
}
(Some(title), None, Some(percentage)) => {
format!("[{}] {}% {}", unwrap_token!(token), percentage, title)
format!("[{}] {}% {}", token_d, percentage, title)
}
(Some(title), Some(message), None) => {
format!("[{}] {} - {}", unwrap_token!(token), title, message)
format!("[{}] {} - {}", token_d, title, message)
}
(None, Some(message), Some(percentage)) => {
format!("[{}] {}% {}", unwrap_token!(token), percentage, message)
format!("[{}] {}% {}", token_d, percentage, message)
}
(Some(title), None, None) => {
format!("[{}] {}", unwrap_token!(token), title)
format!("[{}] {}", token_d, title)
}
(None, Some(message), None) => {
format!("[{}] {}", unwrap_token!(token), message)
format!("[{}] {}", token_d, message)
}
(None, None, Some(percentage)) => {
format!("[{}] {}%", unwrap_token!(token), percentage)
format!("[{}] {}%", token_d, percentage)
}
(None, None, None) => format!("[{}]", unwrap_token!(token)),
(None, None, None) => format!("[{}]", token_d),
};

if let lsp::WorkDoneProgress::End(_) = work {
Expand Down

0 comments on commit 5bc5816

Please sign in to comment.