Skip to content

Commit

Permalink
return immediately from render_record_lit if snippet_cap is None
Browse files Browse the repository at this point in the history
this is the record literal version of rust-lang#13805, which handled the same issue for
tuple literals
  • Loading branch information
ntBre committed Jan 4, 2023
1 parent a97c71f commit 150da92
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
31 changes: 30 additions & 1 deletion crates/ide-completion/src/completions/record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions crates/ide-completion/src/render/variant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit 150da92

Please sign in to comment.