diff options
Diffstat (limited to 'crates/ra_analysis/src/descriptors/module')
-rw-r--r-- | crates/ra_analysis/src/descriptors/module/imp.rs | 33 | ||||
-rw-r--r-- | crates/ra_analysis/src/descriptors/module/mod.rs | 30 | ||||
-rw-r--r-- | crates/ra_analysis/src/descriptors/module/scope.rs | 5 |
3 files changed, 35 insertions, 33 deletions
diff --git a/crates/ra_analysis/src/descriptors/module/imp.rs b/crates/ra_analysis/src/descriptors/module/imp.rs index dae3a356d..1c102f4e5 100644 --- a/crates/ra_analysis/src/descriptors/module/imp.rs +++ b/crates/ra_analysis/src/descriptors/module/imp.rs | |||
@@ -1,24 +1,25 @@ | |||
1 | use std::sync::Arc; | 1 | use std::sync::Arc; |
2 | 2 | ||
3 | use relative_path::RelativePathBuf; | ||
4 | use rustc_hash::{FxHashMap, FxHashSet}; | ||
5 | use ra_syntax::{ | 3 | use ra_syntax::{ |
6 | SmolStr, | ||
7 | ast::{self, NameOwner}, | 4 | ast::{self, NameOwner}, |
5 | SmolStr, | ||
8 | }; | 6 | }; |
7 | use relative_path::RelativePathBuf; | ||
8 | use rustc_hash::{FxHashMap, FxHashSet}; | ||
9 | 9 | ||
10 | use crate::{ | 10 | use crate::{ |
11 | FileId, Cancelable, FileResolverImp, db, | 11 | db, |
12 | input::{SourceRoot, SourceRootId}, | ||
13 | descriptors::DescriptorDatabase, | 12 | descriptors::DescriptorDatabase, |
13 | input::{SourceRoot, SourceRootId}, | ||
14 | Cancelable, FileId, FileResolverImp, | ||
14 | }; | 15 | }; |
15 | 16 | ||
16 | use super::{ | 17 | use super::{LinkData, LinkId, ModuleData, ModuleId, ModuleScope, ModuleTree, Problem}; |
17 | ModuleData, ModuleTree, ModuleId, LinkId, LinkData, Problem, ModuleScope | ||
18 | }; | ||
19 | |||
20 | 18 | ||
21 | pub(crate) fn submodules(db: &impl DescriptorDatabase, file_id: FileId) -> Cancelable<Arc<Vec<SmolStr>>> { | 19 | pub(crate) fn submodules( |
20 | db: &impl DescriptorDatabase, | ||
21 | file_id: FileId, | ||
22 | ) -> Cancelable<Arc<Vec<SmolStr>>> { | ||
22 | db::check_canceled(db)?; | 23 | db::check_canceled(db)?; |
23 | let file = db.file_syntax(file_id); | 24 | let file = db.file_syntax(file_id); |
24 | let root = file.ast(); | 25 | let root = file.ast(); |
@@ -57,13 +58,11 @@ pub(crate) fn module_tree( | |||
57 | Ok(Arc::new(res)) | 58 | Ok(Arc::new(res)) |
58 | } | 59 | } |
59 | 60 | ||
60 | |||
61 | #[derive(Clone, Hash, PartialEq, Eq, Debug)] | 61 | #[derive(Clone, Hash, PartialEq, Eq, Debug)] |
62 | pub struct Submodule { | 62 | pub struct Submodule { |
63 | pub name: SmolStr, | 63 | pub name: SmolStr, |
64 | } | 64 | } |
65 | 65 | ||
66 | |||
67 | fn create_module_tree<'a>( | 66 | fn create_module_tree<'a>( |
68 | db: &impl DescriptorDatabase, | 67 | db: &impl DescriptorDatabase, |
69 | source_root: SourceRootId, | 68 | source_root: SourceRootId, |
@@ -82,7 +81,15 @@ fn create_module_tree<'a>( | |||
82 | continue; // TODO: use explicit crate_roots here | 81 | continue; // TODO: use explicit crate_roots here |
83 | } | 82 | } |
84 | assert!(!roots.contains_key(&file_id)); | 83 | assert!(!roots.contains_key(&file_id)); |
85 | let module_id = build_subtree(db, &source_root, &mut tree, &mut visited, &mut roots, None, file_id)?; | 84 | let module_id = build_subtree( |
85 | db, | ||
86 | &source_root, | ||
87 | &mut tree, | ||
88 | &mut visited, | ||
89 | &mut roots, | ||
90 | None, | ||
91 | file_id, | ||
92 | )?; | ||
86 | roots.insert(file_id, module_id); | 93 | roots.insert(file_id, module_id); |
87 | } | 94 | } |
88 | Ok(tree) | 95 | Ok(tree) |
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 | |||
diff --git a/crates/ra_analysis/src/descriptors/module/scope.rs b/crates/ra_analysis/src/descriptors/module/scope.rs index 846b8b44f..681e272c2 100644 --- a/crates/ra_analysis/src/descriptors/module/scope.rs +++ b/crates/ra_analysis/src/descriptors/module/scope.rs | |||
@@ -1,9 +1,8 @@ | |||
1 | //! Backend for module-level scope resolution & completion | 1 | //! Backend for module-level scope resolution & completion |
2 | 2 | ||
3 | |||
4 | use ra_syntax::{ | 3 | use ra_syntax::{ |
5 | ast::{self, ModuleItemOwner}, | 4 | ast::{self, ModuleItemOwner}, |
6 | File, AstNode, SmolStr, | 5 | AstNode, File, SmolStr, |
7 | }; | 6 | }; |
8 | 7 | ||
9 | use crate::syntax_ptr::LocalSyntaxPtr; | 8 | use crate::syntax_ptr::LocalSyntaxPtr; |
@@ -103,7 +102,7 @@ fn collect_imports(tree: ast::UseTree, acc: &mut Vec<Entry>) { | |||
103 | #[cfg(test)] | 102 | #[cfg(test)] |
104 | mod tests { | 103 | mod tests { |
105 | use super::*; | 104 | use super::*; |
106 | use ra_syntax::{File}; | 105 | use ra_syntax::File; |
107 | 106 | ||
108 | fn do_check(code: &str, expected: &[&str]) { | 107 | fn do_check(code: &str, expected: &[&str]) { |
109 | let file = File::parse(&code); | 108 | let file = File::parse(&code); |