mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 12:54:58 +00:00
Do not drop ..Default::default()
completion when typing ..
This commit is contained in:
parent
f2246fecef
commit
e729529410
3 changed files with 84 additions and 49 deletions
|
@ -178,6 +178,38 @@ impl Default for Struct {
|
||||||
fn default() -> Self {}
|
fn default() -> Self {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn foo() {
|
||||||
|
let other = Struct {
|
||||||
|
foo: 5,
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
);
|
||||||
|
check_edit(
|
||||||
|
"..Default::default()",
|
||||||
|
r#"
|
||||||
|
//- minicore: default
|
||||||
|
struct Struct { foo: u32, bar: usize }
|
||||||
|
|
||||||
|
impl Default for Struct {
|
||||||
|
fn default() -> Self {}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn foo() {
|
||||||
|
let other = Struct {
|
||||||
|
foo: 5,
|
||||||
|
..$0
|
||||||
|
};
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
r#"
|
||||||
|
struct Struct { foo: u32, bar: usize }
|
||||||
|
|
||||||
|
impl Default for Struct {
|
||||||
|
fn default() -> Self {}
|
||||||
|
}
|
||||||
|
|
||||||
fn foo() {
|
fn foo() {
|
||||||
let other = Struct {
|
let other = Struct {
|
||||||
foo: 5,
|
foo: 5,
|
||||||
|
|
|
@ -191,6 +191,7 @@ pub(crate) fn determine_location(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let res = match_ast! {
|
let res = match_ast! {
|
||||||
match parent {
|
match parent {
|
||||||
ast::IdentPat(_it) => ImmediateLocation::IdentPat,
|
ast::IdentPat(_it) => ImmediateLocation::IdentPat,
|
||||||
|
@ -206,6 +207,9 @@ pub(crate) fn determine_location(
|
||||||
} else {
|
} else {
|
||||||
ImmediateLocation::RecordField
|
ImmediateLocation::RecordField
|
||||||
},
|
},
|
||||||
|
ast::RecordExprFieldList(_it) => sema
|
||||||
|
.find_node_at_offset_with_macros(original_file, offset)
|
||||||
|
.map(ImmediateLocation::RecordExpr)?,
|
||||||
ast::TupleField(_it) => ImmediateLocation::TupleField,
|
ast::TupleField(_it) => ImmediateLocation::TupleField,
|
||||||
ast::TupleFieldList(_it) => ImmediateLocation::TupleField,
|
ast::TupleFieldList(_it) => ImmediateLocation::TupleField,
|
||||||
ast::TypeBound(_it) => ImmediateLocation::TypeBound,
|
ast::TypeBound(_it) => ImmediateLocation::TypeBound,
|
||||||
|
|
|
@ -7,36 +7,6 @@ fn check(ra_fixture: &str, expect: Expect) {
|
||||||
expect.assert_eq(&actual);
|
expect.assert_eq(&actual);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn with_default_impl() {
|
|
||||||
check(
|
|
||||||
r#"
|
|
||||||
//- minicore: default
|
|
||||||
struct Struct { foo: u32, bar: usize }
|
|
||||||
|
|
||||||
impl Default for Struct {
|
|
||||||
fn default() -> Self {
|
|
||||||
Struct {
|
|
||||||
foo: 0,
|
|
||||||
bar: 0,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn foo() {
|
|
||||||
let other = Struct {
|
|
||||||
foo: 5,
|
|
||||||
$0
|
|
||||||
};
|
|
||||||
}
|
|
||||||
"#,
|
|
||||||
expect![[r#"
|
|
||||||
fd ..Default::default()
|
|
||||||
fd bar usize
|
|
||||||
"#]],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn without_default_impl() {
|
fn without_default_impl() {
|
||||||
check(
|
check(
|
||||||
|
@ -129,9 +99,54 @@ fn foo(f: Struct) {
|
||||||
#[test]
|
#[test]
|
||||||
fn functional_update() {
|
fn functional_update() {
|
||||||
// FIXME: This should filter out all completions that do not have the type `Foo`
|
// FIXME: This should filter out all completions that do not have the type `Foo`
|
||||||
|
// FIXME: Fields should not show up after `.`
|
||||||
check(
|
check(
|
||||||
r#"
|
r#"
|
||||||
|
//- minicore:default
|
||||||
struct Foo { foo1: u32, foo2: u32 }
|
struct Foo { foo1: u32, foo2: u32 }
|
||||||
|
impl Default for Foo {
|
||||||
|
fn default() -> Self { loop {} }
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let thing = 1;
|
||||||
|
let foo = Foo { foo1: 0, foo2: 0 };
|
||||||
|
let foo2 = Foo { thing, $0 }
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
expect![[r#"
|
||||||
|
fd ..Default::default()
|
||||||
|
fd foo1 u32
|
||||||
|
fd foo2 u32
|
||||||
|
"#]],
|
||||||
|
);
|
||||||
|
check(
|
||||||
|
r#"
|
||||||
|
//- minicore:default
|
||||||
|
struct Foo { foo1: u32, foo2: u32 }
|
||||||
|
impl Default for Foo {
|
||||||
|
fn default() -> Self { loop {} }
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let thing = 1;
|
||||||
|
let foo = Foo { foo1: 0, foo2: 0 };
|
||||||
|
let foo2 = Foo { thing, .$0 }
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
expect![[r#"
|
||||||
|
fd ..Default::default()
|
||||||
|
fd foo1 u32
|
||||||
|
fd foo2 u32
|
||||||
|
"#]],
|
||||||
|
);
|
||||||
|
check(
|
||||||
|
r#"
|
||||||
|
//- minicore:default
|
||||||
|
struct Foo { foo1: u32, foo2: u32 }
|
||||||
|
impl Default for Foo {
|
||||||
|
fn default() -> Self { loop {} }
|
||||||
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let thing = 1;
|
let thing = 1;
|
||||||
|
@ -140,25 +155,9 @@ fn main() {
|
||||||
}
|
}
|
||||||
"#,
|
"#,
|
||||||
expect![[r#"
|
expect![[r#"
|
||||||
kw unsafe
|
fd ..Default::default()
|
||||||
kw match
|
fd foo1 u32
|
||||||
kw while
|
fd foo2 u32
|
||||||
kw while let
|
|
||||||
kw loop
|
|
||||||
kw if
|
|
||||||
kw if let
|
|
||||||
kw for
|
|
||||||
kw true
|
|
||||||
kw false
|
|
||||||
kw return
|
|
||||||
kw self
|
|
||||||
kw super
|
|
||||||
kw crate
|
|
||||||
lc foo Foo
|
|
||||||
lc thing i32
|
|
||||||
st Foo
|
|
||||||
fn main() fn()
|
|
||||||
bt u32
|
|
||||||
"#]],
|
"#]],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue