diff --git a/crates/lsp/src/lsp.rs b/crates/lsp/src/lsp.rs index 519883818c44bdc06b8fa4ac2e3db39d1e14719b..d1ce36c462181544bcf4c4dec26b4e4d3ee9ec2d 100644 --- a/crates/lsp/src/lsp.rs +++ b/crates/lsp/src/lsp.rs @@ -25,6 +25,7 @@ use smol::{ }; use std::{ + any::TypeId, collections::BTreeSet, ffi::{OsStr, OsString}, fmt, @@ -200,14 +201,22 @@ pub enum RequestId { Str(String), } +fn is_unit(_: &T) -> bool { + TypeId::of::() == TypeId::of::<()>() +} + /// Language server protocol RPC request message. /// /// [LSP Specification](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#requestMessage) #[derive(Serialize, Deserialize)] -pub struct Request<'a, T> { +pub struct Request<'a, T> +where + T: 'static, +{ jsonrpc: &'static str, id: RequestId, method: &'a str, + #[serde(default, skip_serializing_if = "is_unit")] params: T, } @@ -245,10 +254,14 @@ enum LspResult { /// /// [LSP Specification](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#notificationMessage) #[derive(Serialize, Deserialize)] -struct Notification<'a, T> { +struct Notification<'a, T> +where + T: 'static, +{ jsonrpc: &'static str, #[serde(borrow)] method: &'a str, + #[serde(default, skip_serializing_if = "is_unit")] params: T, }