From 0192c116f78b3a81ef15587eecac29a2676ae00c Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 5 Nov 2018 14:57:41 +0300 Subject: Use FilePosition everywhere --- crates/ra_analysis/src/completion.rs | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) (limited to 'crates/ra_analysis/src/completion.rs') 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::{ descriptors::module::{ModuleId, ModuleScope, ModuleTree, ModuleSource}, descriptors::DescriptorDatabase, input::FilesDatabase, - Cancelable, FileId, + Cancelable, FilePosition, }; #[derive(Debug)] @@ -29,21 +29,21 @@ pub struct CompletionItem { pub(crate) fn resolve_based_completion( db: &db::RootDatabase, - file_id: FileId, - offset: TextUnit, + position: FilePosition, ) -> Cancelable>> { - let source_root_id = db.file_source_root(file_id); - let file = db.file_syntax(file_id); + let source_root_id = db.file_source_root(position.file_id); + let file = db.file_syntax(position.file_id); let module_tree = db.module_tree(source_root_id)?; - let module_id = match module_tree.any_module_for_source(ModuleSource::File(file_id)) { + let module_id = match module_tree.any_module_for_source(ModuleSource::File(position.file_id)) { None => return Ok(None), Some(it) => it, }; let file = { - let edit = AtomEdit::insert(offset, "intellijRulezz".to_string()); + let edit = AtomEdit::insert(position.offset, "intellijRulezz".to_string()); file.reparse(&edit) }; - let target_module_id = match find_target_module(&module_tree, module_id, &file, offset) { + let target_module_id = match find_target_module(&module_tree, module_id, &file, position.offset) + { None => return Ok(None), Some(it) => it, }; @@ -99,18 +99,17 @@ fn crate_path(name_ref: ast::NameRef) -> Option> { pub(crate) fn scope_completion( db: &db::RootDatabase, - file_id: FileId, - offset: TextUnit, + position: FilePosition, ) -> Option> { - let original_file = db.file_syntax(file_id); + let original_file = db.file_syntax(position.file_id); // Insert a fake ident to get a valid parse tree let file = { - let edit = AtomEdit::insert(offset, "intellijRulezz".to_string()); + let edit = AtomEdit::insert(position.offset, "intellijRulezz".to_string()); original_file.reparse(&edit) }; let mut has_completions = false; let mut res = Vec::new(); - if let Some(name_ref) = find_node_at_offset::(file.syntax(), offset) { + if let Some(name_ref) = find_node_at_offset::(file.syntax(), position.offset) { has_completions = true; complete_name_ref(&file, name_ref, &mut res); // special case, `trait T { fn foo(i_am_a_name_ref) {} }` @@ -129,7 +128,7 @@ pub(crate) fn scope_completion( _ => (), } } - if let Some(name) = find_node_at_offset::(file.syntax(), offset) { + if let Some(name) = find_node_at_offset::(file.syntax(), position.offset) { if is_node::(name.syntax()) { has_completions = true; param_completions(name.syntax(), &mut res); @@ -383,7 +382,7 @@ mod tests { fn check_scope_completion(code: &str, expected_completions: &str) { let (analysis, position) = single_file_with_position(code); - let completions = scope_completion(&analysis.imp.db, position.file_id, position.offset) + let completions = scope_completion(&analysis.imp.db, position) .unwrap() .into_iter() .filter(|c| c.snippet.is_none()) @@ -393,7 +392,7 @@ mod tests { fn check_snippet_completion(code: &str, expected_completions: &str) { let (analysis, position) = single_file_with_position(code); - let completions = scope_completion(&analysis.imp.db, position.file_id, position.offset) + let completions = scope_completion(&analysis.imp.db, position) .unwrap() .into_iter() .filter(|c| c.snippet.is_some()) -- cgit v1.2.3