diff options
Diffstat (limited to 'crates/ra_analysis/src/descriptors/module/mod.rs')
-rw-r--r-- | crates/ra_analysis/src/descriptors/module/mod.rs | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/crates/ra_analysis/src/descriptors/module/mod.rs b/crates/ra_analysis/src/descriptors/module/mod.rs index cfdffcdbc..acc6c1c5a 100644 --- a/crates/ra_analysis/src/descriptors/module/mod.rs +++ b/crates/ra_analysis/src/descriptors/module/mod.rs | |||
@@ -14,11 +14,11 @@ use relative_path::RelativePathBuf; | |||
14 | 14 | ||
15 | use crate::{ | 15 | use crate::{ |
16 | db::SyntaxDatabase, syntax_ptr::SyntaxPtr, FileId, FilePosition, Cancelable, | 16 | db::SyntaxDatabase, syntax_ptr::SyntaxPtr, FileId, FilePosition, Cancelable, |
17 | descriptors::DescriptorDatabase, | 17 | descriptors::{Path, PathKind, DescriptorDatabase}, |
18 | input::SourceRootId | 18 | input::SourceRootId |
19 | }; | 19 | }; |
20 | 20 | ||
21 | pub(crate) use self::{nameres::ModuleScope}; | 21 | pub(crate) use self::nameres::ModuleScope; |
22 | 22 | ||
23 | /// `ModuleDescriptor` is API entry point to get all the information | 23 | /// `ModuleDescriptor` is API entry point to get all the information |
24 | /// about a particular module. | 24 | /// about a particular module. |
@@ -110,6 +110,7 @@ impl ModuleDescriptor { | |||
110 | } | 110 | } |
111 | 111 | ||
112 | /// `name` is `None` for the crate's root module | 112 | /// `name` is `None` for the crate's root module |
113 | #[allow(unused)] | ||
113 | pub fn name(&self) -> Option<SmolStr> { | 114 | pub fn name(&self) -> Option<SmolStr> { |
114 | let link = self.module_id.parent_link(&self.tree)?; | 115 | let link = self.module_id.parent_link(&self.tree)?; |
115 | Some(link.name(&self.tree)) | 116 | Some(link.name(&self.tree)) |
@@ -131,6 +132,19 @@ impl ModuleDescriptor { | |||
131 | Ok(res) | 132 | Ok(res) |
132 | } | 133 | } |
133 | 134 | ||
135 | pub(crate) fn resolve_path(&self, path: Path) -> Option<ModuleDescriptor> { | ||
136 | let mut curr = match path.kind { | ||
137 | PathKind::Crate => self.crate_root(), | ||
138 | PathKind::Self_ | PathKind::Plain => self.clone(), | ||
139 | PathKind::Super => self.parent()?, | ||
140 | }; | ||
141 | let segments = path.segments; | ||
142 | for name in segments { | ||
143 | curr = curr.child(&name)?; | ||
144 | } | ||
145 | Some(curr) | ||
146 | } | ||
147 | |||
134 | pub fn problems(&self, db: &impl DescriptorDatabase) -> Vec<(SyntaxNode, Problem)> { | 148 | pub fn problems(&self, db: &impl DescriptorDatabase) -> Vec<(SyntaxNode, Problem)> { |
135 | self.module_id.problems(&self.tree, db) | 149 | self.module_id.problems(&self.tree, db) |
136 | } | 150 | } |