diff options
Diffstat (limited to 'crates/ra_analysis/src/descriptors/module/mod.rs')
-rw-r--r-- | crates/ra_analysis/src/descriptors/module/mod.rs | 30 |
1 files changed, 13 insertions, 17 deletions
diff --git a/crates/ra_analysis/src/descriptors/module/mod.rs b/crates/ra_analysis/src/descriptors/module/mod.rs index 667553f74..302e3e81c 100644 --- a/crates/ra_analysis/src/descriptors/module/mod.rs +++ b/crates/ra_analysis/src/descriptors/module/mod.rs | |||
@@ -1,8 +1,11 @@ | |||
1 | pub(super) mod imp; | 1 | pub(super) mod imp; |
2 | pub(crate) mod scope; | 2 | pub(crate) mod scope; |
3 | 3 | ||
4 | use ra_syntax::{ | ||
5 | ast::{self, AstNode, NameOwner}, | ||
6 | SmolStr, SyntaxNode, | ||
7 | }; | ||
4 | use relative_path::RelativePathBuf; | 8 | use relative_path::RelativePathBuf; |
5 | use ra_syntax::{ast::{self, NameOwner, AstNode}, SmolStr, SyntaxNode}; | ||
6 | 9 | ||
7 | use crate::FileId; | 10 | use crate::FileId; |
8 | 11 | ||
@@ -16,9 +19,11 @@ pub(crate) struct ModuleTree { | |||
16 | 19 | ||
17 | impl ModuleTree { | 20 | impl ModuleTree { |
18 | pub(crate) fn modules_for_file(&self, file_id: FileId) -> Vec<ModuleId> { | 21 | pub(crate) fn modules_for_file(&self, file_id: FileId) -> Vec<ModuleId> { |
19 | self.mods.iter() | 22 | self.mods |
23 | .iter() | ||
20 | .enumerate() | 24 | .enumerate() |
21 | .filter(|(_idx, it)| it.file_id == file_id).map(|(idx, _)| ModuleId(idx as u32)) | 25 | .filter(|(_idx, it)| it.file_id == file_id) |
26 | .map(|(idx, _)| ModuleId(idx as u32)) | ||
22 | .collect() | 27 | .collect() |
23 | } | 28 | } |
24 | 29 | ||
@@ -50,7 +55,7 @@ impl ModuleId { | |||
50 | } | 55 | } |
51 | pub(crate) fn parent_link(self, tree: &ModuleTree) -> Option<LinkId> { | 56 | pub(crate) fn parent_link(self, tree: &ModuleTree) -> Option<LinkId> { |
52 | tree.module(self).parent | 57 | tree.module(self).parent |
53 | } | 58 | } |
54 | pub(crate) fn parent(self, tree: &ModuleTree) -> Option<ModuleId> { | 59 | pub(crate) fn parent(self, tree: &ModuleTree) -> Option<ModuleId> { |
55 | let link = self.parent_link(tree)?; | 60 | let link = self.parent_link(tree)?; |
56 | Some(tree.link(link).owner) | 61 | Some(tree.link(link).owner) |
@@ -69,18 +74,15 @@ impl ModuleId { | |||
69 | curr | 74 | curr |
70 | } | 75 | } |
71 | pub(crate) fn child(self, tree: &ModuleTree, name: &str) -> Option<ModuleId> { | 76 | pub(crate) fn child(self, tree: &ModuleTree, name: &str) -> Option<ModuleId> { |
72 | let link = tree.module(self) | 77 | let link = tree |
78 | .module(self) | ||
73 | .children | 79 | .children |
74 | .iter() | 80 | .iter() |
75 | .map(|&it| tree.link(it)) | 81 | .map(|&it| tree.link(it)) |
76 | .find(|it| it.name == name)?; | 82 | .find(|it| it.name == name)?; |
77 | Some(*link.points_to.first()?) | 83 | Some(*link.points_to.first()?) |
78 | } | 84 | } |
79 | pub(crate) fn problems( | 85 | pub(crate) fn problems(self, tree: &ModuleTree, root: ast::Root) -> Vec<(SyntaxNode, Problem)> { |
80 | self, | ||
81 | tree: &ModuleTree, | ||
82 | root: ast::Root, | ||
83 | ) -> Vec<(SyntaxNode, Problem)> { | ||
84 | tree.module(self) | 86 | tree.module(self) |
85 | .children | 87 | .children |
86 | .iter() | 88 | .iter() |
@@ -98,11 +100,7 @@ impl LinkId { | |||
98 | pub(crate) fn owner(self, tree: &ModuleTree) -> ModuleId { | 100 | pub(crate) fn owner(self, tree: &ModuleTree) -> ModuleId { |
99 | tree.link(self).owner | 101 | tree.link(self).owner |
100 | } | 102 | } |
101 | pub(crate) fn bind_source<'a>( | 103 | pub(crate) fn bind_source<'a>(self, tree: &ModuleTree, root: ast::Root<'a>) -> ast::Module<'a> { |
102 | self, | ||
103 | tree: &ModuleTree, | ||
104 | root: ast::Root<'a>, | ||
105 | ) -> ast::Module<'a> { | ||
106 | imp::modules(root) | 104 | imp::modules(root) |
107 | .find(|(name, _)| name == &tree.link(self).name) | 105 | .find(|(name, _)| name == &tree.link(self).name) |
108 | .unwrap() | 106 | .unwrap() |
@@ -125,7 +123,6 @@ struct LinkData { | |||
125 | problem: Option<Problem>, | 123 | problem: Option<Problem>, |
126 | } | 124 | } |
127 | 125 | ||
128 | |||
129 | impl ModuleTree { | 126 | impl ModuleTree { |
130 | fn module(&self, id: ModuleId) -> &ModuleData { | 127 | fn module(&self, id: ModuleId) -> &ModuleData { |
131 | &self.mods[id.0 as usize] | 128 | &self.mods[id.0 as usize] |
@@ -152,4 +149,3 @@ impl ModuleTree { | |||
152 | id | 149 | id |
153 | } | 150 | } |
154 | } | 151 | } |
155 | |||