Skip to content

Commit f6ef043

Browse files
bors[bot]Veykril
andauthored
Merge #9845
9845: fix: Do not drop `..Default::default()` completion when typing `..` r=Veykril a=Veykril cc #9839 bors r+ Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2 parents cb32011 + e729529 commit f6ef043

File tree

3 files changed

+84
-49
lines changed

3 files changed

+84
-49
lines changed

crates/ide_completion/src/completions/record.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,38 @@ impl Default for Struct {
178178
fn default() -> Self {}
179179
}
180180
181+
fn foo() {
182+
let other = Struct {
183+
foo: 5,
184+
..Default::default()
185+
};
186+
}
187+
"#,
188+
);
189+
check_edit(
190+
"..Default::default()",
191+
r#"
192+
//- minicore: default
193+
struct Struct { foo: u32, bar: usize }
194+
195+
impl Default for Struct {
196+
fn default() -> Self {}
197+
}
198+
199+
fn foo() {
200+
let other = Struct {
201+
foo: 5,
202+
..$0
203+
};
204+
}
205+
"#,
206+
r#"
207+
struct Struct { foo: u32, bar: usize }
208+
209+
impl Default for Struct {
210+
fn default() -> Self {}
211+
}
212+
181213
fn foo() {
182214
let other = Struct {
183215
foo: 5,

crates/ide_completion/src/patterns.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ pub(crate) fn determine_location(
191191
}
192192
}
193193
};
194+
194195
let res = match_ast! {
195196
match parent {
196197
ast::IdentPat(_it) => ImmediateLocation::IdentPat,
@@ -206,6 +207,9 @@ pub(crate) fn determine_location(
206207
} else {
207208
ImmediateLocation::RecordField
208209
},
210+
ast::RecordExprFieldList(_it) => sema
211+
.find_node_at_offset_with_macros(original_file, offset)
212+
.map(ImmediateLocation::RecordExpr)?,
209213
ast::TupleField(_it) => ImmediateLocation::TupleField,
210214
ast::TupleFieldList(_it) => ImmediateLocation::TupleField,
211215
ast::TypeBound(_it) => ImmediateLocation::TypeBound,

crates/ide_completion/src/tests/record.rs

Lines changed: 48 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -7,36 +7,6 @@ fn check(ra_fixture: &str, expect: Expect) {
77
expect.assert_eq(&actual);
88
}
99

10-
#[test]
11-
fn with_default_impl() {
12-
check(
13-
r#"
14-
//- minicore: default
15-
struct Struct { foo: u32, bar: usize }
16-
17-
impl Default for Struct {
18-
fn default() -> Self {
19-
Struct {
20-
foo: 0,
21-
bar: 0,
22-
}
23-
}
24-
}
25-
26-
fn foo() {
27-
let other = Struct {
28-
foo: 5,
29-
$0
30-
};
31-
}
32-
"#,
33-
expect![[r#"
34-
fd ..Default::default()
35-
fd bar usize
36-
"#]],
37-
);
38-
}
39-
4010
#[test]
4111
fn without_default_impl() {
4212
check(
@@ -129,9 +99,54 @@ fn foo(f: Struct) {
12999
#[test]
130100
fn functional_update() {
131101
// FIXME: This should filter out all completions that do not have the type `Foo`
102+
// FIXME: Fields should not show up after `.`
132103
check(
133104
r#"
105+
//- minicore:default
134106
struct Foo { foo1: u32, foo2: u32 }
107+
impl Default for Foo {
108+
fn default() -> Self { loop {} }
109+
}
110+
111+
fn main() {
112+
let thing = 1;
113+
let foo = Foo { foo1: 0, foo2: 0 };
114+
let foo2 = Foo { thing, $0 }
115+
}
116+
"#,
117+
expect![[r#"
118+
fd ..Default::default()
119+
fd foo1 u32
120+
fd foo2 u32
121+
"#]],
122+
);
123+
check(
124+
r#"
125+
//- minicore:default
126+
struct Foo { foo1: u32, foo2: u32 }
127+
impl Default for Foo {
128+
fn default() -> Self { loop {} }
129+
}
130+
131+
fn main() {
132+
let thing = 1;
133+
let foo = Foo { foo1: 0, foo2: 0 };
134+
let foo2 = Foo { thing, .$0 }
135+
}
136+
"#,
137+
expect![[r#"
138+
fd ..Default::default()
139+
fd foo1 u32
140+
fd foo2 u32
141+
"#]],
142+
);
143+
check(
144+
r#"
145+
//- minicore:default
146+
struct Foo { foo1: u32, foo2: u32 }
147+
impl Default for Foo {
148+
fn default() -> Self { loop {} }
149+
}
135150
136151
fn main() {
137152
let thing = 1;
@@ -140,25 +155,9 @@ fn main() {
140155
}
141156
"#,
142157
expect![[r#"
143-
kw unsafe
144-
kw match
145-
kw while
146-
kw while let
147-
kw loop
148-
kw if
149-
kw if let
150-
kw for
151-
kw true
152-
kw false
153-
kw return
154-
kw self
155-
kw super
156-
kw crate
157-
lc foo Foo
158-
lc thing i32
159-
st Foo
160-
fn main() fn()
161-
bt u32
158+
fd ..Default::default()
159+
fd foo1 u32
160+
fd foo2 u32
162161
"#]],
163162
);
164163
}

0 commit comments

Comments
 (0)