|
1 | 1 | //! Completes references after dot (fields and method calls).
|
2 | 2 |
|
3 | 3 | use either::Either;
|
4 |
| -use hir::ScopeDef; |
5 | 4 | use rustc_hash::FxHashSet;
|
6 | 5 |
|
7 | 6 | use crate::{context::CompletionContext, patterns::ImmediateLocation, Completions};
|
@@ -36,24 +35,22 @@ fn complete_undotted_self(acc: &mut Completions, ctx: &CompletionContext) {
|
36 | 35 | if !ctx.is_trivial_path() || ctx.is_path_disallowed() || !ctx.expects_expression() {
|
37 | 36 | return;
|
38 | 37 | }
|
39 |
| - ctx.scope.process_all_names(&mut |name, def| { |
40 |
| - if let ScopeDef::Local(local) = &def { |
41 |
| - if local.is_self(ctx.db) { |
42 |
| - let ty = local.ty(ctx.db); |
43 |
| - complete_fields(ctx, &ty, |field, ty| match field { |
44 |
| - either::Either::Left(field) => { |
45 |
| - acc.add_field(ctx, Some(name.clone()), field, &ty) |
46 |
| - } |
47 |
| - either::Either::Right(tuple_idx) => { |
48 |
| - acc.add_tuple_field(ctx, Some(name.clone()), tuple_idx, &ty) |
49 |
| - } |
50 |
| - }); |
51 |
| - complete_methods(ctx, &ty, |func| { |
52 |
| - acc.add_method(ctx, func, Some(name.clone()), None) |
53 |
| - }); |
54 |
| - } |
| 38 | + if let Some(func) = ctx.function_def.as_ref().and_then(|fn_| ctx.sema.to_def(fn_)) { |
| 39 | + if let Some(self_) = func.self_param(ctx.db) { |
| 40 | + let ty = self_.ty(ctx.db); |
| 41 | + complete_fields(ctx, &ty, |field, ty| match field { |
| 42 | + either::Either::Left(field) => { |
| 43 | + acc.add_field(ctx, Some(hir::known::SELF_PARAM), field, &ty) |
| 44 | + } |
| 45 | + either::Either::Right(tuple_idx) => { |
| 46 | + acc.add_tuple_field(ctx, Some(hir::known::SELF_PARAM), tuple_idx, &ty) |
| 47 | + } |
| 48 | + }); |
| 49 | + complete_methods(ctx, &ty, |func| { |
| 50 | + acc.add_method(ctx, func, Some(hir::known::SELF_PARAM), None) |
| 51 | + }); |
55 | 52 | }
|
56 |
| - }); |
| 53 | + } |
57 | 54 | }
|
58 | 55 |
|
59 | 56 | fn complete_fields(
|
|
0 commit comments