From c4680e66ffc36c65f63089ced1cb802853e5da3e Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Thu, 13 Oct 2022 11:10:23 +0200 Subject: [PATCH] Fix error on clangd when `compile-commands.json` is present The language server was failing because we were forgetting to provide a `jsonrpc` field for responses to requests coming from the lsp. --- crates/lsp/src/lsp.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/crates/lsp/src/lsp.rs b/crates/lsp/src/lsp.rs index 95ef299c72ecbadb342764423cfab611aeb8a9be..6e7def92e9ec98a4e157ac875db6b6f769898639 100644 --- a/crates/lsp/src/lsp.rs +++ b/crates/lsp/src/lsp.rs @@ -56,7 +56,7 @@ pub struct Subscription { #[derive(Serialize, Deserialize)] struct Request<'a, T> { - jsonrpc: &'a str, + jsonrpc: &'static str, id: usize, method: &'a str, params: T, @@ -73,6 +73,7 @@ struct AnyResponse<'a> { #[derive(Serialize)] struct Response { + jsonrpc: &'static str, id: usize, result: Option, error: Option, @@ -80,8 +81,7 @@ struct Response { #[derive(Serialize, Deserialize)] struct Notification<'a, T> { - #[serde(borrow)] - jsonrpc: &'a str, + jsonrpc: &'static str, #[serde(borrow)] method: &'a str, params: T, @@ -453,11 +453,13 @@ impl LanguageServer { async move { let response = match response.await { Ok(result) => Response { + jsonrpc: JSON_RPC_VERSION, id, result: Some(result), error: None, }, Err(error) => Response { + jsonrpc: JSON_RPC_VERSION, id, result: None, error: Some(Error {