From 2a4ba4295b3bb53e672cb2dded2247a5553cf089 Mon Sep 17 00:00:00 2001 From: Niklas Lindorfer Date: Mon, 4 Mar 2024 18:14:25 +0000 Subject: [PATCH] fix: hide destructure_struct_binding assist if no public fields --- .../handlers/destructure_struct_binding.rs | 27 +++++++++++++------ crates/syntax/src/ast/make.rs | 5 +++- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/crates/ide-assists/src/handlers/destructure_struct_binding.rs b/crates/ide-assists/src/handlers/destructure_struct_binding.rs index 4edc52b614ab..c1a3f9302650 100644 --- a/crates/ide-assists/src/handlers/destructure_struct_binding.rs +++ b/crates/ide-assists/src/handlers/destructure_struct_binding.rs @@ -107,6 +107,10 @@ fn collect_data(ident_pat: ast::IdentPat, ctx: &AssistContext<'_>) -> Option ast::RecordPatFieldList { let mut fields = fields.into_iter().join(", "); if let Some(rest_pat) = rest_pat { - format_to!(fields, ", {rest_pat}"); + if !fields.is_empty() { + fields.push_str(", "); + } + format_to!(fields, "{rest_pat}"); } ast_from_text(&format!("fn f(S {{ {fields} }}: ()))")) }