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