From 150da92b5c6e4a8dc3c27f24864de471c2b2c380 Mon Sep 17 00:00:00 2001 From: Brent Westbrook Date: Wed, 4 Jan 2023 12:55:05 -0500 Subject: [PATCH] return immediately from `render_record_lit` if `snippet_cap` is None this is the record literal version of #13805, which handled the same issue for tuple literals --- .../ide-completion/src/completions/record.rs | 31 ++++++++++++++++++- crates/ide-completion/src/render/variant.rs | 3 ++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/crates/ide-completion/src/completions/record.rs b/crates/ide-completion/src/completions/record.rs index 6743ec897f00b..0521e735dedf1 100644 --- a/crates/ide-completion/src/completions/record.rs +++ b/crates/ide-completion/src/completions/record.rs @@ -159,8 +159,9 @@ fn baz() { #[test] fn enum_variant_no_snippets() { let conf = CompletionConfig { snippet_cap: SnippetCap::new(false), ..TEST_CONFIG }; + // tuple variant check_edit_with_config( - conf, + conf.clone(), "Variant()", r#" enum Enum { @@ -178,6 +179,34 @@ enum Enum { Variant(usize), } +impl Enum { + fn new(u: usize) -> Self { + Self::Variant + } +} +"#, + ); + + // record variant + check_edit_with_config( + conf, + "Variant{}", + r#" +enum Enum { + Variant{u: usize}, +} + +impl Enum { + fn new(u: usize) -> Self { + Self::Va$0 + } +} +"#, + r#" +enum Enum { + Variant{u: usize}, +} + impl Enum { fn new(u: usize) -> Self { Self::Variant diff --git a/crates/ide-completion/src/render/variant.rs b/crates/ide-completion/src/render/variant.rs index f3e88489f46df..55c55725be4f9 100644 --- a/crates/ide-completion/src/render/variant.rs +++ b/crates/ide-completion/src/render/variant.rs @@ -22,6 +22,9 @@ pub(crate) fn render_record_lit( fields: &[hir::Field], path: &str, ) -> RenderedLiteral { + if snippet_cap.is_none() { + return RenderedLiteral { literal: path.to_string(), detail: path.to_string() }; + } let completions = fields.iter().enumerate().format_with(", ", |(idx, field), f| { if snippet_cap.is_some() { f(&format_args!("{}: ${{{}:()}}", field.name(db), idx + 1))