diff options
| author | Lukas Wirth <lukastw97@gmail.com> | 2024-12-16 11:14:56 +0100 |
|---|---|---|
| committer | Lukas Wirth <lukastw97@gmail.com> | 2024-12-16 11:25:29 +0100 |
| commit | 5c678215dd52e20efade9b69d949fbdc7a1ccd50 (patch) | |
| tree | 28ad1d4d82973ee534fc142dd010b397708bca82 /src/tools/rust-analyzer | |
| parent | 5c6bae0fc0930d57dba2e279c0b67a4397b3999c (diff) | |
| download | rust-5c678215dd52e20efade9b69d949fbdc7a1ccd50.tar.gz rust-5c678215dd52e20efade9b69d949fbdc7a1ccd50.zip | |
internal: Don't serialize empty fields in completions and resolve payloads
Diffstat (limited to 'src/tools/rust-analyzer')
3 files changed, 12 insertions, 4 deletions
diff --git a/src/tools/rust-analyzer/crates/rust-analyzer/src/lsp/ext.rs b/src/tools/rust-analyzer/crates/rust-analyzer/src/lsp/ext.rs index df06270a8b1..c0173d9c247 100644 --- a/src/tools/rust-analyzer/crates/rust-analyzer/src/lsp/ext.rs +++ b/src/tools/rust-analyzer/crates/rust-analyzer/src/lsp/ext.rs @@ -823,8 +823,11 @@ impl Request for OnTypeFormatting { #[derive(Debug, Serialize, Deserialize)] pub struct CompletionResolveData { pub position: lsp_types::TextDocumentPositionParams, + #[serde(skip_serializing_if = "Vec::is_empty", default)] pub imports: Vec<CompletionImport>, + #[serde(skip_serializing_if = "Option::is_none", default)] pub version: Option<i32>, + #[serde(skip_serializing_if = "Option::is_none", default)] pub trigger_character: Option<char>, pub for_ref: bool, pub hash: String, @@ -836,6 +839,7 @@ pub struct InlayHintResolveData { // This is a string instead of a u64 as javascript can't represent u64 fully pub hash: String, pub resolve_range: lsp_types::Range, + #[serde(skip_serializing_if = "Option::is_none", default)] pub version: Option<i32>, } diff --git a/src/tools/rust-analyzer/crates/rust-analyzer/src/lsp/to_proto.rs b/src/tools/rust-analyzer/crates/rust-analyzer/src/lsp/to_proto.rs index 612cb547b41..c3e7543d921 100644 --- a/src/tools/rust-analyzer/crates/rust-analyzer/src/lsp/to_proto.rs +++ b/src/tools/rust-analyzer/crates/rust-analyzer/src/lsp/to_proto.rs @@ -2,6 +2,7 @@ use std::{ iter::once, mem, + ops::Not as _, sync::atomic::{AtomicU32, Ordering}, }; @@ -358,9 +359,12 @@ fn completion_item( filter_text, kind: Some(completion_item_kind(item.kind)), text_edit, - additional_text_edits: Some(additional_text_edits), + additional_text_edits: additional_text_edits + .is_empty() + .not() + .then_some(additional_text_edits), documentation, - deprecated: Some(item.deprecated), + deprecated: item.deprecated.then_some(item.deprecated), tags, command, insert_text_format, @@ -370,7 +374,7 @@ fn completion_item( if config.completion_label_details_support() { if fields_to_resolve.resolve_label_details { something_to_resolve |= true; - } else { + } else if item.label_detail.is_some() || item.detail.is_some() { lsp_item.label_details = Some(lsp_types::CompletionItemLabelDetails { detail: item.label_detail.as_ref().map(ToString::to_string), description: item.detail.clone(), diff --git a/src/tools/rust-analyzer/docs/dev/lsp-extensions.md b/src/tools/rust-analyzer/docs/dev/lsp-extensions.md index 2aad2cfa361..0e37611a549 100644 --- a/src/tools/rust-analyzer/docs/dev/lsp-extensions.md +++ b/src/tools/rust-analyzer/docs/dev/lsp-extensions.md @@ -1,5 +1,5 @@ <!--- -lsp/ext.rs hash: 14b7fb1309f5bb00 +lsp/ext.rs hash: 9790509d87670c22 If you need to change the above hash to make the test pass, please check if you need to adjust this doc as well and ping this issue: |
