From 5ad757ed48bdb035b6fd4f52a05c73a8cdd1d87a Mon Sep 17 00:00:00 2001
From: "gcp-cherry-pick-bot[bot]"
<98988430+gcp-cherry-pick-bot[bot]@users.noreply.github.com>
Date: Thu, 23 Jan 2025 15:57:29 +0200
Subject: [PATCH] Fix LSP violation when dismissing server notifications
(cherry-pick #23531) (#23536)
Cherry-picked Fix LSP violation when dismissing server notifications
(#23531)
Part of https://github.com/zed-industries/zed/issues/22606
Closes https://github.com/zed-industries/zed/issues/23509
When a user sees an odd notification from the language server like
they usually dismiss that.
Zed uses channels to wait and handle user interactions with such
notifications, and, due to `?`, sends back
```json
{"jsonrpc":"2.0","id":1,"error":{"message":"receiving from an empty and closed channel"}}
```
which is not spec-compliant:
https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#window_showMessageRequest
> Response:
>
> * result: the selected
[MessageActionItem](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#messageActionItem)
| null if none got selected.
> * error: code and message set in case an exception happens during
showing a message.
Unfortunately, vtsls (and, potentially, others) crash if receive such
non-compliant requests, and do not get back.
After the fix, the message is correct:
```json
{"jsonrpc":"2.0","id":1,"result":null}
```
Release Notes:
- Fixed vtsls crashing on notification dismiss
Co-authored-by: Piotr Osiewicz
Co-authored-by: Kirill Bulatov
Co-authored-by: Piotr Osiewicz
---
crates/project/src/lsp_store.rs | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/crates/project/src/lsp_store.rs b/crates/project/src/lsp_store.rs
index 7ae1c57b5f07ac7cec9c0f73897fa0601a19e0e0..55598336a67129ca22e2cc5a1417e7c53ff16ecf 100644
--- a/crates/project/src/lsp_store.rs
+++ b/crates/project/src/lsp_store.rs
@@ -858,9 +858,8 @@ impl LocalLspStore {
})
.is_ok();
if did_update {
- let response = rx.recv().await?;
-
- Ok(Some(response))
+ let response = rx.recv().await.ok();
+ Ok(response)
} else {
Ok(None)
}