diff options
| author | bors <bors@rust-lang.org> | 2023-01-04 18:38:34 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-01-04 18:38:34 +0000 |
| commit | 80cabf726068187d8686b5ccf37aac484da84904 (patch) | |
| tree | aa4591ba5b808c76a7003d459854b4c9430bd8c6 | |
| parent | a97c71f92d574cb5104e3e1246eb9038d1a214a2 (diff) | |
| parent | 150da92b5c6e4a8dc3c27f24864de471c2b2c380 (diff) | |
| download | rust-80cabf726068187d8686b5ccf37aac484da84904.tar.gz rust-80cabf726068187d8686b5ccf37aac484da84904.zip | |
Auto merge of #13893 - ntBre:master, r=lnicola
Complete record enum variants without parens when snippets are disabled I didn't realize I only handled this for tuple variants in #13805. This is the same change but for record variants.
| -rw-r--r-- | crates/ide-completion/src/completions/record.rs | 31 | ||||
| -rw-r--r-- | crates/ide-completion/src/render/variant.rs | 3 |
2 files changed, 33 insertions, 1 deletions
diff --git a/crates/ide-completion/src/completions/record.rs b/crates/ide-completion/src/completions/record.rs index 6743ec897f0..0521e735ded 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 { @@ -184,6 +185,34 @@ impl Enum { } } "#, + ); + + // 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 f3e88489f46..55c55725be4 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)) |
