From 21508cfb2f5452c6f19ab0e615a6c61cb28154c8 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 20 Nov 2018 16:55:35 +0300 Subject: Use OO API instead of resolve_module --- crates/ra_analysis/src/descriptors/module/mod.rs | 13 +----- crates/ra_analysis/src/imp.rs | 58 +++++++----------------- 2 files changed, 19 insertions(+), 52 deletions(-) (limited to 'crates') diff --git a/crates/ra_analysis/src/descriptors/module/mod.rs b/crates/ra_analysis/src/descriptors/module/mod.rs index 16faea94e..d0560244a 100644 --- a/crates/ra_analysis/src/descriptors/module/mod.rs +++ b/crates/ra_analysis/src/descriptors/module/mod.rs @@ -165,15 +165,6 @@ enum ModuleSourceNode { #[derive(Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, Debug)] pub(crate) struct ModuleId(u32); -impl crate::loc2id::NumericId for ModuleId { - fn from_u32(id: u32) -> Self { - ModuleId(id) - } - fn to_u32(self) -> u32 { - self.0 - } -} - #[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)] struct LinkId(u32); @@ -189,13 +180,13 @@ pub enum Problem { } impl ModuleId { - pub(crate) fn source(self, tree: &ModuleTree) -> ModuleSource { + fn source(self, tree: &ModuleTree) -> ModuleSource { tree.module(self).source } fn parent_link(self, tree: &ModuleTree) -> Option { tree.module(self).parent } - pub(crate) fn parent(self, tree: &ModuleTree) -> Option { + fn parent(self, tree: &ModuleTree) -> Option { let link = self.parent_link(tree)?; Some(tree.link(link).owner) } diff --git a/crates/ra_analysis/src/imp.rs b/crates/ra_analysis/src/imp.rs index 49b863756..1bbf0cb6d 100644 --- a/crates/ra_analysis/src/imp.rs +++ b/crates/ra_analysis/src/imp.rs @@ -266,7 +266,6 @@ impl AnalysisImpl { &self, position: FilePosition, ) -> Cancelable> { - let module_tree = self.module_tree(position.file_id)?; let file = self.db.file_syntax(position.file_id); let syntax = file.syntax(); if let Some(name_ref) = find_node_at_offset::(syntax, position.offset) { @@ -292,25 +291,23 @@ impl AnalysisImpl { if let Some(name) = find_node_at_offset::(syntax, position.offset) { if let Some(module) = name.syntax().parent().and_then(ast::Module::cast) { if module.has_semi() { - let file_ids = self.resolve_module(&*module_tree, position.file_id, module); - - let res = file_ids - .into_iter() - .map(|id| { - let name = module - .name() - .map(|n| n.text()) - .unwrap_or_else(|| SmolStr::new("")); - let symbol = FileSymbol { - name, - node_range: TextRange::offset_len(0.into(), 0.into()), - kind: MODULE, - }; - (id, symbol) - }) - .collect(); - - return Ok(res); + let parent_module = + ModuleDescriptor::guess_from_file_id(&*self.db, position.file_id)?; + let child_name = module.name(); + match (parent_module, child_name) { + (Some(parent_module), Some(child_name)) => { + if let Some(child) = parent_module.child(&child_name.text()) { + let file_id = child.source().file_id(); + let symbol = FileSymbol { + name: child_name.text(), + node_range: TextRange::offset_len(0.into(), 0.into()), + kind: MODULE, + }; + return Ok(vec![(file_id, symbol)]); + } + } + _ => (), + } } } } @@ -519,27 +516,6 @@ impl AnalysisImpl { query.limit(4); self.world_symbols(query) } - - fn resolve_module( - &self, - module_tree: &ModuleTree, - file_id: FileId, - module: ast::Module, - ) -> Vec { - let name = match module.name() { - Some(name) => name.text(), - None => return Vec::new(), - }; - let module_id = match module_tree.any_module_for_source(ModuleSource::SourceFile(file_id)) { - Some(id) => id, - None => return Vec::new(), - }; - module_id - .child(module_tree, name.as_str()) - .and_then(|it| it.source(&module_tree).as_file()) - .into_iter() - .collect() - } } impl SourceChange { -- cgit v1.2.3