From 88a15d10d543c09ef66a9f105c3dcdb5011abbee Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 4 Nov 2018 20:21:20 +0300 Subject: use module_for_source --- crates/ra_analysis/src/imp.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'crates/ra_analysis/src/imp.rs') diff --git a/crates/ra_analysis/src/imp.rs b/crates/ra_analysis/src/imp.rs index 4f337d163..823ac9bdd 100644 --- a/crates/ra_analysis/src/imp.rs +++ b/crates/ra_analysis/src/imp.rs @@ -224,7 +224,7 @@ impl AnalysisImpl { let module_tree = self.module_tree(file_id)?; let res = module_tree - .modules_for_file(file_id) + .modules_for_source(ModuleSource::File(file_id)) .into_iter() .filter_map(|module_id| { let link = module_id.parent_link(&module_tree)?; @@ -252,7 +252,7 @@ impl AnalysisImpl { let module_tree = self.module_tree(file_id)?; let crate_graph = self.db.crate_graph(); let res = module_tree - .modules_for_file(file_id) + .modules_for_source(ModuleSource::File(file_id)) .into_iter() .map(|it| it.root(&module_tree)) .filter_map(|it| it.source(&module_tree).as_file()) @@ -376,7 +376,7 @@ impl AnalysisImpl { fix: None, }) .collect::>(); - if let Some(m) = module_tree.any_module_for_file(file_id) { + if let Some(m) = module_tree.any_module_for_source(ModuleSource::File(file_id)) { for (name_node, problem) in m.problems(&module_tree, &*self.db) { let diag = match problem { Problem::UnresolvedModule { candidate } => { @@ -539,7 +539,7 @@ impl AnalysisImpl { Some(name) => name.text(), None => return Vec::new(), }; - let module_id = match module_tree.any_module_for_file(file_id) { + let module_id = match module_tree.any_module_for_source(ModuleSource::File(file_id)) { Some(id) => id, None => return Vec::new(), }; -- cgit v1.2.3 From 6bbcfca7aec6408cf27415ae6f965adc472d6f18 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 5 Nov 2018 14:10:20 +0300 Subject: Fully add inline modules to module tree --- crates/ra_analysis/src/imp.rs | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) (limited to 'crates/ra_analysis/src/imp.rs') diff --git a/crates/ra_analysis/src/imp.rs b/crates/ra_analysis/src/imp.rs index 823ac9bdd..704648b59 100644 --- a/crates/ra_analysis/src/imp.rs +++ b/crates/ra_analysis/src/imp.rs @@ -220,27 +220,32 @@ impl AnalysisImpl { let source_root = self.db.file_source_root(file_id); self.db.module_tree(source_root) } - pub fn parent_module(&self, file_id: FileId) -> Cancelable> { + pub fn parent_module( + &self, + file_id: FileId, + offset: TextUnit, + ) -> Cancelable> { let module_tree = self.module_tree(file_id)?; + let file = self.db.file_syntax(file_id); + let module_source = match find_node_at_offset::(file.syntax(), offset) { + Some(m) if !m.has_semi() => ModuleSource::new_inline(file_id, m), + _ => ModuleSource::File(file_id), + }; let res = module_tree - .modules_for_source(ModuleSource::File(file_id)) + .modules_for_source(module_source) .into_iter() .filter_map(|module_id| { let link = module_id.parent_link(&module_tree)?; - let file_id = match link.owner(&module_tree).source(&module_tree) { - ModuleSource::File(file_id) => file_id, - ModuleSource::Inline(..) => { - //TODO: https://github.com/rust-analyzer/rust-analyzer/issues/181 - return None; - } - }; + let file_id = link.owner(&module_tree).source(&module_tree).file_id(); let decl = link.bind_source(&module_tree, &*self.db); let decl = decl.ast(); + let decl_name = decl.name().unwrap(); + let sym = FileSymbol { - name: decl.name().unwrap().text(), - node_range: decl.syntax().range(), + name: decl_name.text(), + node_range: decl_name.syntax().range(), kind: MODULE, }; Some((file_id, sym)) -- cgit v1.2.3