mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-13 21:54:42 +00:00
Merge #9862
9862: internal: Fill out expected type for functional update syntax completion r=Veykril a=Veykril Last part of https://github.com/rust-analyzer/rust-analyzer/issues/9839 bors r+ Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
This commit is contained in:
commit
2511e1bc35
2 changed files with 40 additions and 10 deletions
|
@ -480,18 +480,30 @@ impl<'a> CompletionContext<'a> {
|
||||||
})
|
})
|
||||||
.unwrap_or((None, None))
|
.unwrap_or((None, None))
|
||||||
},
|
},
|
||||||
ast::RecordExprFieldList(_it) => {
|
ast::RecordExprFieldList(it) => {
|
||||||
cov_mark::hit!(expected_type_struct_field_without_leading_char);
|
|
||||||
// wouldn't try {} be nice...
|
// wouldn't try {} be nice...
|
||||||
(|| {
|
(|| {
|
||||||
let expr_field = self.token.prev_sibling_or_token()?
|
if self.token.kind() == T![..]
|
||||||
.into_node()
|
|| self.token.prev_token().map(|t| t.kind()) == Some(T![..])
|
||||||
.and_then(ast::RecordExprField::cast)?;
|
{
|
||||||
let (_, _, ty) = self.sema.resolve_record_field(&expr_field)?;
|
cov_mark::hit!(expected_type_struct_func_update);
|
||||||
Some((
|
let record_expr = it.syntax().parent().and_then(ast::RecordExpr::cast)?;
|
||||||
Some(ty),
|
let ty = self.sema.type_of_expr(&record_expr.into())?;
|
||||||
expr_field.field_name().map(NameOrNameRef::NameRef),
|
Some((
|
||||||
))
|
Some(ty.original),
|
||||||
|
None
|
||||||
|
))
|
||||||
|
} else {
|
||||||
|
cov_mark::hit!(expected_type_struct_field_without_leading_char);
|
||||||
|
let expr_field = self.token.prev_sibling_or_token()?
|
||||||
|
.into_node()
|
||||||
|
.and_then(ast::RecordExprField::cast)?;
|
||||||
|
let (_, _, ty) = self.sema.resolve_record_field(&expr_field)?;
|
||||||
|
Some((
|
||||||
|
Some(ty),
|
||||||
|
expr_field.field_name().map(NameOrNameRef::NameRef),
|
||||||
|
))
|
||||||
|
}
|
||||||
})().unwrap_or((None, None))
|
})().unwrap_or((None, None))
|
||||||
},
|
},
|
||||||
ast::RecordExprField(it) => {
|
ast::RecordExprField(it) => {
|
||||||
|
@ -533,6 +545,7 @@ impl<'a> CompletionContext<'a> {
|
||||||
.unwrap_or((None, None))
|
.unwrap_or((None, None))
|
||||||
},
|
},
|
||||||
ast::Stmt(_it) => (None, None),
|
ast::Stmt(_it) => (None, None),
|
||||||
|
ast::Item(__) => (None, None),
|
||||||
_ => {
|
_ => {
|
||||||
match node.parent() {
|
match node.parent() {
|
||||||
Some(n) => {
|
Some(n) => {
|
||||||
|
@ -1091,4 +1104,20 @@ impl<T> S<T> {
|
||||||
expect![[r#"ty: u32, name: t"#]],
|
expect![[r#"ty: u32, name: t"#]],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn expected_type_functional_update() {
|
||||||
|
cov_mark::check!(expected_type_struct_func_update);
|
||||||
|
check_expected_type_and_name(
|
||||||
|
r#"
|
||||||
|
struct Foo { field: u32 }
|
||||||
|
fn foo() {
|
||||||
|
Foo {
|
||||||
|
..$0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
expect![[r#"ty: Foo, name: ?"#]],
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -179,6 +179,7 @@ fn main() {
|
||||||
fd ..Default::default()
|
fd ..Default::default()
|
||||||
fd foo1 u32
|
fd foo1 u32
|
||||||
fd foo2 u32
|
fd foo2 u32
|
||||||
|
sn Foo {…} Foo { foo1: ${1:()}, foo2: ${2:()} }$0
|
||||||
"#]],
|
"#]],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue