Fix LSP show message macro to allow format args (#15487)

## Summary

This PR fixes the `show_*_msg` macros to pass all the tokens instead of
just a single token. This allows for using various expressions right in
the macro similar to how it would be in `format_args!`.

## Test Plan

`cargo clippy`
This commit is contained in:
Dhruv Manilawala 2025-01-15 13:41:49 +05:30 committed by GitHub
parent 18d5dbfb7f
commit 6aef4ad008
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 10 additions and 11 deletions

View file

@ -40,7 +40,7 @@ pub(super) fn try_show_message(
/// Sends an error to the client with a formatted message. The error is sent in a
/// `window/showMessage` notification.
macro_rules! show_err_msg {
($msg:expr$(, $($arg:tt),*)?) => {
crate::message::show_message(::core::format_args!($msg, $($($arg),*)?).to_string(), lsp_types::MessageType::ERROR)
($msg:expr$(, $($arg:tt)*)?) => {
crate::message::show_message(::core::format_args!($msg$(, $($arg)*)?).to_string(), lsp_types::MessageType::ERROR)
};
}

View file

@ -40,15 +40,15 @@ pub(super) fn try_show_message(
/// Sends a request to display an error to the client with a formatted message. The error is sent
/// in a `window/showMessage` notification.
macro_rules! show_err_msg {
($msg:expr$(, $($arg:tt),*)?) => {
crate::message::show_message(::core::format_args!($msg, $($($arg),*)?).to_string(), lsp_types::MessageType::ERROR)
($msg:expr$(, $($arg:tt)*)?) => {
crate::message::show_message(::core::format_args!($msg$(, $($arg)*)?).to_string(), lsp_types::MessageType::ERROR)
};
}
/// Sends a request to display a warning to the client with a formatted message. The warning is
/// sent in a `window/showMessage` notification.
macro_rules! show_warn_msg {
($msg:expr$(, $($arg:tt),*)?) => {
crate::message::show_message(::core::format_args!($msg, $($($arg),*)?).to_string(), lsp_types::MessageType::WARNING)
($msg:expr$(, $($arg:tt)*)?) => {
crate::message::show_message(::core::format_args!($msg$(, $($arg)*)?).to_string(), lsp_types::MessageType::WARNING)
};
}

View file

@ -186,10 +186,9 @@ impl RuffSettingsIndex {
// means for different editors.
if is_default_workspace {
if has_error {
let root = root.display();
show_err_msg!(
"Error while resolving settings from workspace {root}. \
Please refer to the logs for more details.",
"Error while resolving settings from workspace {}. Please refer to the logs for more details.",
root.display()
);
}
@ -300,9 +299,9 @@ impl RuffSettingsIndex {
});
if has_error.load(Ordering::Relaxed) {
let root = root.display();
show_err_msg!(
"Error while resolving settings from workspace {root}. Please refer to the logs for more details.",
"Error while resolving settings from workspace {}. Please refer to the logs for more details.",
root.display()
);
}