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.
This commit is contained in:
bors 2023-01-04 18:38:34 +00:00
commit 80cabf7260
2 changed files with 33 additions and 1 deletions

View file

@ -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

View file

@ -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))