diff options
Diffstat (limited to 'crates/ra_editor/src/completion.rs')
-rw-r--r-- | crates/ra_editor/src/completion.rs | 30 |
1 files changed, 17 insertions, 13 deletions
diff --git a/crates/ra_editor/src/completion.rs b/crates/ra_editor/src/completion.rs index 8502b337d..0a3675255 100644 --- a/crates/ra_editor/src/completion.rs +++ b/crates/ra_editor/src/completion.rs | |||
@@ -2,7 +2,7 @@ use rustc_hash::{FxHashMap, FxHashSet}; | |||
2 | 2 | ||
3 | use ra_syntax::{ | 3 | use ra_syntax::{ |
4 | algo::visit::{visitor, visitor_ctx, Visitor, VisitorCtx}, | 4 | algo::visit::{visitor, visitor_ctx, Visitor, VisitorCtx}, |
5 | ast::{self, LoopBodyOwner, ModuleItemOwner}, | 5 | ast::{self, AstChildren, LoopBodyOwner, ModuleItemOwner}, |
6 | text_utils::is_subrange, | 6 | text_utils::is_subrange, |
7 | AstNode, File, | 7 | AstNode, File, |
8 | SyntaxKind::*, | 8 | SyntaxKind::*, |
@@ -65,6 +65,21 @@ pub fn scope_completion(file: &File, offset: TextUnit) -> Option<Vec<CompletionI | |||
65 | } | 65 | } |
66 | } | 66 | } |
67 | 67 | ||
68 | pub fn complete_module_items(items: AstChildren<ast::ModuleItem>, this_item: Option<ast::NameRef>, acc: &mut Vec<CompletionItem>) { | ||
69 | let scope = ModuleScope::new(items); | ||
70 | acc.extend( | ||
71 | scope | ||
72 | .entries() | ||
73 | .iter() | ||
74 | .filter(|entry| Some(entry.syntax()) != this_item.map(|it| it.syntax())) | ||
75 | .map(|entry| CompletionItem { | ||
76 | label: entry.name().to_string(), | ||
77 | lookup: None, | ||
78 | snippet: None, | ||
79 | }), | ||
80 | ); | ||
81 | } | ||
82 | |||
68 | fn complete_name_ref(file: &File, name_ref: ast::NameRef, acc: &mut Vec<CompletionItem>) { | 83 | fn complete_name_ref(file: &File, name_ref: ast::NameRef, acc: &mut Vec<CompletionItem>) { |
69 | if !is_node::<ast::Path>(name_ref.syntax()) { | 84 | if !is_node::<ast::Path>(name_ref.syntax()) { |
70 | return; | 85 | return; |
@@ -77,18 +92,7 @@ fn complete_name_ref(file: &File, name_ref: ast::NameRef, acc: &mut Vec<Completi | |||
77 | .accept(node) | 92 | .accept(node) |
78 | { | 93 | { |
79 | if let Some(items) = items { | 94 | if let Some(items) = items { |
80 | let scope = ModuleScope::new(items); | 95 | complete_module_items(items, Some(name_ref), acc); |
81 | acc.extend( | ||
82 | scope | ||
83 | .entries() | ||
84 | .iter() | ||
85 | .filter(|entry| entry.syntax() != name_ref.syntax()) | ||
86 | .map(|entry| CompletionItem { | ||
87 | label: entry.name().to_string(), | ||
88 | lookup: None, | ||
89 | snippet: None, | ||
90 | }), | ||
91 | ); | ||
92 | } | 96 | } |
93 | break; | 97 | break; |
94 | } else if !visited_fn { | 98 | } else if !visited_fn { |