mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-17 22:08:41 +00:00
Merge 6c290552a9
into c4fbb96421
This commit is contained in:
commit
36b9f33cb8
2 changed files with 40 additions and 6 deletions
|
@ -178,6 +178,33 @@ fn baz() {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn literal_struct_completion_shorthand() {
|
||||||
|
check_edit(
|
||||||
|
"FooDesc{}",
|
||||||
|
r#"
|
||||||
|
struct FooDesc { pub bar: bool, n: i32 }
|
||||||
|
|
||||||
|
fn create_foo(foo_desc: &FooDesc) -> () { () }
|
||||||
|
|
||||||
|
fn baz() {
|
||||||
|
let bar = true;
|
||||||
|
let foo = create_foo(&$0);
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
r#"
|
||||||
|
struct FooDesc { pub bar: bool, n: i32 }
|
||||||
|
|
||||||
|
fn create_foo(foo_desc: &FooDesc) -> () { () }
|
||||||
|
|
||||||
|
fn baz() {
|
||||||
|
let bar = true;
|
||||||
|
let foo = create_foo(&FooDesc { bar$1, n: ${2:()} }$0);
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn enum_variant_no_snippets() {
|
fn enum_variant_no_snippets() {
|
||||||
let conf = CompletionConfig { snippet_cap: SnippetCap::new(false), ..TEST_CONFIG };
|
let conf = CompletionConfig { snippet_cap: SnippetCap::new(false), ..TEST_CONFIG };
|
||||||
|
|
|
@ -26,14 +26,21 @@ pub(crate) fn render_record_lit(
|
||||||
return RenderedLiteral { literal: path.to_owned(), detail: path.to_owned() };
|
return RenderedLiteral { literal: path.to_owned(), detail: path.to_owned() };
|
||||||
}
|
}
|
||||||
let completions = fields.iter().enumerate().format_with(", ", |(idx, field), f| {
|
let completions = fields.iter().enumerate().format_with(", ", |(idx, field), f| {
|
||||||
|
let mut fmt_field = |fill, tab| {
|
||||||
|
let field_name = field.name(ctx.db);
|
||||||
|
|
||||||
|
if let Some(local) = ctx.locals.get(&field_name)
|
||||||
|
&& local.ty(ctx.db) == field.ty(ctx.db).to_type(ctx.db)
|
||||||
|
{
|
||||||
|
f(&format_args!("{}{tab}", field_name.display(ctx.db, ctx.edition)))
|
||||||
|
} else {
|
||||||
|
f(&format_args!("{}: {fill}", field_name.display(ctx.db, ctx.edition)))
|
||||||
|
}
|
||||||
|
};
|
||||||
if snippet_cap.is_some() {
|
if snippet_cap.is_some() {
|
||||||
f(&format_args!(
|
fmt_field(format_args!("${{{}:()}}", idx + 1), format_args!("${}", idx + 1))
|
||||||
"{}: ${{{}:()}}",
|
|
||||||
field.name(ctx.db).display(ctx.db, ctx.edition),
|
|
||||||
idx + 1
|
|
||||||
))
|
|
||||||
} else {
|
} else {
|
||||||
f(&format_args!("{}: ()", field.name(ctx.db).display(ctx.db, ctx.edition)))
|
fmt_field(format_args!("()"), format_args!(""))
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue