aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_analysis/src/descriptors/module/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_analysis/src/descriptors/module/mod.rs')
-rw-r--r--crates/ra_analysis/src/descriptors/module/mod.rs29
1 files changed, 18 insertions, 11 deletions
diff --git a/crates/ra_analysis/src/descriptors/module/mod.rs b/crates/ra_analysis/src/descriptors/module/mod.rs
index e22489fc1..3d799ba05 100644
--- a/crates/ra_analysis/src/descriptors/module/mod.rs
+++ b/crates/ra_analysis/src/descriptors/module/mod.rs
@@ -25,17 +25,17 @@ pub(crate) struct ModuleTree {
25} 25}
26 26
27impl ModuleTree { 27impl ModuleTree {
28 pub(crate) fn modules_for_file(&self, file_id: FileId) -> Vec<ModuleId> { 28 pub(crate) fn modules_for_source(&self, source: ModuleSource) -> Vec<ModuleId> {
29 self.mods 29 self.mods
30 .iter() 30 .iter()
31 .enumerate() 31 .enumerate()
32 .filter(|(_idx, it)| it.source.is_file(file_id)) 32 .filter(|(_idx, it)| it.source == source)
33 .map(|(idx, _)| ModuleId(idx as u32)) 33 .map(|(idx, _)| ModuleId(idx as u32))
34 .collect() 34 .collect()
35 } 35 }
36 36
37 pub(crate) fn any_module_for_file(&self, file_id: FileId) -> Option<ModuleId> { 37 pub(crate) fn any_module_for_source(&self, source: ModuleSource) -> Option<ModuleId> {
38 self.modules_for_file(file_id).pop() 38 self.modules_for_source(source).pop()
39 } 39 }
40} 40}
41 41
@@ -142,9 +142,7 @@ impl LinkId {
142 .1; 142 .1;
143 ast.into() 143 ast.into()
144 } 144 }
145 ModuleSourceNode::Inline(..) => { 145 ModuleSourceNode::Inline(it) => it,
146 unimplemented!("https://github.com/rust-analyzer/rust-analyzer/issues/181")
147 }
148 } 146 }
149 } 147 }
150} 148}
@@ -157,6 +155,12 @@ struct ModuleData {
157} 155}
158 156
159impl ModuleSource { 157impl ModuleSource {
158 pub(crate) fn new_inline(file_id: FileId, module: ast::Module) -> ModuleSource {
159 assert!(!module.has_semi());
160 let ptr = SyntaxPtr::new(file_id, module.syntax());
161 ModuleSource::Inline(ptr)
162 }
163
160 pub(crate) fn as_file(self) -> Option<FileId> { 164 pub(crate) fn as_file(self) -> Option<FileId> {
161 match self { 165 match self {
162 ModuleSource::File(f) => Some(f), 166 ModuleSource::File(f) => Some(f),
@@ -164,6 +168,13 @@ impl ModuleSource {
164 } 168 }
165 } 169 }
166 170
171 pub(crate) fn file_id(self) -> FileId {
172 match self {
173 ModuleSource::File(f) => f,
174 ModuleSource::Inline(ptr) => ptr.file_id(),
175 }
176 }
177
167 fn resolve(self, db: &impl SyntaxDatabase) -> ModuleSourceNode { 178 fn resolve(self, db: &impl SyntaxDatabase) -> ModuleSourceNode {
168 match self { 179 match self {
169 ModuleSource::File(file_id) => { 180 ModuleSource::File(file_id) => {
@@ -178,10 +189,6 @@ impl ModuleSource {
178 } 189 }
179 } 190 }
180 } 191 }
181
182 fn is_file(self, file_id: FileId) -> bool {
183 self.as_file() == Some(file_id)
184 }
185} 192}
186 193
187#[derive(Hash, Debug, PartialEq, Eq)] 194#[derive(Hash, Debug, PartialEq, Eq)]