diff options
author | Aleksey Kladov <[email protected]> | 2018-11-27 16:56:03 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-11-27 16:56:03 +0000 |
commit | 192e2bbb0e5c772d43ec61d36de56a0f7062610e (patch) | |
tree | 160b6aecfabb2f7dac111763b35b6f52ba6ff25b /crates/ra_analysis/src/descriptors/module | |
parent | aa7fd563a4b8817223ac50fa22cd946ce354f47d (diff) |
resolve_path works with DefIds
Diffstat (limited to 'crates/ra_analysis/src/descriptors/module')
-rw-r--r-- | crates/ra_analysis/src/descriptors/module/mod.rs | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/crates/ra_analysis/src/descriptors/module/mod.rs b/crates/ra_analysis/src/descriptors/module/mod.rs index 764e19ce0..78911d5d9 100644 --- a/crates/ra_analysis/src/descriptors/module/mod.rs +++ b/crates/ra_analysis/src/descriptors/module/mod.rs | |||
@@ -77,7 +77,7 @@ impl ModuleDescriptor { | |||
77 | Ok(res) | 77 | Ok(res) |
78 | } | 78 | } |
79 | 79 | ||
80 | fn new( | 80 | pub(super) fn new( |
81 | db: &impl DescriptorDatabase, | 81 | db: &impl DescriptorDatabase, |
82 | source_root_id: SourceRootId, | 82 | source_root_id: SourceRootId, |
83 | module_id: ModuleId, | 83 | module_id: ModuleId, |
@@ -132,6 +132,14 @@ impl ModuleDescriptor { | |||
132 | Some(link.name(&self.tree)) | 132 | Some(link.name(&self.tree)) |
133 | } | 133 | } |
134 | 134 | ||
135 | pub fn def_id(&self, db: &impl DescriptorDatabase) -> DefId { | ||
136 | let def_loc = DefLoc::Module { | ||
137 | id: self.module_id, | ||
138 | source_root: self.source_root_id, | ||
139 | }; | ||
140 | db.id_maps().def_id(def_loc) | ||
141 | } | ||
142 | |||
135 | /// Finds a child module with the specified name. | 143 | /// Finds a child module with the specified name. |
136 | pub fn child(&self, name: &str) -> Option<ModuleDescriptor> { | 144 | pub fn child(&self, name: &str) -> Option<ModuleDescriptor> { |
137 | let child_id = self.module_id.child(&self.tree, name)?; | 145 | let child_id = self.module_id.child(&self.tree, name)?; |
@@ -152,23 +160,23 @@ impl ModuleDescriptor { | |||
152 | &self, | 160 | &self, |
153 | db: &impl DescriptorDatabase, | 161 | db: &impl DescriptorDatabase, |
154 | path: Path, | 162 | path: Path, |
155 | ) -> Cancelable<Option<ModuleDescriptor>> { | 163 | ) -> Cancelable<Option<DefId>> { |
156 | let mut curr = match path.kind { | 164 | let mut curr = match path.kind { |
157 | PathKind::Crate => self.crate_root(), | 165 | PathKind::Crate => self.crate_root(), |
158 | PathKind::Self_ | PathKind::Plain => self.clone(), | 166 | PathKind::Self_ | PathKind::Plain => self.clone(), |
159 | PathKind::Super => ctry!(self.parent()), | 167 | PathKind::Super => ctry!(self.parent()), |
160 | }; | 168 | } |
169 | .def_id(db); | ||
161 | 170 | ||
162 | let segments = path.segments; | 171 | let segments = path.segments; |
163 | for name in segments { | 172 | for name in segments.iter() { |
164 | let scope = curr.scope(db)?; | 173 | let module = match db.id_maps().def_loc(curr) { |
165 | let def_id = ctry!(ctry!(scope.get(&name)).def_id); | ||
166 | curr = match db.id_maps().def_loc(def_id) { | ||
167 | DefLoc::Module { id, source_root } => ModuleDescriptor::new(db, source_root, id)?, | 174 | DefLoc::Module { id, source_root } => ModuleDescriptor::new(db, source_root, id)?, |
168 | _ => return Ok(None), | 175 | _ => return Ok(None), |
169 | }; | 176 | }; |
177 | let scope = module.scope(db)?; | ||
178 | curr = ctry!(ctry!(scope.get(&name)).def_id); | ||
170 | } | 179 | } |
171 | |||
172 | Ok(Some(curr)) | 180 | Ok(Some(curr)) |
173 | } | 181 | } |
174 | 182 | ||