diff options
Diffstat (limited to 'crates/ra_analysis/src/completion/reference_completion.rs')
-rw-r--r-- | crates/ra_analysis/src/completion/reference_completion.rs | 31 |
1 files changed, 11 insertions, 20 deletions
diff --git a/crates/ra_analysis/src/completion/reference_completion.rs b/crates/ra_analysis/src/completion/reference_completion.rs index 6c5fd0be6..c94d9af75 100644 --- a/crates/ra_analysis/src/completion/reference_completion.rs +++ b/crates/ra_analysis/src/completion/reference_completion.rs | |||
@@ -9,20 +9,16 @@ use ra_syntax::{ | |||
9 | 9 | ||
10 | use crate::{ | 10 | use crate::{ |
11 | db::RootDatabase, | 11 | db::RootDatabase, |
12 | input::{SourceRootId}, | ||
13 | completion::CompletionItem, | 12 | completion::CompletionItem, |
14 | descriptors::module::{ModuleId, ModuleTree}, | 13 | descriptors::module::{ModuleDescriptor}, |
15 | descriptors::function::FnScopes, | 14 | descriptors::function::FnScopes, |
16 | descriptors::DescriptorDatabase, | ||
17 | Cancelable | 15 | Cancelable |
18 | }; | 16 | }; |
19 | 17 | ||
20 | pub(super) fn completions( | 18 | pub(super) fn completions( |
21 | acc: &mut Vec<CompletionItem>, | 19 | acc: &mut Vec<CompletionItem>, |
22 | db: &RootDatabase, | 20 | db: &RootDatabase, |
23 | source_root_id: SourceRootId, | 21 | module: &ModuleDescriptor, |
24 | module_tree: &ModuleTree, | ||
25 | module_id: ModuleId, | ||
26 | file: &SourceFileNode, | 22 | file: &SourceFileNode, |
27 | name_ref: ast::NameRef, | 23 | name_ref: ast::NameRef, |
28 | ) -> Cancelable<()> { | 24 | ) -> Cancelable<()> { |
@@ -40,7 +36,7 @@ pub(super) fn completions( | |||
40 | complete_expr_snippets(acc); | 36 | complete_expr_snippets(acc); |
41 | } | 37 | } |
42 | 38 | ||
43 | let module_scope = db.module_scope(source_root_id, module_id)?; | 39 | let module_scope = module.scope(db)?; |
44 | acc.extend( | 40 | acc.extend( |
45 | module_scope | 41 | module_scope |
46 | .entries() | 42 | .entries() |
@@ -56,9 +52,7 @@ pub(super) fn completions( | |||
56 | }), | 52 | }), |
57 | ); | 53 | ); |
58 | } | 54 | } |
59 | NameRefKind::CratePath(path) => { | 55 | NameRefKind::CratePath(path) => complete_path(acc, db, module, path)?, |
60 | complete_path(acc, db, source_root_id, module_tree, module_id, path)? | ||
61 | } | ||
62 | NameRefKind::BareIdentInMod => { | 56 | NameRefKind::BareIdentInMod => { |
63 | let name_range = name_ref.syntax().range(); | 57 | let name_range = name_ref.syntax().range(); |
64 | let top_node = name_ref | 58 | let top_node = name_ref |
@@ -171,16 +165,14 @@ fn complete_fn(name_ref: ast::NameRef, scopes: &FnScopes, acc: &mut Vec<Completi | |||
171 | fn complete_path( | 165 | fn complete_path( |
172 | acc: &mut Vec<CompletionItem>, | 166 | acc: &mut Vec<CompletionItem>, |
173 | db: &RootDatabase, | 167 | db: &RootDatabase, |
174 | source_root_id: SourceRootId, | 168 | module: &ModuleDescriptor, |
175 | module_tree: &ModuleTree, | ||
176 | module_id: ModuleId, | ||
177 | crate_path: Vec<ast::NameRef>, | 169 | crate_path: Vec<ast::NameRef>, |
178 | ) -> Cancelable<()> { | 170 | ) -> Cancelable<()> { |
179 | let target_module_id = match find_target_module(module_tree, module_id, crate_path) { | 171 | let target_module = match find_target_module(module, crate_path) { |
180 | None => return Ok(()), | 172 | None => return Ok(()), |
181 | Some(it) => it, | 173 | Some(it) => it, |
182 | }; | 174 | }; |
183 | let module_scope = db.module_scope(source_root_id, target_module_id)?; | 175 | let module_scope = target_module.scope(db)?; |
184 | let completions = module_scope.entries().iter().map(|entry| CompletionItem { | 176 | let completions = module_scope.entries().iter().map(|entry| CompletionItem { |
185 | label: entry.name().to_string(), | 177 | label: entry.name().to_string(), |
186 | lookup: None, | 178 | lookup: None, |
@@ -191,14 +183,13 @@ fn complete_path( | |||
191 | } | 183 | } |
192 | 184 | ||
193 | fn find_target_module( | 185 | fn find_target_module( |
194 | module_tree: &ModuleTree, | 186 | module: &ModuleDescriptor, |
195 | module_id: ModuleId, | ||
196 | mut crate_path: Vec<ast::NameRef>, | 187 | mut crate_path: Vec<ast::NameRef>, |
197 | ) -> Option<ModuleId> { | 188 | ) -> Option<ModuleDescriptor> { |
198 | crate_path.pop(); | 189 | crate_path.pop(); |
199 | let mut target_module = module_id.root(&module_tree); | 190 | let mut target_module = module.crate_root(); |
200 | for name in crate_path { | 191 | for name in crate_path { |
201 | target_module = target_module.child(module_tree, name.text().as_str())?; | 192 | target_module = target_module.child(name.text().as_str())?; |
202 | } | 193 | } |
203 | Some(target_module) | 194 | Some(target_module) |
204 | } | 195 | } |