diff --git a/generator/plugins/rust/rust_enum.py b/generator/plugins/rust/rust_enum.py index c24a6de..e20265c 100644 --- a/generator/plugins/rust/rust_enum.py +++ b/generator/plugins/rust/rust_enum.py @@ -15,13 +15,19 @@ def _get_enum_docs(enum: Union[model.Enum, model.EnumItem]) -> List[str]: def generate_serde(enum: model.Enum) -> List[str]: - ser = [ + ser = [] + de = [] + if enum.proposed: + ser += ["#[cfg(feature = \"proposed\")]"] + de += ["#[cfg(feature = \"proposed\")]"] + + ser += [ f"impl Serialize for {enum.name} {{", "fn serialize(&self, serializer: S) -> Result where S: serde::Serializer,{", "match self {", ] - de = [ + de += [ f"impl<'de> Deserialize<'de> for {enum.name} {{", f"fn deserialize(deserializer: D) -> Result<{enum.name}, D::Error> where D: serde::Deserializer<'de>," "{", @@ -30,8 +36,12 @@ def generate_serde(enum: model.Enum) -> List[str]: ] for item in enum.values: full_name = f"{enum.name}::{to_upper_camel_case(item.name)}" + if item.proposed: + ser += ['#[cfg(feature = "proposed")]'] + de += ['#[cfg(feature = "proposed")]'] ser += [f"{full_name} => serializer.serialize_i32({item.value}),"] de += [f"{item.value} => Ok({full_name}),"] + ser += [ "}", # match "}", # fn diff --git a/generator/plugins/rust/rust_structs.py b/generator/plugins/rust/rust_structs.py index b6ca878..ec1f953 100644 --- a/generator/plugins/rust/rust_structs.py +++ b/generator/plugins/rust/rust_structs.py @@ -470,6 +470,7 @@ def generate_response( properties=properties, since=request_def.since, deprecated=request_def.deprecated, + proposed=request_def.proposed, ) inner = [] diff --git a/packages/rust/lsprotocol/src/lib.rs b/packages/rust/lsprotocol/src/lib.rs index e5a07b2..4323762 100644 --- a/packages/rust/lsprotocol/src/lib.rs +++ b/packages/rust/lsprotocol/src/lib.rs @@ -887,6 +887,7 @@ impl Serialize for MessageType { MessageType::Warning => serializer.serialize_i32(2), MessageType::Info => serializer.serialize_i32(3), MessageType::Log => serializer.serialize_i32(4), + #[cfg(feature = "proposed")] MessageType::Debug => serializer.serialize_i32(5), } } @@ -902,6 +903,7 @@ impl<'de> Deserialize<'de> for MessageType { 2 => Ok(MessageType::Warning), 3 => Ok(MessageType::Info), 4 => Ok(MessageType::Log), + #[cfg(feature = "proposed")] 5 => Ok(MessageType::Debug), _ => Err(serde::de::Error::custom("Unexpected value")), } @@ -1640,6 +1642,7 @@ pub enum InlineCompletionTriggerKind { /// Completion was triggered automatically while editing. Automatic = 2, } +#[cfg(feature = "proposed")] impl Serialize for InlineCompletionTriggerKind { fn serialize(&self, serializer: S) -> Result where @@ -1651,6 +1654,7 @@ impl Serialize for InlineCompletionTriggerKind { } } } +#[cfg(feature = "proposed")] impl<'de> Deserialize<'de> for InlineCompletionTriggerKind { fn deserialize(deserializer: D) -> Result where @@ -9996,6 +10000,7 @@ pub struct FoldingRangeRefreshRequest { } /// Response to the [FoldingRangeRefreshRequest]. +#[cfg(feature = "proposed")] #[derive(Serialize, Deserialize, PartialEq, Debug, Eq, Clone)] #[serde(rename_all = "camelCase", deny_unknown_fields)] pub struct FoldingRangeRefreshResponse { @@ -10977,6 +10982,7 @@ pub struct InlineCompletionRequest { } /// Response to the [InlineCompletionRequest]. +#[cfg(feature = "proposed")] #[derive(Serialize, Deserialize, PartialEq, Debug, Eq, Clone)] #[serde(rename_all = "camelCase", deny_unknown_fields)] pub struct InlineCompletionResponse { @@ -11015,6 +11021,7 @@ pub struct TextDocumentContentRequest { } /// Response to the [TextDocumentContentRequest]. +#[cfg(feature = "proposed")] #[derive(Serialize, Deserialize, PartialEq, Debug, Eq, Clone)] #[serde(rename_all = "camelCase", deny_unknown_fields)] pub struct TextDocumentContentResponse { @@ -11052,6 +11059,7 @@ pub struct TextDocumentContentRefreshRequest { } /// Response to the [TextDocumentContentRefreshRequest]. +#[cfg(feature = "proposed")] #[derive(Serialize, Deserialize, PartialEq, Debug, Eq, Clone)] #[serde(rename_all = "camelCase", deny_unknown_fields)] pub struct TextDocumentContentRefreshResponse { @@ -11957,6 +11965,7 @@ pub struct DocumentRangesFormattingRequest { } /// Response to the [DocumentRangesFormattingRequest]. +#[cfg(feature = "proposed")] #[derive(Serialize, Deserialize, PartialEq, Debug, Eq, Clone)] #[serde(rename_all = "camelCase", deny_unknown_fields)] pub struct DocumentRangesFormattingResponse {