-
Notifications
You must be signed in to change notification settings - Fork 2.2k
ruff server: Important errors are now shown as popups
#10951
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+81
−1
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a5daba2
Implement `showMessage` handler and `show_err_msg!` macro
snowsignal 6e0b6ca
Introduce `show_err_msg!` to significant error paths
snowsignal 97f24bb
Document `show_err_msg!`
snowsignal 6cec603
'error log' -> 'logs'
snowsignal 11c9136
Print panic message with tracing::error
snowsignal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,8 @@ mod edit; | |
| mod fix; | ||
| mod format; | ||
| mod lint; | ||
| #[macro_use] | ||
| mod message; | ||
| mod server; | ||
| mod session; | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| use std::sync::OnceLock; | ||
|
|
||
| use lsp_types::notification::Notification; | ||
|
|
||
| use crate::server::ClientSender; | ||
|
|
||
| static MESSENGER: OnceLock<ClientSender> = OnceLock::new(); | ||
|
|
||
| pub(crate) fn init_messenger(client_sender: &ClientSender) { | ||
| MESSENGER | ||
| .set(client_sender.clone()) | ||
| .expect("messenger should only be initialized once"); | ||
|
|
||
| // unregister any previously registered panic hook | ||
| let _ = std::panic::take_hook(); | ||
|
|
||
| // When we panic, try to notify the client. | ||
| std::panic::set_hook(Box::new(move |panic_info| { | ||
| if let Some(messenger) = MESSENGER.get() { | ||
| let _ = messenger.send(lsp_server::Message::Notification( | ||
| lsp_server::Notification { | ||
| method: lsp_types::notification::ShowMessage::METHOD.into(), | ||
| params: serde_json::to_value(lsp_types::ShowMessageParams { | ||
| typ: lsp_types::MessageType::ERROR, | ||
| message: String::from( | ||
| "The Ruff language server exited with a panic. See the logs for more details." | ||
| ), | ||
| }) | ||
| .unwrap_or_default(), | ||
| }, | ||
| )); | ||
| } | ||
|
|
||
| let backtrace = std::backtrace::Backtrace::force_capture(); | ||
| tracing::error!("{panic_info}\n{backtrace}"); | ||
| })); | ||
| } | ||
|
|
||
| pub(crate) fn show_message(message: String, message_type: lsp_types::MessageType) { | ||
| MESSENGER | ||
| .get() | ||
| .expect("messenger should be initialized") | ||
| .send(lsp_server::Message::Notification( | ||
| lsp_server::Notification { | ||
| method: lsp_types::notification::ShowMessage::METHOD.into(), | ||
| params: serde_json::to_value(lsp_types::ShowMessageParams { | ||
| typ: message_type, | ||
| message, | ||
| }) | ||
| .unwrap(), | ||
| }, | ||
| )) | ||
| .expect("message should send"); | ||
| } | ||
|
|
||
| /// Sends an error to the client with a formatted message. The error is sent in a | ||
| /// `window/showMessage` notification. | ||
| macro_rules! show_err_msg { | ||
|
snowsignal marked this conversation as resolved.
|
||
| ($msg:expr$(, $($arg:tt),*)?) => { | ||
| crate::message::show_message(::core::format_args!($msg, $($($arg),*)?).to_string(), lsp_types::MessageType::ERROR) | ||
| }; | ||
| } | ||
|
snowsignal marked this conversation as resolved.
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.