From a12783cef73794c00a874f71b0f7f8dca34d7a2c Mon Sep 17 00:00:00 2001 From: Piotr Osiewicz <24362066+osiewicz@users.noreply.github.com> Date: Tue, 9 Jul 2024 20:12:05 +0200 Subject: [PATCH] lsp: Add support for ShowMessage notification (#14012) When "one newer language" sends these messages, "one newer editor" will display a pop-up for users to see. :) Related to https://github.com/gleam-lang/gleam/issues/3274 ![image](https://github.com/zed-industries/zed/assets/24362066/00d2c168-59f0-4033-91c8-af29c47516b3) Release Notes: - A certain popular language recently had to work around a missing LSP notification. This has been fixed --- crates/project/src/project.rs | 65 ++++++++++++++++++++++++----------- 1 file changed, 44 insertions(+), 21 deletions(-) diff --git a/crates/project/src/project.rs b/crates/project/src/project.rs index 4185281bd5c0ef15402f475754882adf8503175a..52253613afbb5845f22cbb4d0f9491af62ab27ba 100644 --- a/crates/project/src/project.rs +++ b/crates/project/src/project.rs @@ -3662,29 +3662,26 @@ impl Project { let this = this.clone(); let name = name.to_string(); async move { - if let Some(actions) = params.actions { - let (tx, mut rx) = smol::channel::bounded(1); - let request = LanguageServerPromptRequest { - level: match params.typ { - lsp::MessageType::ERROR => PromptLevel::Critical, - lsp::MessageType::WARNING => PromptLevel::Warning, - _ => PromptLevel::Info, - }, - message: params.message, - actions, - response_channel: tx, - lsp_name: name.clone(), - }; + let actions = params.actions.unwrap_or_default(); + let (tx, mut rx) = smol::channel::bounded(1); + let request = LanguageServerPromptRequest { + level: match params.typ { + lsp::MessageType::ERROR => PromptLevel::Critical, + lsp::MessageType::WARNING => PromptLevel::Warning, + _ => PromptLevel::Info, + }, + message: params.message, + actions, + response_channel: tx, + lsp_name: name.clone(), + }; - if let Ok(_) = this.update(&mut cx, |_, cx| { - cx.emit(Event::LanguageServerPrompt(request)); - }) { - let response = rx.next().await; + if let Ok(_) = this.update(&mut cx, |_, cx| { + cx.emit(Event::LanguageServerPrompt(request)); + }) { + let response = rx.next().await; - Ok(response) - } else { - Ok(None) - } + Ok(response) } else { Ok(None) } @@ -3739,7 +3736,33 @@ impl Project { } }) .detach(); + language_server + .on_notification::({ + let this = this.clone(); + let name = name.to_string(); + move |params, mut cx| { + let this = this.clone(); + let name = name.to_string(); + + let (tx, _) = smol::channel::bounded(1); + let request = LanguageServerPromptRequest { + level: match params.typ { + lsp::MessageType::ERROR => PromptLevel::Critical, + lsp::MessageType::WARNING => PromptLevel::Warning, + _ => PromptLevel::Info, + }, + message: params.message, + actions: vec![], + response_channel: tx, + lsp_name: name.clone(), + }; + let _ = this.update(&mut cx, |_, cx| { + cx.emit(Event::LanguageServerPrompt(request)); + }); + } + }) + .detach(); language_server .on_notification::(move |params, mut cx| { if let Some(this) = this.upgrade() {