aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_analysis/src/descriptors/module
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_analysis/src/descriptors/module')
-rw-r--r--crates/ra_analysis/src/descriptors/module/imp.rs29
1 files changed, 18 insertions, 11 deletions
diff --git a/crates/ra_analysis/src/descriptors/module/imp.rs b/crates/ra_analysis/src/descriptors/module/imp.rs
index 3a010ecf5..b9cd81739 100644
--- a/crates/ra_analysis/src/descriptors/module/imp.rs
+++ b/crates/ra_analysis/src/descriptors/module/imp.rs
@@ -19,14 +19,25 @@ use super::{
19 ModuleTree, Problem, 19 ModuleTree, Problem,
20}; 20};
21 21
22#[derive(Clone, Hash, PartialEq, Eq, Debug)]
23pub(crate) struct Submodule {
24 name: SmolStr
25}
26
22pub(crate) fn submodules( 27pub(crate) fn submodules(
23 db: &impl DescriptorDatabase, 28 db: &impl DescriptorDatabase,
24 file_id: FileId, 29 source: ModuleSource,
25) -> Cancelable<Arc<Vec<SmolStr>>> { 30) -> Cancelable<Arc<Vec<Submodule>>> {
26 db::check_canceled(db)?; 31 db::check_canceled(db)?;
32 let file_id = match source {
33 ModuleSource::File(it) => it,
34 _ => unimplemented!(),
35 };
27 let file = db.file_syntax(file_id); 36 let file = db.file_syntax(file_id);
28 let root = file.ast(); 37 let root = file.ast();
29 let submodules = modules(root).map(|(name, _)| name).collect(); 38 let submodules = modules(root)
39 .map(|(name, _)| Submodule { name })
40 .collect();
30 Ok(Arc::new(submodules)) 41 Ok(Arc::new(submodules))
31} 42}
32 43
@@ -66,11 +77,6 @@ pub(crate) fn module_tree(
66 Ok(Arc::new(res)) 77 Ok(Arc::new(res))
67} 78}
68 79
69#[derive(Clone, Hash, PartialEq, Eq, Debug)]
70pub struct Submodule {
71 pub name: SmolStr,
72}
73
74fn create_module_tree<'a>( 80fn create_module_tree<'a>(
75 db: &impl DescriptorDatabase, 81 db: &impl DescriptorDatabase,
76 source_root: SourceRootId, 82 source_root: SourceRootId,
@@ -118,10 +124,11 @@ fn build_subtree(
118 parent, 124 parent,
119 children: Vec::new(), 125 children: Vec::new(),
120 }); 126 });
121 for name in db.submodules(file_id)?.iter() { 127 for sub in db.submodules(ModuleSource::File(file_id))?.iter() {
122 let (points_to, problem) = resolve_submodule(file_id, name, &source_root.file_resolver); 128 let name = sub.name.clone();
129 let (points_to, problem) = resolve_submodule(file_id, &name, &source_root.file_resolver);
123 let link = tree.push_link(LinkData { 130 let link = tree.push_link(LinkData {
124 name: name.clone(), 131 name,
125 owner: id, 132 owner: id,
126 points_to: Vec::new(), 133 points_to: Vec::new(),
127 problem: None, 134 problem: None,