diff options
Diffstat (limited to 'crates/ra_analysis/src/completion')
-rw-r--r-- | crates/ra_analysis/src/completion/complete_dot.rs | 10 | ||||
-rw-r--r-- | crates/ra_analysis/src/completion/complete_scope.rs | 14 |
2 files changed, 12 insertions, 12 deletions
diff --git a/crates/ra_analysis/src/completion/complete_dot.rs b/crates/ra_analysis/src/completion/complete_dot.rs index 031d8b98f..54ce1b638 100644 --- a/crates/ra_analysis/src/completion/complete_dot.rs +++ b/crates/ra_analysis/src/completion/complete_dot.rs | |||
@@ -1,4 +1,3 @@ | |||
1 | use ra_syntax::ast::AstNode; | ||
2 | use hir::{Ty, Def}; | 1 | use hir::{Ty, Def}; |
3 | 2 | ||
4 | use crate::Cancelable; | 3 | use crate::Cancelable; |
@@ -11,11 +10,12 @@ pub(super) fn complete_dot(acc: &mut Completions, ctx: &CompletionContext) -> Ca | |||
11 | _ => return Ok(()), | 10 | _ => return Ok(()), |
12 | }; | 11 | }; |
13 | let infer_result = function.infer(ctx.db)?; | 12 | let infer_result = function.infer(ctx.db)?; |
14 | let receiver_ty = if let Some(ty) = infer_result.type_of_node(receiver.syntax()) { | 13 | let syntax_mapping = function.body_syntax_mapping(ctx.db)?; |
15 | ty | 14 | let expr = match syntax_mapping.node_expr(receiver) { |
16 | } else { | 15 | Some(expr) => expr, |
17 | return Ok(()); | 16 | None => return Ok(()), |
18 | }; | 17 | }; |
18 | let receiver_ty = infer_result[expr].clone(); | ||
19 | if !ctx.is_method_call { | 19 | if !ctx.is_method_call { |
20 | complete_fields(acc, ctx, receiver_ty)?; | 20 | complete_fields(acc, ctx, receiver_ty)?; |
21 | } | 21 | } |
diff --git a/crates/ra_analysis/src/completion/complete_scope.rs b/crates/ra_analysis/src/completion/complete_scope.rs index 4dead3689..ee9052d3d 100644 --- a/crates/ra_analysis/src/completion/complete_scope.rs +++ b/crates/ra_analysis/src/completion/complete_scope.rs | |||
@@ -15,19 +15,22 @@ pub(super) fn complete_scope(acc: &mut Completions, ctx: &CompletionContext) -> | |||
15 | None => return Ok(()), | 15 | None => return Ok(()), |
16 | }; | 16 | }; |
17 | if let Some(function) = &ctx.function { | 17 | if let Some(function) = &ctx.function { |
18 | let scopes = function.scopes(ctx.db); | 18 | let scopes = function.scopes(ctx.db)?; |
19 | complete_fn(acc, &scopes, ctx.offset); | 19 | complete_fn(acc, &scopes, ctx.offset); |
20 | } | 20 | } |
21 | 21 | ||
22 | let module_scope = module.scope(ctx.db)?; | 22 | let module_scope = module.scope(ctx.db)?; |
23 | let (file_id, _) = module.defenition_source(ctx.db)?; | ||
23 | module_scope | 24 | module_scope |
24 | .entries() | 25 | .entries() |
25 | .filter(|(_name, res)| { | 26 | .filter(|(_name, res)| { |
26 | // Don't expose this item | 27 | // Don't expose this item |
28 | // FIXME: this penetrates through all kinds of abstractions, | ||
29 | // we need to figura out the way to do it less ugly. | ||
27 | match res.import { | 30 | match res.import { |
28 | None => true, | 31 | None => true, |
29 | Some(import) => { | 32 | Some(import) => { |
30 | let range = import.range(ctx.db, module.file_id()); | 33 | let range = import.range(ctx.db, file_id); |
31 | !range.is_subrange(&ctx.leaf.range()) | 34 | !range.is_subrange(&ctx.leaf.range()) |
32 | } | 35 | } |
33 | } | 36 | } |
@@ -40,20 +43,17 @@ pub(super) fn complete_scope(acc: &mut Completions, ctx: &CompletionContext) -> | |||
40 | Ok(()) | 43 | Ok(()) |
41 | } | 44 | } |
42 | 45 | ||
43 | fn complete_fn(acc: &mut Completions, scopes: &hir::FnScopes, offset: TextUnit) { | 46 | fn complete_fn(acc: &mut Completions, scopes: &hir::ScopesWithSyntaxMapping, offset: TextUnit) { |
44 | let mut shadowed = FxHashSet::default(); | 47 | let mut shadowed = FxHashSet::default(); |
45 | scopes | 48 | scopes |
46 | .scope_chain_for_offset(offset) | 49 | .scope_chain_for_offset(offset) |
47 | .flat_map(|scope| scopes.entries(scope).iter()) | 50 | .flat_map(|scope| scopes.scopes.entries(scope).iter()) |
48 | .filter(|entry| shadowed.insert(entry.name())) | 51 | .filter(|entry| shadowed.insert(entry.name())) |
49 | .for_each(|entry| { | 52 | .for_each(|entry| { |
50 | CompletionItem::new(CompletionKind::Reference, entry.name().to_string()) | 53 | CompletionItem::new(CompletionKind::Reference, entry.name().to_string()) |
51 | .kind(CompletionItemKind::Binding) | 54 | .kind(CompletionItemKind::Binding) |
52 | .add_to(acc) | 55 | .add_to(acc) |
53 | }); | 56 | }); |
54 | if scopes.self_param.is_some() { | ||
55 | CompletionItem::new(CompletionKind::Reference, "self").add_to(acc); | ||
56 | } | ||
57 | } | 57 | } |
58 | 58 | ||
59 | #[cfg(test)] | 59 | #[cfg(test)] |