aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_analysis/src/completion/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_analysis/src/completion/mod.rs')
-rw-r--r--crates/ra_analysis/src/completion/mod.rs25
1 files changed, 5 insertions, 20 deletions
diff --git a/crates/ra_analysis/src/completion/mod.rs b/crates/ra_analysis/src/completion/mod.rs
index 2e082705e..5e3ee79dd 100644
--- a/crates/ra_analysis/src/completion/mod.rs
+++ b/crates/ra_analysis/src/completion/mod.rs
@@ -2,7 +2,6 @@ mod reference_completion;
2 2
3use ra_editor::find_node_at_offset; 3use ra_editor::find_node_at_offset;
4use ra_syntax::{ 4use ra_syntax::{
5 algo::find_leaf_at_offset,
6 algo::visit::{visitor_ctx, VisitorCtx}, 5 algo::visit::{visitor_ctx, VisitorCtx},
7 ast, 6 ast,
8 AstNode, AtomEdit, 7 AstNode, AtomEdit,
@@ -12,8 +11,9 @@ use rustc_hash::{FxHashMap};
12 11
13use crate::{ 12use crate::{
14 db::{self, SyntaxDatabase}, 13 db::{self, SyntaxDatabase},
15 descriptors::{DescriptorDatabase, module::ModuleSource}, 14 descriptors::{
16 input::{FilesDatabase}, 15 module::{ModuleDescriptor}
16 },
17 Cancelable, FilePosition 17 Cancelable, FilePosition
18}; 18};
19 19
@@ -38,14 +38,7 @@ pub(crate) fn completions(
38 original_file.reparse(&edit) 38 original_file.reparse(&edit)
39 }; 39 };
40 40
41 let leaf = match find_leaf_at_offset(original_file.syntax(), position.offset).left_biased() { 41 let module = match ModuleDescriptor::guess_from_position(db, position)? {
42 None => return Ok(None),
43 Some(it) => it,
44 };
45 let source_root_id = db.file_source_root(position.file_id);
46 let module_tree = db.module_tree(source_root_id)?;
47 let module_source = ModuleSource::for_node(position.file_id, leaf);
48 let module_id = match module_tree.any_module_for_source(module_source) {
49 None => return Ok(None), 42 None => return Ok(None),
50 Some(it) => it, 43 Some(it) => it,
51 }; 44 };
@@ -55,15 +48,7 @@ pub(crate) fn completions(
55 // First, let's try to complete a reference to some declaration. 48 // First, let's try to complete a reference to some declaration.
56 if let Some(name_ref) = find_node_at_offset::<ast::NameRef>(file.syntax(), position.offset) { 49 if let Some(name_ref) = find_node_at_offset::<ast::NameRef>(file.syntax(), position.offset) {
57 has_completions = true; 50 has_completions = true;
58 reference_completion::completions( 51 reference_completion::completions(&mut res, db, &module, &file, name_ref)?;
59 &mut res,
60 db,
61 source_root_id,
62 &module_tree,
63 module_id,
64 &file,
65 name_ref,
66 )?;
67 // special case, `trait T { fn foo(i_am_a_name_ref) {} }` 52 // special case, `trait T { fn foo(i_am_a_name_ref) {} }`
68 if is_node::<ast::Param>(name_ref.syntax()) { 53 if is_node::<ast::Param>(name_ref.syntax()) {
69 param_completions(name_ref.syntax(), &mut res); 54 param_completions(name_ref.syntax(), &mut res);