Skip to content

Commit 150da92

Browse files
committed
return immediately from render_record_lit if snippet_cap is None
this is the record literal version of rust-lang#13805, which handled the same issue for tuple literals
1 parent a97c71f commit 150da92

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

crates/ide-completion/src/completions/record.rs

+30-1
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,9 @@ fn baz() {
159159
#[test]
160160
fn enum_variant_no_snippets() {
161161
let conf = CompletionConfig { snippet_cap: SnippetCap::new(false), ..TEST_CONFIG };
162+
// tuple variant
162163
check_edit_with_config(
163-
conf,
164+
conf.clone(),
164165
"Variant()",
165166
r#"
166167
enum Enum {
@@ -178,6 +179,34 @@ enum Enum {
178179
Variant(usize),
179180
}
180181
182+
impl Enum {
183+
fn new(u: usize) -> Self {
184+
Self::Variant
185+
}
186+
}
187+
"#,
188+
);
189+
190+
// record variant
191+
check_edit_with_config(
192+
conf,
193+
"Variant{}",
194+
r#"
195+
enum Enum {
196+
Variant{u: usize},
197+
}
198+
199+
impl Enum {
200+
fn new(u: usize) -> Self {
201+
Self::Va$0
202+
}
203+
}
204+
"#,
205+
r#"
206+
enum Enum {
207+
Variant{u: usize},
208+
}
209+
181210
impl Enum {
182211
fn new(u: usize) -> Self {
183212
Self::Variant

crates/ide-completion/src/render/variant.rs

+3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ pub(crate) fn render_record_lit(
2222
fields: &[hir::Field],
2323
path: &str,
2424
) -> RenderedLiteral {
25+
if snippet_cap.is_none() {
26+
return RenderedLiteral { literal: path.to_string(), detail: path.to_string() };
27+
}
2528
let completions = fields.iter().enumerate().format_with(", ", |(idx, field), f| {
2629
if snippet_cap.is_some() {
2730
f(&format_args!("{}: ${{{}:()}}", field.name(db), idx + 1))

0 commit comments

Comments
 (0)