aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_analysis/src/descriptors/module/mod.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-10-31 20:41:43 +0000
committerAleksey Kladov <[email protected]>2018-10-31 20:41:43 +0000
commit6be50f7d5de3737464853a589673375fc0cafa97 (patch)
tree2c6da7f3a1234c3f2fd3f330d2c9445953979598 /crates/ra_analysis/src/descriptors/module/mod.rs
parent857c1650efdb51650458f9ec1119adaa49b34371 (diff)
Reformat all
Diffstat (limited to 'crates/ra_analysis/src/descriptors/module/mod.rs')
-rw-r--r--crates/ra_analysis/src/descriptors/module/mod.rs30
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 @@
1pub(super) mod imp; 1pub(super) mod imp;
2pub(crate) mod scope; 2pub(crate) mod scope;
3 3
4use ra_syntax::{
5 ast::{self, AstNode, NameOwner},
6 SmolStr, SyntaxNode,
7};
4use relative_path::RelativePathBuf; 8use relative_path::RelativePathBuf;
5use ra_syntax::{ast::{self, NameOwner, AstNode}, SmolStr, SyntaxNode};
6 9
7use crate::FileId; 10use crate::FileId;
8 11
@@ -16,9 +19,11 @@ pub(crate) struct ModuleTree {
16 19
17impl ModuleTree { 20impl 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
129impl ModuleTree { 126impl 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