aboutsummaryrefslogtreecommitdiff
path: root/crates/ide_completion/src/completions/unqualified_path.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ide_completion/src/completions/unqualified_path.rs')
-rw-r--r--crates/ide_completion/src/completions/unqualified_path.rs48
1 files changed, 48 insertions, 0 deletions
diff --git a/crates/ide_completion/src/completions/unqualified_path.rs b/crates/ide_completion/src/completions/unqualified_path.rs
index 9db8516d0..573a39996 100644
--- a/crates/ide_completion/src/completions/unqualified_path.rs
+++ b/crates/ide_completion/src/completions/unqualified_path.rs
@@ -11,6 +11,7 @@ pub(crate) fn complete_unqualified_path(acc: &mut Completions, ctx: &CompletionC
11 if ctx.is_path_disallowed() || ctx.expects_item() { 11 if ctx.is_path_disallowed() || ctx.expects_item() {
12 return; 12 return;
13 } 13 }
14
14 if ctx.expects_assoc_item() { 15 if ctx.expects_assoc_item() {
15 ctx.scope.process_all_names(&mut |name, def| { 16 ctx.scope.process_all_names(&mut |name, def| {
16 if let ScopeDef::MacroDef(macro_def) = def { 17 if let ScopeDef::MacroDef(macro_def) = def {
@@ -32,6 +33,7 @@ pub(crate) fn complete_unqualified_path(acc: &mut Completions, ctx: &CompletionC
32 }); 33 });
33 return; 34 return;
34 } 35 }
36
35 if let Some(hir::Adt::Enum(e)) = 37 if let Some(hir::Adt::Enum(e)) =
36 ctx.expected_type.as_ref().and_then(|ty| ty.strip_references().as_adt()) 38 ctx.expected_type.as_ref().and_then(|ty| ty.strip_references().as_adt())
37 { 39 {
@@ -45,6 +47,22 @@ pub(crate) fn complete_unqualified_path(acc: &mut Completions, ctx: &CompletionC
45 cov_mark::hit!(skip_lifetime_completion); 47 cov_mark::hit!(skip_lifetime_completion);
46 return; 48 return;
47 } 49 }
50 if let ScopeDef::Local(local) = &res {
51 if local.is_self(ctx.db) {
52 let ty = local.ty(ctx.db);
53 super::complete_fields(ctx, &ty, |field, ty| match field {
54 either::Either::Left(field) => {
55 acc.add_field(ctx, Some(name.to_string()), field, &ty)
56 }
57 either::Either::Right(tuple_idx) => {
58 acc.add_tuple_field(ctx, Some(name.to_string()), tuple_idx, &ty)
59 }
60 });
61 super::complete_methods(ctx, &ty, |func| {
62 acc.add_method(ctx, func, Some(name.to_string()), None)
63 });
64 }
65 }
48 acc.add_resolution(ctx, name, &res); 66 acc.add_resolution(ctx, name, &res);
49 }); 67 });
50} 68}
@@ -376,6 +394,36 @@ fn foo() {
376 } 394 }
377 395
378 #[test] 396 #[test]
397 fn completes_qualified_fields_and_methods_in_methods() {
398 check(
399 r#"
400struct Foo { field: i32 }
401
402impl Foo { fn foo(&self) { $0 } }"#,
403 expect![[r#"
404 fd self.field i32
405 me self.foo() fn(&self)
406 lc self &Foo
407 sp Self
408 st Foo
409 "#]],
410 );
411 check(
412 r#"
413struct Foo(i32);
414
415impl Foo { fn foo(&mut self) { $0 } }"#,
416 expect![[r#"
417 fd self.0 i32
418 me self.foo() fn(&mut self)
419 lc self &mut Foo
420 sp Self
421 st Foo
422 "#]],
423 );
424 }
425
426 #[test]
379 fn completes_prelude() { 427 fn completes_prelude() {
380 check( 428 check(
381 r#" 429 r#"