aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_analysis/src
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-11-20 13:55:35 +0000
committerAleksey Kladov <[email protected]>2018-11-20 13:55:35 +0000
commit21508cfb2f5452c6f19ab0e615a6c61cb28154c8 (patch)
tree8430c92fa6488dedf2704f2b64effd413aa6e62d /crates/ra_analysis/src
parent0ab3c65d9819765016c926df4aca634b5be8344c (diff)
Use OO API instead of resolve_module
Diffstat (limited to 'crates/ra_analysis/src')
-rw-r--r--crates/ra_analysis/src/descriptors/module/mod.rs13
-rw-r--r--crates/ra_analysis/src/imp.rs58
2 files changed, 19 insertions, 52 deletions
diff --git a/crates/ra_analysis/src/descriptors/module/mod.rs b/crates/ra_analysis/src/descriptors/module/mod.rs
index 16faea94e..d0560244a 100644
--- a/crates/ra_analysis/src/descriptors/module/mod.rs
+++ b/crates/ra_analysis/src/descriptors/module/mod.rs
@@ -165,15 +165,6 @@ enum ModuleSourceNode {
165#[derive(Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, Debug)] 165#[derive(Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, Debug)]
166pub(crate) struct ModuleId(u32); 166pub(crate) struct ModuleId(u32);
167 167
168impl crate::loc2id::NumericId for ModuleId {
169 fn from_u32(id: u32) -> Self {
170 ModuleId(id)
171 }
172 fn to_u32(self) -> u32 {
173 self.0
174 }
175}
176
177#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)] 168#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
178struct LinkId(u32); 169struct LinkId(u32);
179 170
@@ -189,13 +180,13 @@ pub enum Problem {
189} 180}
190 181
191impl ModuleId { 182impl ModuleId {
192 pub(crate) fn source(self, tree: &ModuleTree) -> ModuleSource { 183 fn source(self, tree: &ModuleTree) -> ModuleSource {
193 tree.module(self).source 184 tree.module(self).source
194 } 185 }
195 fn parent_link(self, tree: &ModuleTree) -> Option<LinkId> { 186 fn parent_link(self, tree: &ModuleTree) -> Option<LinkId> {
196 tree.module(self).parent 187 tree.module(self).parent
197 } 188 }
198 pub(crate) fn parent(self, tree: &ModuleTree) -> Option<ModuleId> { 189 fn parent(self, tree: &ModuleTree) -> Option<ModuleId> {
199 let link = self.parent_link(tree)?; 190 let link = self.parent_link(tree)?;
200 Some(tree.link(link).owner) 191 Some(tree.link(link).owner)
201 } 192 }
diff --git a/crates/ra_analysis/src/imp.rs b/crates/ra_analysis/src/imp.rs
index 49b863756..1bbf0cb6d 100644
--- a/crates/ra_analysis/src/imp.rs
+++ b/crates/ra_analysis/src/imp.rs
@@ -266,7 +266,6 @@ impl AnalysisImpl {
266 &self, 266 &self,
267 position: FilePosition, 267 position: FilePosition,
268 ) -> Cancelable<Vec<(FileId, FileSymbol)>> { 268 ) -> Cancelable<Vec<(FileId, FileSymbol)>> {
269 let module_tree = self.module_tree(position.file_id)?;
270 let file = self.db.file_syntax(position.file_id); 269 let file = self.db.file_syntax(position.file_id);
271 let syntax = file.syntax(); 270 let syntax = file.syntax();
272 if let Some(name_ref) = find_node_at_offset::<ast::NameRef>(syntax, position.offset) { 271 if let Some(name_ref) = find_node_at_offset::<ast::NameRef>(syntax, position.offset) {
@@ -292,25 +291,23 @@ impl AnalysisImpl {
292 if let Some(name) = find_node_at_offset::<ast::Name>(syntax, position.offset) { 291 if let Some(name) = find_node_at_offset::<ast::Name>(syntax, position.offset) {
293 if let Some(module) = name.syntax().parent().and_then(ast::Module::cast) { 292 if let Some(module) = name.syntax().parent().and_then(ast::Module::cast) {
294 if module.has_semi() { 293 if module.has_semi() {
295 let file_ids = self.resolve_module(&*module_tree, position.file_id, module); 294 let parent_module =
296 295 ModuleDescriptor::guess_from_file_id(&*self.db, position.file_id)?;
297 let res = file_ids 296 let child_name = module.name();
298 .into_iter() 297 match (parent_module, child_name) {
299 .map(|id| { 298 (Some(parent_module), Some(child_name)) => {
300 let name = module 299 if let Some(child) = parent_module.child(&child_name.text()) {
301 .name() 300 let file_id = child.source().file_id();
302 .map(|n| n.text()) 301 let symbol = FileSymbol {
303 .unwrap_or_else(|| SmolStr::new("")); 302 name: child_name.text(),
304 let symbol = FileSymbol { 303 node_range: TextRange::offset_len(0.into(), 0.into()),
305 name, 304 kind: MODULE,
306 node_range: TextRange::offset_len(0.into(), 0.into()), 305 };
307 kind: MODULE, 306 return Ok(vec![(file_id, symbol)]);
308 }; 307 }
309 (id, symbol) 308 }
310 }) 309 _ => (),
311 .collect(); 310 }
312
313 return Ok(res);
314 } 311 }
315 } 312 }
316 } 313 }
@@ -519,27 +516,6 @@ impl AnalysisImpl {
519 query.limit(4); 516 query.limit(4);
520 self.world_symbols(query) 517 self.world_symbols(query)
521 } 518 }
522
523 fn resolve_module(
524 &self,
525 module_tree: &ModuleTree,
526 file_id: FileId,
527 module: ast::Module,
528 ) -> Vec<FileId> {
529 let name = match module.name() {
530 Some(name) => name.text(),
531 None => return Vec::new(),
532 };
533 let module_id = match module_tree.any_module_for_source(ModuleSource::SourceFile(file_id)) {
534 Some(id) => id,
535 None => return Vec::new(),
536 };
537 module_id
538 .child(module_tree, name.as_str())
539 .and_then(|it| it.source(&module_tree).as_file())
540 .into_iter()
541 .collect()
542 }
543} 519}
544 520
545impl SourceChange { 521impl SourceChange {