File tree Expand file tree Collapse file tree 1 file changed +61
-0
lines changed
crates/ide-completion/src/completions Expand file tree Collapse file tree 1 file changed +61
-0
lines changed Original file line number Diff line number Diff line change @@ -89,6 +89,12 @@ pub(crate) fn complete_record_literal(
8989 . filter ( |it| it. len ( ) > 1 ) ;
9090
9191 acc. add_struct_literal ( ctx, strukt, path, None ) ;
92+
93+ let impl_ = ctx. impl_def . as_ref ( ) ?;
94+ let impl_adt = ctx. sema . to_def ( impl_) ?. self_ty ( ctx. db ) . as_adt ( ) ?;
95+ if hir:: Adt :: Struct ( strukt) == impl_adt {
96+ acc. add_struct_literal ( ctx, strukt, None , Some ( hir:: known:: SELF_TYPE ) ) ;
97+ }
9298 }
9399 hir:: Adt :: Union ( un) if ctx. path_qual ( ) . is_none ( ) => {
94100 let path = ctx
@@ -133,6 +139,61 @@ fn baz() {
133139 )
134140 }
135141
142+ #[ test]
143+ fn literal_struct_impl_self_completion ( ) {
144+ check_edit (
145+ "Self {…}" ,
146+ r#"
147+ struct Foo {
148+ bar: u64,
149+ }
150+
151+ impl Foo {
152+ fn new() -> Foo {
153+ Self$0
154+ }
155+ }
156+ "# ,
157+ r#"
158+ struct Foo {
159+ bar: u64,
160+ }
161+
162+ impl Foo {
163+ fn new() -> Foo {
164+ Self { bar: ${1:()} }$0
165+ }
166+ }
167+ "# ,
168+ ) ;
169+
170+ check_edit (
171+ "Self(…)" ,
172+ r#"
173+ mod submod {
174+ pub struct Foo(pub u64);
175+ }
176+
177+ impl submod::Foo {
178+ fn new() -> submod::Foo {
179+ Self$0
180+ }
181+ }
182+ "# ,
183+ r#"
184+ mod submod {
185+ pub struct Foo(pub u64);
186+ }
187+
188+ impl submod::Foo {
189+ fn new() -> submod::Foo {
190+ Self(${1:()})$0
191+ }
192+ }
193+ "# ,
194+ )
195+ }
196+
136197 #[ test]
137198 fn literal_struct_completion_from_sub_modules ( ) {
138199 check_edit (
You can’t perform that action at this time.
0 commit comments