From 61687b9db67d34bbcce8596496448c0717d98316 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 6 Jan 2019 13:41:12 +0300 Subject: fix tests --- crates/ra_analysis/src/imp.rs | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) (limited to 'crates/ra_analysis/src') diff --git a/crates/ra_analysis/src/imp.rs b/crates/ra_analysis/src/imp.rs index 5988fb779..44e7aca44 100644 --- a/crates/ra_analysis/src/imp.rs +++ b/crates/ra_analysis/src/imp.rs @@ -105,39 +105,36 @@ impl db::RootDatabase { &self, position: FilePosition, ) -> Cancelable> { - let descr = match source_binder::module_from_position(self, position)? { + let module = match source_binder::module_from_position(self, position)? { None => return Ok(Vec::new()), Some(it) => it, }; - let (file_id, decl) = match descr.parent_link_source(self) { + let (file_id, ast_module) = module.source(self); + let ast_module = match ast_module { None => return Ok(Vec::new()), Some(it) => it, }; - let decl = decl.borrowed(); - let decl_name = decl.name().unwrap(); + let ast_module = ast_module.borrowed(); + let name = ast_module.name().unwrap(); Ok(vec![NavigationTarget { file_id, - name: decl_name.text(), - range: decl_name.syntax().range(), + name: name.text(), + range: name.syntax().range(), kind: MODULE, ptr: None, }]) } /// Returns `Vec` for the same reason as `parent_module` pub(crate) fn crate_for(&self, file_id: FileId) -> Cancelable> { - let descr = match source_binder::module_from_file_id(self, file_id)? { + let module = match source_binder::module_from_file_id(self, file_id)? { + Some(it) => it, None => return Ok(Vec::new()), + }; + let krate = match module.krate(self)? { Some(it) => it, + None => return Ok(Vec::new()), }; - let root = descr.crate_root(); - let file_id = root.file_id(); - - let crate_graph = self.crate_graph(); - let crate_id = crate_graph.crate_id_for_crate_root(file_id); - Ok(crate_id.into_iter().collect()) - } - pub(crate) fn crate_root(&self, crate_id: CrateId) -> FileId { - self.crate_graph().crate_root(crate_id) + Ok(vec![krate.crate_id()]) } pub(crate) fn find_all_refs( &self, -- cgit v1.2.3 From a7f4f7bfcc524a55ba559e0141a70aa799a8686d Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 6 Jan 2019 15:58:45 +0300 Subject: split module source into decl/defin --- crates/ra_analysis/src/lib.rs | 2 +- crates/ra_analysis/src/runnables.rs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'crates/ra_analysis/src') diff --git a/crates/ra_analysis/src/lib.rs b/crates/ra_analysis/src/lib.rs index 390c31c3f..77f77e9a8 100644 --- a/crates/ra_analysis/src/lib.rs +++ b/crates/ra_analysis/src/lib.rs @@ -397,7 +397,7 @@ impl Analysis { } /// Returns the root file of the given crate. pub fn crate_root(&self, crate_id: CrateId) -> Cancelable { - Ok(self.db.crate_root(crate_id)) + Ok(self.db.crate_graph().crate_root(crate_id)) } /// Returns the set of possible targets to run for the current file. pub fn runnables(&self, file_id: FileId) -> Cancelable> { diff --git a/crates/ra_analysis/src/runnables.rs b/crates/ra_analysis/src/runnables.rs index 474267605..f24aa514a 100644 --- a/crates/ra_analysis/src/runnables.rs +++ b/crates/ra_analysis/src/runnables.rs @@ -73,11 +73,11 @@ fn runnable_mod(db: &RootDatabase, file_id: FileId, module: ast::Module) -> Opti let module = hir::source_binder::module_from_child_node(db, file_id, module.syntax()).ok()??; let path = module - .path_to_root() + .path_to_root(db) + .ok()? .into_iter() .rev() - .into_iter() - .filter_map(|it| it.name().map(Clone::clone)) + .filter_map(|it| it.name(db).map(Clone::clone)) .join("::"); Some(Runnable { range, -- cgit v1.2.3 From c303e6fbdfd8d04b645796489766e912d2cb3009 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 6 Jan 2019 16:05:59 +0300 Subject: fix ra_analysis to work with the new API --- crates/ra_analysis/src/completion/complete_scope.rs | 5 ++++- crates/ra_analysis/src/goto_defenition.rs | 4 ++-- crates/ra_analysis/src/imp.rs | 5 ++--- crates/ra_analysis/src/runnables.rs | 5 ++++- 4 files changed, 12 insertions(+), 7 deletions(-) (limited to 'crates/ra_analysis/src') diff --git a/crates/ra_analysis/src/completion/complete_scope.rs b/crates/ra_analysis/src/completion/complete_scope.rs index 21d77aa97..ee9052d3d 100644 --- a/crates/ra_analysis/src/completion/complete_scope.rs +++ b/crates/ra_analysis/src/completion/complete_scope.rs @@ -20,14 +20,17 @@ pub(super) fn complete_scope(acc: &mut Completions, ctx: &CompletionContext) -> } let module_scope = module.scope(ctx.db)?; + let (file_id, _) = module.defenition_source(ctx.db)?; module_scope .entries() .filter(|(_name, res)| { // Don't expose this item + // FIXME: this penetrates through all kinds of abstractions, + // we need to figura out the way to do it less ugly. match res.import { None => true, Some(import) => { - let range = import.range(ctx.db, module.file_id()); + let range = import.range(ctx.db, file_id); !range.is_subrange(&ctx.leaf.range()) } } diff --git a/crates/ra_analysis/src/goto_defenition.rs b/crates/ra_analysis/src/goto_defenition.rs index 68b6ac3ba..aa0616e3b 100644 --- a/crates/ra_analysis/src/goto_defenition.rs +++ b/crates/ra_analysis/src/goto_defenition.rs @@ -60,8 +60,8 @@ fn name_defenition( if let Some(child_module) = hir::source_binder::module_from_declaration(db, file_id, module)? { - let file_id = child_module.file_id(); - let name = match child_module.name() { + let (file_id, _) = child_module.defenition_source(db)?; + let name = match child_module.name(db)? { Some(name) => name.to_string().into(), None => "".into(), }; diff --git a/crates/ra_analysis/src/imp.rs b/crates/ra_analysis/src/imp.rs index 44e7aca44..07a966290 100644 --- a/crates/ra_analysis/src/imp.rs +++ b/crates/ra_analysis/src/imp.rs @@ -109,8 +109,7 @@ impl db::RootDatabase { None => return Ok(Vec::new()), Some(it) => it, }; - let (file_id, ast_module) = module.source(self); - let ast_module = match ast_module { + let (file_id, ast_module) = match module.declaration_source(self)? { None => return Ok(Vec::new()), Some(it) => it, }; @@ -206,7 +205,7 @@ impl db::RootDatabase { }) .collect::>(); if let Some(m) = source_binder::module_from_file_id(self, file_id)? { - for (name_node, problem) in m.problems(self) { + for (name_node, problem) in m.problems(self)? { let source_root = self.file_source_root(file_id); let diag = match problem { Problem::UnresolvedModule { candidate } => { diff --git a/crates/ra_analysis/src/runnables.rs b/crates/ra_analysis/src/runnables.rs index f24aa514a..216209098 100644 --- a/crates/ra_analysis/src/runnables.rs +++ b/crates/ra_analysis/src/runnables.rs @@ -72,12 +72,15 @@ fn runnable_mod(db: &RootDatabase, file_id: FileId, module: ast::Module) -> Opti let range = module.syntax().range(); let module = hir::source_binder::module_from_child_node(db, file_id, module.syntax()).ok()??; + + // FIXME: thread cancellation instead of `.ok`ing let path = module .path_to_root(db) .ok()? .into_iter() .rev() - .filter_map(|it| it.name(db).map(Clone::clone)) + .filter_map(|it| it.name(db).ok()) + .filter_map(|it| it) .join("::"); Some(Runnable { range, -- cgit v1.2.3