From a2950fcb052b624c8971f668d61e70c176defe99 Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Wed, 24 Mar 2021 15:01:37 +0800 Subject: [PATCH] Trim down IPC json size --- crates/proc_macro_api/src/rpc.rs | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/crates/proc_macro_api/src/rpc.rs b/crates/proc_macro_api/src/rpc.rs index 9a68e2cc51..8f7270afeb 100644 --- a/crates/proc_macro_api/src/rpc.rs +++ b/crates/proc_macro_api/src/rpc.rs @@ -77,7 +77,11 @@ struct TokenIdDef(u32); #[derive(Serialize, Deserialize)] #[serde(remote = "Delimiter")] struct DelimiterDef { - #[serde(with = "TokenIdDef")] + #[serde( + with = "TokenIdDef", + default = "tt::TokenId::unspecified", + skip_serializing_if = "token_id_def::skip_if" + )] id: TokenId, #[serde(with = "DelimiterKindDef")] kind: DelimiterKind, @@ -116,7 +120,11 @@ enum LeafDef { #[serde(remote = "Literal")] struct LiteralDef { text: SmolStr, - #[serde(with = "TokenIdDef")] + #[serde( + with = "TokenIdDef", + default = "tt::TokenId::unspecified", + skip_serializing_if = "token_id_def::skip_if" + )] id: TokenId, } @@ -126,7 +134,11 @@ struct PunctDef { char: char, #[serde(with = "SpacingDef")] spacing: Spacing, - #[serde(with = "TokenIdDef")] + #[serde( + with = "TokenIdDef", + default = "tt::TokenId::unspecified", + skip_serializing_if = "token_id_def::skip_if" + )] id: TokenId, } @@ -141,10 +153,20 @@ enum SpacingDef { #[serde(remote = "Ident")] struct IdentDef { text: SmolStr, - #[serde(with = "TokenIdDef")] + #[serde( + with = "TokenIdDef", + default = "tt::TokenId::unspecified", + skip_serializing_if = "token_id_def::skip_if" + )] id: TokenId, } +mod token_id_def { + pub(super) fn skip_if(value: &tt::TokenId) -> bool { + *value == tt::TokenId::unspecified() + } +} + mod opt_delimiter_def { use super::{Delimiter, DelimiterDef}; use serde::{Deserialize, Deserializer, Serialize, Serializer};