Skip to content

Commit 3e8f13d

Browse files
Merge #8182
8182: Trim down IPC json size r=edwin0cheng a=edwin0cheng This PR try to trim down the json of proc macro IPC by ignore token id if it equals to `TokenId::unspecifed`. Test by following commands: ```bash $ git clone https://github.com/gluon-lang/lsp-types.git $ export RA_LOG="proc_macro_api=debug" $ rust-analyzer -q analysis-stats --load-output-dirs --with-proc-macro . 2> debug.log $ cat debug.log | awk '/^\[DEBUG proc_macro_api::msg\] >/ {print substr($0,31)}' >expand.log $ stat -c "%s" expand.log ``` Before: 37576726 After: 28551718 So it trimed down 75%. bors r+ Co-authored-by: Edwin Cheng <[email protected]>
2 parents d702f10 + a2950fc commit 3e8f13d

File tree

1 file changed

+26
-4
lines changed
  • crates/proc_macro_api/src

1 file changed

+26
-4
lines changed

crates/proc_macro_api/src/rpc.rs

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,11 @@ struct TokenIdDef(u32);
7777
#[derive(Serialize, Deserialize)]
7878
#[serde(remote = "Delimiter")]
7979
struct DelimiterDef {
80-
#[serde(with = "TokenIdDef")]
80+
#[serde(
81+
with = "TokenIdDef",
82+
default = "tt::TokenId::unspecified",
83+
skip_serializing_if = "token_id_def::skip_if"
84+
)]
8185
id: TokenId,
8286
#[serde(with = "DelimiterKindDef")]
8387
kind: DelimiterKind,
@@ -116,7 +120,11 @@ enum LeafDef {
116120
#[serde(remote = "Literal")]
117121
struct LiteralDef {
118122
text: SmolStr,
119-
#[serde(with = "TokenIdDef")]
123+
#[serde(
124+
with = "TokenIdDef",
125+
default = "tt::TokenId::unspecified",
126+
skip_serializing_if = "token_id_def::skip_if"
127+
)]
120128
id: TokenId,
121129
}
122130

@@ -126,7 +134,11 @@ struct PunctDef {
126134
char: char,
127135
#[serde(with = "SpacingDef")]
128136
spacing: Spacing,
129-
#[serde(with = "TokenIdDef")]
137+
#[serde(
138+
with = "TokenIdDef",
139+
default = "tt::TokenId::unspecified",
140+
skip_serializing_if = "token_id_def::skip_if"
141+
)]
130142
id: TokenId,
131143
}
132144

@@ -141,10 +153,20 @@ enum SpacingDef {
141153
#[serde(remote = "Ident")]
142154
struct IdentDef {
143155
text: SmolStr,
144-
#[serde(with = "TokenIdDef")]
156+
#[serde(
157+
with = "TokenIdDef",
158+
default = "tt::TokenId::unspecified",
159+
skip_serializing_if = "token_id_def::skip_if"
160+
)]
145161
id: TokenId,
146162
}
147163

164+
mod token_id_def {
165+
pub(super) fn skip_if(value: &tt::TokenId) -> bool {
166+
*value == tt::TokenId::unspecified()
167+
}
168+
}
169+
148170
mod opt_delimiter_def {
149171
use super::{Delimiter, DelimiterDef};
150172
use serde::{Deserialize, Deserializer, Serialize, Serializer};

0 commit comments

Comments
 (0)