aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_analysis/src/hir/module/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_analysis/src/hir/module/mod.rs')
-rw-r--r--crates/ra_analysis/src/hir/module/mod.rs23
1 files changed, 10 insertions, 13 deletions
diff --git a/crates/ra_analysis/src/hir/module/mod.rs b/crates/ra_analysis/src/hir/module/mod.rs
index f374a079f..5bff11c90 100644
--- a/crates/ra_analysis/src/hir/module/mod.rs
+++ b/crates/ra_analysis/src/hir/module/mod.rs
@@ -14,7 +14,7 @@ use relative_path::RelativePathBuf;
14 14
15use crate::{ 15use crate::{
16 db::SyntaxDatabase, syntax_ptr::SyntaxPtr, FileId, FilePosition, Cancelable, 16 db::SyntaxDatabase, syntax_ptr::SyntaxPtr, FileId, FilePosition, Cancelable,
17 hir::{Path, PathKind, DescriptorDatabase}, 17 hir::{Path, PathKind, HirDatabase},
18 input::SourceRootId, 18 input::SourceRootId,
19 arena::{Arena, Id}, 19 arena::{Arena, Id},
20 loc2id::{DefLoc, DefId}, 20 loc2id::{DefLoc, DefId},
@@ -36,7 +36,7 @@ impl ModuleDescriptor {
36 /// lossy transformation: in general, a single source might correspond to 36 /// lossy transformation: in general, a single source might correspond to
37 /// several modules. 37 /// several modules.
38 pub fn guess_from_file_id( 38 pub fn guess_from_file_id(
39 db: &impl DescriptorDatabase, 39 db: &impl HirDatabase,
40 file_id: FileId, 40 file_id: FileId,
41 ) -> Cancelable<Option<ModuleDescriptor>> { 41 ) -> Cancelable<Option<ModuleDescriptor>> {
42 ModuleDescriptor::guess_from_source(db, file_id, ModuleSource::SourceFile(file_id)) 42 ModuleDescriptor::guess_from_source(db, file_id, ModuleSource::SourceFile(file_id))
@@ -46,7 +46,7 @@ impl ModuleDescriptor {
46 /// is inherently lossy transformation: in general, a single source might 46 /// is inherently lossy transformation: in general, a single source might
47 /// correspond to several modules. 47 /// correspond to several modules.
48 pub fn guess_from_position( 48 pub fn guess_from_position(
49 db: &impl DescriptorDatabase, 49 db: &impl HirDatabase,
50 position: FilePosition, 50 position: FilePosition,
51 ) -> Cancelable<Option<ModuleDescriptor>> { 51 ) -> Cancelable<Option<ModuleDescriptor>> {
52 let file = db.file_syntax(position.file_id); 52 let file = db.file_syntax(position.file_id);
@@ -59,7 +59,7 @@ impl ModuleDescriptor {
59 } 59 }
60 60
61 fn guess_from_source( 61 fn guess_from_source(
62 db: &impl DescriptorDatabase, 62 db: &impl HirDatabase,
63 file_id: FileId, 63 file_id: FileId,
64 module_source: ModuleSource, 64 module_source: ModuleSource,
65 ) -> Cancelable<Option<ModuleDescriptor>> { 65 ) -> Cancelable<Option<ModuleDescriptor>> {
@@ -78,7 +78,7 @@ impl ModuleDescriptor {
78 } 78 }
79 79
80 pub(super) fn new( 80 pub(super) fn new(
81 db: &impl DescriptorDatabase, 81 db: &impl HirDatabase,
82 source_root_id: SourceRootId, 82 source_root_id: SourceRootId,
83 module_id: ModuleId, 83 module_id: ModuleId,
84 ) -> Cancelable<ModuleDescriptor> { 84 ) -> Cancelable<ModuleDescriptor> {
@@ -93,10 +93,7 @@ impl ModuleDescriptor {
93 93
94 /// Returns `mod foo;` or `mod foo {}` node whihc declared this module. 94 /// Returns `mod foo;` or `mod foo {}` node whihc declared this module.
95 /// Returns `None` for the root module 95 /// Returns `None` for the root module
96 pub fn parent_link_source( 96 pub fn parent_link_source(&self, db: &impl HirDatabase) -> Option<(FileId, ast::ModuleNode)> {
97 &self,
98 db: &impl DescriptorDatabase,
99 ) -> Option<(FileId, ast::ModuleNode)> {
100 let link = self.module_id.parent_link(&self.tree)?; 97 let link = self.module_id.parent_link(&self.tree)?;
101 let file_id = link.owner(&self.tree).source(&self.tree).file_id(); 98 let file_id = link.owner(&self.tree).source(&self.tree).file_id();
102 let src = link.bind_source(&self.tree, db); 99 let src = link.bind_source(&self.tree, db);
@@ -132,7 +129,7 @@ impl ModuleDescriptor {
132 Some(link.name(&self.tree)) 129 Some(link.name(&self.tree))
133 } 130 }
134 131
135 pub fn def_id(&self, db: &impl DescriptorDatabase) -> DefId { 132 pub fn def_id(&self, db: &impl HirDatabase) -> DefId {
136 let def_loc = DefLoc::Module { 133 let def_loc = DefLoc::Module {
137 id: self.module_id, 134 id: self.module_id,
138 source_root: self.source_root_id, 135 source_root: self.source_root_id,
@@ -150,7 +147,7 @@ impl ModuleDescriptor {
150 } 147 }
151 148
152 /// Returns a `ModuleScope`: a set of items, visible in this module. 149 /// Returns a `ModuleScope`: a set of items, visible in this module.
153 pub(crate) fn scope(&self, db: &impl DescriptorDatabase) -> Cancelable<ModuleScope> { 150 pub(crate) fn scope(&self, db: &impl HirDatabase) -> Cancelable<ModuleScope> {
154 let item_map = db._item_map(self.source_root_id)?; 151 let item_map = db._item_map(self.source_root_id)?;
155 let res = item_map.per_module[&self.module_id].clone(); 152 let res = item_map.per_module[&self.module_id].clone();
156 Ok(res) 153 Ok(res)
@@ -158,7 +155,7 @@ impl ModuleDescriptor {
158 155
159 pub(crate) fn resolve_path( 156 pub(crate) fn resolve_path(
160 &self, 157 &self,
161 db: &impl DescriptorDatabase, 158 db: &impl HirDatabase,
162 path: Path, 159 path: Path,
163 ) -> Cancelable<Option<DefId>> { 160 ) -> Cancelable<Option<DefId>> {
164 let mut curr = match path.kind { 161 let mut curr = match path.kind {
@@ -180,7 +177,7 @@ impl ModuleDescriptor {
180 Ok(Some(curr)) 177 Ok(Some(curr))
181 } 178 }
182 179
183 pub fn problems(&self, db: &impl DescriptorDatabase) -> Vec<(SyntaxNode, Problem)> { 180 pub fn problems(&self, db: &impl HirDatabase) -> Vec<(SyntaxNode, Problem)> {
184 self.module_id.problems(&self.tree, db) 181 self.module_id.problems(&self.tree, db)
185 } 182 }
186} 183}