diff options
author | Aleksey Kladov <[email protected]> | 2018-12-21 12:46:01 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-12-21 12:46:01 +0000 |
commit | ba0072401c3b8b6c9391428672bd91055150c8ee (patch) | |
tree | aecfd8e5e2a55fad6b963b1b9f436cb902f910ad /crates/ra_analysis/src/completion.rs | |
parent | 052e20162a026356c716116ac10ea795ca5dc28d (diff) |
use Completions to collect completions
Diffstat (limited to 'crates/ra_analysis/src/completion.rs')
-rw-r--r-- | crates/ra_analysis/src/completion.rs | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/crates/ra_analysis/src/completion.rs b/crates/ra_analysis/src/completion.rs index 222b6854c..074033ad8 100644 --- a/crates/ra_analysis/src/completion.rs +++ b/crates/ra_analysis/src/completion.rs | |||
@@ -15,7 +15,8 @@ use hir::source_binder; | |||
15 | 15 | ||
16 | use crate::{ | 16 | use crate::{ |
17 | db, | 17 | db, |
18 | Cancelable, FilePosition | 18 | Cancelable, FilePosition, |
19 | completion::completion_item::Completions, | ||
19 | }; | 20 | }; |
20 | 21 | ||
21 | pub use crate::completion::completion_item::{CompletionItem, InsertText}; | 22 | pub use crate::completion::completion_item::{CompletionItem, InsertText}; |
@@ -33,15 +34,15 @@ pub(crate) fn completions( | |||
33 | 34 | ||
34 | let module = ctry!(source_binder::module_from_position(db, position)?); | 35 | let module = ctry!(source_binder::module_from_position(db, position)?); |
35 | 36 | ||
36 | let mut res = Vec::new(); | 37 | let mut acc = Completions::default(); |
37 | let mut has_completions = false; | 38 | let mut has_completions = false; |
38 | // First, let's try to complete a reference to some declaration. | 39 | // First, let's try to complete a reference to some declaration. |
39 | if let Some(name_ref) = find_node_at_offset::<ast::NameRef>(file.syntax(), position.offset) { | 40 | if let Some(name_ref) = find_node_at_offset::<ast::NameRef>(file.syntax(), position.offset) { |
40 | has_completions = true; | 41 | has_completions = true; |
41 | reference_completion::completions(&mut res, db, &module, &file, name_ref)?; | 42 | reference_completion::completions(&mut acc, db, &module, &file, name_ref)?; |
42 | // special case, `trait T { fn foo(i_am_a_name_ref) {} }` | 43 | // special case, `trait T { fn foo(i_am_a_name_ref) {} }` |
43 | if is_node::<ast::Param>(name_ref.syntax()) { | 44 | if is_node::<ast::Param>(name_ref.syntax()) { |
44 | param_completions(&mut res, name_ref.syntax()); | 45 | param_completions(&mut acc, name_ref.syntax()); |
45 | } | 46 | } |
46 | } | 47 | } |
47 | 48 | ||
@@ -49,10 +50,14 @@ pub(crate) fn completions( | |||
49 | if let Some(name) = find_node_at_offset::<ast::Name>(file.syntax(), position.offset) { | 50 | if let Some(name) = find_node_at_offset::<ast::Name>(file.syntax(), position.offset) { |
50 | if is_node::<ast::Param>(name.syntax()) { | 51 | if is_node::<ast::Param>(name.syntax()) { |
51 | has_completions = true; | 52 | has_completions = true; |
52 | param_completions(&mut res, name.syntax()); | 53 | param_completions(&mut acc, name.syntax()); |
53 | } | 54 | } |
54 | } | 55 | } |
55 | let res = if has_completions { Some(res) } else { None }; | 56 | let res = if has_completions { |
57 | Some(acc.into()) | ||
58 | } else { | ||
59 | None | ||
60 | }; | ||
56 | Ok(res) | 61 | Ok(res) |
57 | } | 62 | } |
58 | 63 | ||
@@ -60,7 +65,7 @@ pub(crate) fn completions( | |||
60 | /// functions in a file have a `spam: &mut Spam` parameter, a completion with | 65 | /// functions in a file have a `spam: &mut Spam` parameter, a completion with |
61 | /// `spam: &mut Spam` insert text/label and `spam` lookup string will be | 66 | /// `spam: &mut Spam` insert text/label and `spam` lookup string will be |
62 | /// suggested. | 67 | /// suggested. |
63 | fn param_completions(acc: &mut Vec<CompletionItem>, ctx: SyntaxNodeRef) { | 68 | fn param_completions(acc: &mut Completions, ctx: SyntaxNodeRef) { |
64 | let mut params = FxHashMap::default(); | 69 | let mut params = FxHashMap::default(); |
65 | for node in ctx.ancestors() { | 70 | for node in ctx.ancestors() { |
66 | let _ = visitor_ctx(&mut params) | 71 | let _ = visitor_ctx(&mut params) |