diff options
Diffstat (limited to 'crates/ra_analysis/src/descriptors')
-rw-r--r-- | crates/ra_analysis/src/descriptors/module/imp.rs | 24 | ||||
-rw-r--r-- | crates/ra_analysis/src/descriptors/module/mod.rs | 9 |
2 files changed, 16 insertions, 17 deletions
diff --git a/crates/ra_analysis/src/descriptors/module/imp.rs b/crates/ra_analysis/src/descriptors/module/imp.rs index 22e4bd785..aecf6e29a 100644 --- a/crates/ra_analysis/src/descriptors/module/imp.rs +++ b/crates/ra_analysis/src/descriptors/module/imp.rs | |||
@@ -8,8 +8,8 @@ use ra_syntax::{ | |||
8 | }; | 8 | }; |
9 | 9 | ||
10 | use crate::{ | 10 | use crate::{ |
11 | FileId, Cancelable, FileResolverImp, | 11 | FileId, Cancelable, FileResolverImp, db, |
12 | db, | 12 | input::{SourceRoot, SourceRootId}, |
13 | }; | 13 | }; |
14 | 14 | ||
15 | use super::{ | 15 | use super::{ |
@@ -35,9 +35,12 @@ pub(super) fn modules(root: ast::Root<'_>) -> impl Iterator<Item = (SmolStr, ast | |||
35 | }) | 35 | }) |
36 | } | 36 | } |
37 | 37 | ||
38 | pub(super) fn module_tree(db: &impl ModulesDatabase) -> Cancelable<Arc<ModuleTree>> { | 38 | pub(super) fn module_tree( |
39 | db: &impl ModulesDatabase, | ||
40 | source_root: SourceRootId, | ||
41 | ) -> Cancelable<Arc<ModuleTree>> { | ||
39 | db::check_canceled(db)?; | 42 | db::check_canceled(db)?; |
40 | let res = create_module_tree(db)?; | 43 | let res = create_module_tree(db, source_root)?; |
41 | Ok(Arc::new(res)) | 44 | Ok(Arc::new(res)) |
42 | } | 45 | } |
43 | 46 | ||
@@ -50,6 +53,7 @@ pub struct Submodule { | |||
50 | 53 | ||
51 | fn create_module_tree<'a>( | 54 | fn create_module_tree<'a>( |
52 | db: &impl ModulesDatabase, | 55 | db: &impl ModulesDatabase, |
56 | source_root: SourceRootId, | ||
53 | ) -> Cancelable<ModuleTree> { | 57 | ) -> Cancelable<ModuleTree> { |
54 | let mut tree = ModuleTree { | 58 | let mut tree = ModuleTree { |
55 | mods: Vec::new(), | 59 | mods: Vec::new(), |
@@ -59,12 +63,13 @@ fn create_module_tree<'a>( | |||
59 | let mut roots = FxHashMap::default(); | 63 | let mut roots = FxHashMap::default(); |
60 | let mut visited = FxHashSet::default(); | 64 | let mut visited = FxHashSet::default(); |
61 | 65 | ||
62 | for &file_id in db.file_set().files.iter() { | 66 | let source_root = db.source_root(source_root); |
67 | for &file_id in source_root.files.iter() { | ||
63 | if visited.contains(&file_id) { | 68 | if visited.contains(&file_id) { |
64 | continue; // TODO: use explicit crate_roots here | 69 | continue; // TODO: use explicit crate_roots here |
65 | } | 70 | } |
66 | assert!(!roots.contains_key(&file_id)); | 71 | assert!(!roots.contains_key(&file_id)); |
67 | let module_id = build_subtree(db, &mut tree, &mut visited, &mut roots, None, file_id)?; | 72 | let module_id = build_subtree(db, &source_root, &mut tree, &mut visited, &mut roots, None, file_id)?; |
68 | roots.insert(file_id, module_id); | 73 | roots.insert(file_id, module_id); |
69 | } | 74 | } |
70 | Ok(tree) | 75 | Ok(tree) |
@@ -72,6 +77,7 @@ fn create_module_tree<'a>( | |||
72 | 77 | ||
73 | fn build_subtree( | 78 | fn build_subtree( |
74 | db: &impl ModulesDatabase, | 79 | db: &impl ModulesDatabase, |
80 | source_root: &SourceRoot, | ||
75 | tree: &mut ModuleTree, | 81 | tree: &mut ModuleTree, |
76 | visited: &mut FxHashSet<FileId>, | 82 | visited: &mut FxHashSet<FileId>, |
77 | roots: &mut FxHashMap<FileId, ModuleId>, | 83 | roots: &mut FxHashMap<FileId, ModuleId>, |
@@ -84,10 +90,8 @@ fn build_subtree( | |||
84 | parent, | 90 | parent, |
85 | children: Vec::new(), | 91 | children: Vec::new(), |
86 | }); | 92 | }); |
87 | let file_set = db.file_set(); | ||
88 | let file_resolver = &file_set.resolver; | ||
89 | for name in db.submodules(file_id)?.iter() { | 93 | for name in db.submodules(file_id)?.iter() { |
90 | let (points_to, problem) = resolve_submodule(file_id, name, file_resolver); | 94 | let (points_to, problem) = resolve_submodule(file_id, name, &source_root.file_resolver); |
91 | let link = tree.push_link(LinkData { | 95 | let link = tree.push_link(LinkData { |
92 | name: name.clone(), | 96 | name: name.clone(), |
93 | owner: id, | 97 | owner: id, |
@@ -102,7 +106,7 @@ fn build_subtree( | |||
102 | tree.module_mut(module_id).parent = Some(link); | 106 | tree.module_mut(module_id).parent = Some(link); |
103 | Ok(module_id) | 107 | Ok(module_id) |
104 | } | 108 | } |
105 | None => build_subtree(db, tree, visited, roots, Some(link), file_id), | 109 | None => build_subtree(db, source_root, tree, visited, roots, Some(link), file_id), |
106 | }) | 110 | }) |
107 | .collect::<Cancelable<Vec<_>>>()?; | 111 | .collect::<Cancelable<Vec<_>>>()?; |
108 | tree.link_mut(link).points_to = points_to; | 112 | tree.link_mut(link).points_to = points_to; |
diff --git a/crates/ra_analysis/src/descriptors/module/mod.rs b/crates/ra_analysis/src/descriptors/module/mod.rs index 52da650b3..8968c4afd 100644 --- a/crates/ra_analysis/src/descriptors/module/mod.rs +++ b/crates/ra_analysis/src/descriptors/module/mod.rs | |||
@@ -8,11 +8,12 @@ use ra_syntax::{ast::{self, NameOwner, AstNode}, SmolStr, SyntaxNode}; | |||
8 | use crate::{ | 8 | use crate::{ |
9 | FileId, Cancelable, | 9 | FileId, Cancelable, |
10 | db::SyntaxDatabase, | 10 | db::SyntaxDatabase, |
11 | input::SourceRootId, | ||
11 | }; | 12 | }; |
12 | 13 | ||
13 | salsa::query_group! { | 14 | salsa::query_group! { |
14 | pub(crate) trait ModulesDatabase: SyntaxDatabase { | 15 | pub(crate) trait ModulesDatabase: SyntaxDatabase { |
15 | fn module_tree() -> Cancelable<Arc<ModuleTree>> { | 16 | fn module_tree(source_root_id: SourceRootId) -> Cancelable<Arc<ModuleTree>> { |
16 | type ModuleTreeQuery; | 17 | type ModuleTreeQuery; |
17 | use fn imp::module_tree; | 18 | use fn imp::module_tree; |
18 | } | 19 | } |
@@ -110,15 +111,9 @@ impl ModuleId { | |||
110 | } | 111 | } |
111 | 112 | ||
112 | impl LinkId { | 113 | impl LinkId { |
113 | pub(crate) fn name(self, tree: &ModuleTree) -> SmolStr { | ||
114 | tree.link(self).name.clone() | ||
115 | } | ||
116 | pub(crate) fn owner(self, tree: &ModuleTree) -> ModuleId { | 114 | pub(crate) fn owner(self, tree: &ModuleTree) -> ModuleId { |
117 | tree.link(self).owner | 115 | tree.link(self).owner |
118 | } | 116 | } |
119 | fn points_to(self, tree: &ModuleTree) -> &[ModuleId] { | ||
120 | &tree.link(self).points_to | ||
121 | } | ||
122 | pub(crate) fn bind_source<'a>( | 117 | pub(crate) fn bind_source<'a>( |
123 | self, | 118 | self, |
124 | tree: &ModuleTree, | 119 | tree: &ModuleTree, |