diff options
Diffstat (limited to 'crates/ra_analysis/src/completion.rs')
-rw-r--r-- | crates/ra_analysis/src/completion.rs | 31 |
1 files changed, 15 insertions, 16 deletions
diff --git a/crates/ra_analysis/src/completion.rs b/crates/ra_analysis/src/completion.rs index 766df1d96..7c3476e5c 100644 --- a/crates/ra_analysis/src/completion.rs +++ b/crates/ra_analysis/src/completion.rs | |||
@@ -14,7 +14,7 @@ use crate::{ | |||
14 | descriptors::module::{ModuleId, ModuleScope, ModuleTree, ModuleSource}, | 14 | descriptors::module::{ModuleId, ModuleScope, ModuleTree, ModuleSource}, |
15 | descriptors::DescriptorDatabase, | 15 | descriptors::DescriptorDatabase, |
16 | input::FilesDatabase, | 16 | input::FilesDatabase, |
17 | Cancelable, FileId, | 17 | Cancelable, FilePosition, |
18 | }; | 18 | }; |
19 | 19 | ||
20 | #[derive(Debug)] | 20 | #[derive(Debug)] |
@@ -29,21 +29,21 @@ pub struct CompletionItem { | |||
29 | 29 | ||
30 | pub(crate) fn resolve_based_completion( | 30 | pub(crate) fn resolve_based_completion( |
31 | db: &db::RootDatabase, | 31 | db: &db::RootDatabase, |
32 | file_id: FileId, | 32 | position: FilePosition, |
33 | offset: TextUnit, | ||
34 | ) -> Cancelable<Option<Vec<CompletionItem>>> { | 33 | ) -> Cancelable<Option<Vec<CompletionItem>>> { |
35 | let source_root_id = db.file_source_root(file_id); | 34 | let source_root_id = db.file_source_root(position.file_id); |
36 | let file = db.file_syntax(file_id); | 35 | let file = db.file_syntax(position.file_id); |
37 | let module_tree = db.module_tree(source_root_id)?; | 36 | let module_tree = db.module_tree(source_root_id)?; |
38 | let module_id = match module_tree.any_module_for_source(ModuleSource::File(file_id)) { | 37 | let module_id = match module_tree.any_module_for_source(ModuleSource::File(position.file_id)) { |
39 | None => return Ok(None), | 38 | None => return Ok(None), |
40 | Some(it) => it, | 39 | Some(it) => it, |
41 | }; | 40 | }; |
42 | let file = { | 41 | let file = { |
43 | let edit = AtomEdit::insert(offset, "intellijRulezz".to_string()); | 42 | let edit = AtomEdit::insert(position.offset, "intellijRulezz".to_string()); |
44 | file.reparse(&edit) | 43 | file.reparse(&edit) |
45 | }; | 44 | }; |
46 | let target_module_id = match find_target_module(&module_tree, module_id, &file, offset) { | 45 | let target_module_id = match find_target_module(&module_tree, module_id, &file, position.offset) |
46 | { | ||
47 | None => return Ok(None), | 47 | None => return Ok(None), |
48 | Some(it) => it, | 48 | Some(it) => it, |
49 | }; | 49 | }; |
@@ -99,18 +99,17 @@ fn crate_path(name_ref: ast::NameRef) -> Option<Vec<ast::NameRef>> { | |||
99 | 99 | ||
100 | pub(crate) fn scope_completion( | 100 | pub(crate) fn scope_completion( |
101 | db: &db::RootDatabase, | 101 | db: &db::RootDatabase, |
102 | file_id: FileId, | 102 | position: FilePosition, |
103 | offset: TextUnit, | ||
104 | ) -> Option<Vec<CompletionItem>> { | 103 | ) -> Option<Vec<CompletionItem>> { |
105 | let original_file = db.file_syntax(file_id); | 104 | let original_file = db.file_syntax(position.file_id); |
106 | // Insert a fake ident to get a valid parse tree | 105 | // Insert a fake ident to get a valid parse tree |
107 | let file = { | 106 | let file = { |
108 | let edit = AtomEdit::insert(offset, "intellijRulezz".to_string()); | 107 | let edit = AtomEdit::insert(position.offset, "intellijRulezz".to_string()); |
109 | original_file.reparse(&edit) | 108 | original_file.reparse(&edit) |
110 | }; | 109 | }; |
111 | let mut has_completions = false; | 110 | let mut has_completions = false; |
112 | let mut res = Vec::new(); | 111 | let mut res = Vec::new(); |
113 | if let Some(name_ref) = find_node_at_offset::<ast::NameRef>(file.syntax(), offset) { | 112 | if let Some(name_ref) = find_node_at_offset::<ast::NameRef>(file.syntax(), position.offset) { |
114 | has_completions = true; | 113 | has_completions = true; |
115 | complete_name_ref(&file, name_ref, &mut res); | 114 | complete_name_ref(&file, name_ref, &mut res); |
116 | // special case, `trait T { fn foo(i_am_a_name_ref) {} }` | 115 | // special case, `trait T { fn foo(i_am_a_name_ref) {} }` |
@@ -129,7 +128,7 @@ pub(crate) fn scope_completion( | |||
129 | _ => (), | 128 | _ => (), |
130 | } | 129 | } |
131 | } | 130 | } |
132 | if let Some(name) = find_node_at_offset::<ast::Name>(file.syntax(), offset) { | 131 | if let Some(name) = find_node_at_offset::<ast::Name>(file.syntax(), position.offset) { |
133 | if is_node::<ast::Param>(name.syntax()) { | 132 | if is_node::<ast::Param>(name.syntax()) { |
134 | has_completions = true; | 133 | has_completions = true; |
135 | param_completions(name.syntax(), &mut res); | 134 | param_completions(name.syntax(), &mut res); |
@@ -383,7 +382,7 @@ mod tests { | |||
383 | 382 | ||
384 | fn check_scope_completion(code: &str, expected_completions: &str) { | 383 | fn check_scope_completion(code: &str, expected_completions: &str) { |
385 | let (analysis, position) = single_file_with_position(code); | 384 | let (analysis, position) = single_file_with_position(code); |
386 | let completions = scope_completion(&analysis.imp.db, position.file_id, position.offset) | 385 | let completions = scope_completion(&analysis.imp.db, position) |
387 | .unwrap() | 386 | .unwrap() |
388 | .into_iter() | 387 | .into_iter() |
389 | .filter(|c| c.snippet.is_none()) | 388 | .filter(|c| c.snippet.is_none()) |
@@ -393,7 +392,7 @@ mod tests { | |||
393 | 392 | ||
394 | fn check_snippet_completion(code: &str, expected_completions: &str) { | 393 | fn check_snippet_completion(code: &str, expected_completions: &str) { |
395 | let (analysis, position) = single_file_with_position(code); | 394 | let (analysis, position) = single_file_with_position(code); |
396 | let completions = scope_completion(&analysis.imp.db, position.file_id, position.offset) | 395 | let completions = scope_completion(&analysis.imp.db, position) |
397 | .unwrap() | 396 | .unwrap() |
398 | .into_iter() | 397 | .into_iter() |
399 | .filter(|c| c.snippet.is_some()) | 398 | .filter(|c| c.snippet.is_some()) |