internal: Don't serialize empty fields in completions and resolve payloads

This commit is contained in:
Lukas Wirth 2024-12-16 11:14:56 +01:00
parent 27e824fad4
commit de7808bb71
3 changed files with 12 additions and 4 deletions

View file

@ -823,8 +823,11 @@ impl Request for OnTypeFormatting {
#[derive(Debug, Serialize, Deserialize)] #[derive(Debug, Serialize, Deserialize)]
pub struct CompletionResolveData { pub struct CompletionResolveData {
pub position: lsp_types::TextDocumentPositionParams, pub position: lsp_types::TextDocumentPositionParams,
#[serde(skip_serializing_if = "Vec::is_empty", default)]
pub imports: Vec<CompletionImport>, pub imports: Vec<CompletionImport>,
#[serde(skip_serializing_if = "Option::is_none", default)]
pub version: Option<i32>, pub version: Option<i32>,
#[serde(skip_serializing_if = "Option::is_none", default)]
pub trigger_character: Option<char>, pub trigger_character: Option<char>,
pub for_ref: bool, pub for_ref: bool,
pub hash: String, 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 // This is a string instead of a u64 as javascript can't represent u64 fully
pub hash: String, pub hash: String,
pub resolve_range: lsp_types::Range, pub resolve_range: lsp_types::Range,
#[serde(skip_serializing_if = "Option::is_none", default)]
pub version: Option<i32>, pub version: Option<i32>,
} }

View file

@ -2,6 +2,7 @@
use std::{ use std::{
iter::once, iter::once,
mem, mem,
ops::Not as _,
sync::atomic::{AtomicU32, Ordering}, sync::atomic::{AtomicU32, Ordering},
}; };
@ -358,9 +359,12 @@ fn completion_item(
filter_text, filter_text,
kind: Some(completion_item_kind(item.kind)), kind: Some(completion_item_kind(item.kind)),
text_edit, text_edit,
additional_text_edits: Some(additional_text_edits), additional_text_edits: additional_text_edits
.is_empty()
.not()
.then_some(additional_text_edits),
documentation, documentation,
deprecated: Some(item.deprecated), deprecated: item.deprecated.then_some(item.deprecated),
tags, tags,
command, command,
insert_text_format, insert_text_format,
@ -370,7 +374,7 @@ fn completion_item(
if config.completion_label_details_support() { if config.completion_label_details_support() {
if fields_to_resolve.resolve_label_details { if fields_to_resolve.resolve_label_details {
something_to_resolve |= true; something_to_resolve |= true;
} else { } else if item.label_detail.is_some() || item.detail.is_some() {
lsp_item.label_details = Some(lsp_types::CompletionItemLabelDetails { lsp_item.label_details = Some(lsp_types::CompletionItemLabelDetails {
detail: item.label_detail.as_ref().map(ToString::to_string), detail: item.label_detail.as_ref().map(ToString::to_string),
description: item.detail.clone(), description: item.detail.clone(),

View file

@ -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 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: need to adjust this doc as well and ping this issue: