diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2018-12-22 08:01:49 +0000 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2018-12-22 08:01:49 +0000 |
commit | 82e3ab02afee7cc0db178e1b10ee65146e4b7a14 (patch) | |
tree | d2d46b55e76a7a9af91c6502d70c5523b0a89b1a /crates/ra_analysis/src/completion | |
parent | 4e4ca27eabac6a9c97dc07baf9a067efdfc63384 (diff) | |
parent | 49e746b010bbba408e9e4b1a40d89642e4cb84c6 (diff) |
Merge #320
320: completion uses hir scopes r=matklad a=matklad
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_analysis/src/completion')
-rw-r--r-- | crates/ra_analysis/src/completion/complete_scope.rs | 44 |
1 files changed, 23 insertions, 21 deletions
diff --git a/crates/ra_analysis/src/completion/complete_scope.rs b/crates/ra_analysis/src/completion/complete_scope.rs index 82610d63f..a57670e3b 100644 --- a/crates/ra_analysis/src/completion/complete_scope.rs +++ b/crates/ra_analysis/src/completion/complete_scope.rs | |||
@@ -10,32 +10,34 @@ pub(super) fn complete_scope(acc: &mut Completions, ctx: &CompletionContext) -> | |||
10 | if !ctx.is_trivial_path { | 10 | if !ctx.is_trivial_path { |
11 | return Ok(()); | 11 | return Ok(()); |
12 | } | 12 | } |
13 | let module = match &ctx.module { | ||
14 | Some(it) => it, | ||
15 | None => return Ok(()), | ||
16 | }; | ||
13 | if let Some(fn_def) = ctx.enclosing_fn { | 17 | if let Some(fn_def) = ctx.enclosing_fn { |
14 | let scopes = hir::FnScopes::new(fn_def); | 18 | let function = hir::source_binder::function_from_module(ctx.db, module, fn_def); |
19 | let scopes = function.scopes(ctx.db); | ||
15 | complete_fn(acc, &scopes, ctx.offset); | 20 | complete_fn(acc, &scopes, ctx.offset); |
16 | } | 21 | } |
17 | 22 | ||
18 | if let Some(module) = &ctx.module { | 23 | let module_scope = module.scope(ctx.db)?; |
19 | let module_scope = module.scope(ctx.db)?; | 24 | module_scope |
20 | module_scope | 25 | .entries() |
21 | .entries() | 26 | .filter(|(_name, res)| { |
22 | .filter(|(_name, res)| { | 27 | // Don't expose this item |
23 | // Don't expose this item | 28 | match res.import { |
24 | match res.import { | 29 | None => true, |
25 | None => true, | 30 | Some(import) => { |
26 | Some(import) => { | 31 | let range = import.range(ctx.db, module.source().file_id()); |
27 | let range = import.range(ctx.db, module.source().file_id()); | 32 | !range.is_subrange(&ctx.leaf.range()) |
28 | !range.is_subrange(&ctx.leaf.range()) | ||
29 | } | ||
30 | } | 33 | } |
31 | }) | 34 | } |
32 | .for_each(|(name, res)| { | 35 | }) |
33 | CompletionItem::new(CompletionKind::Reference, name.to_string()) | 36 | .for_each(|(name, res)| { |
34 | .from_resolution(ctx.db, res) | 37 | CompletionItem::new(CompletionKind::Reference, name.to_string()) |
35 | .add_to(acc) | 38 | .from_resolution(ctx.db, res) |
36 | }); | 39 | .add_to(acc) |
37 | } | 40 | }); |
38 | |||
39 | Ok(()) | 41 | Ok(()) |
40 | } | 42 | } |
41 | 43 | ||