Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 5c67821

Browse files
committed
internal: Don't serialize empty fields in completions and resolve payloads
1 parent 5c6bae0 commit 5c67821

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

src/tools/rust-analyzer/crates/rust-analyzer/src/lsp/ext.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -823,8 +823,11 @@ impl Request for OnTypeFormatting {
823823
#[derive(Debug, Serialize, Deserialize)]
824824
pub struct CompletionResolveData {
825825
pub position: lsp_types::TextDocumentPositionParams,
826+
#[serde(skip_serializing_if = "Vec::is_empty", default)]
826827
pub imports: Vec<CompletionImport>,
828+
#[serde(skip_serializing_if = "Option::is_none", default)]
827829
pub version: Option<i32>,
830+
#[serde(skip_serializing_if = "Option::is_none", default)]
828831
pub trigger_character: Option<char>,
829832
pub for_ref: bool,
830833
pub hash: String,
@@ -836,6 +839,7 @@ pub struct InlayHintResolveData {
836839
// This is a string instead of a u64 as javascript can't represent u64 fully
837840
pub hash: String,
838841
pub resolve_range: lsp_types::Range,
842+
#[serde(skip_serializing_if = "Option::is_none", default)]
839843
pub version: Option<i32>,
840844
}
841845

src/tools/rust-analyzer/crates/rust-analyzer/src/lsp/to_proto.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
use std::{
33
iter::once,
44
mem,
5+
ops::Not as _,
56
sync::atomic::{AtomicU32, Ordering},
67
};
78

@@ -358,9 +359,12 @@ fn completion_item(
358359
filter_text,
359360
kind: Some(completion_item_kind(item.kind)),
360361
text_edit,
361-
additional_text_edits: Some(additional_text_edits),
362+
additional_text_edits: additional_text_edits
363+
.is_empty()
364+
.not()
365+
.then_some(additional_text_edits),
362366
documentation,
363-
deprecated: Some(item.deprecated),
367+
deprecated: item.deprecated.then_some(item.deprecated),
364368
tags,
365369
command,
366370
insert_text_format,
@@ -370,7 +374,7 @@ fn completion_item(
370374
if config.completion_label_details_support() {
371375
if fields_to_resolve.resolve_label_details {
372376
something_to_resolve |= true;
373-
} else {
377+
} else if item.label_detail.is_some() || item.detail.is_some() {
374378
lsp_item.label_details = Some(lsp_types::CompletionItemLabelDetails {
375379
detail: item.label_detail.as_ref().map(ToString::to_string),
376380
description: item.detail.clone(),

src/tools/rust-analyzer/docs/dev/lsp-extensions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!---
2-
lsp/ext.rs hash: 14b7fb1309f5bb00
2+
lsp/ext.rs hash: 9790509d87670c22
33
44
If you need to change the above hash to make the test pass, please check if you
55
need to adjust this doc as well and ping this issue:

0 commit comments

Comments
 (0)