Use OO API instead of resolve_module

This commit is contained in:
Aleksey Kladov 2018-11-20 16:55:35 +03:00
parent 0ab3c65d98
commit 21508cfb2f
2 changed files with 19 additions and 52 deletions

View file

@ -165,15 +165,6 @@ enum ModuleSourceNode {
#[derive(Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, Debug)]
pub(crate) struct ModuleId(u32);
impl crate::loc2id::NumericId for ModuleId {
fn from_u32(id: u32) -> Self {
ModuleId(id)
}
fn to_u32(self) -> u32 {
self.0
}
}
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
struct LinkId(u32);
@ -189,13 +180,13 @@ pub enum Problem {
}
impl ModuleId {
pub(crate) fn source(self, tree: &ModuleTree) -> ModuleSource {
fn source(self, tree: &ModuleTree) -> ModuleSource {
tree.module(self).source
}
fn parent_link(self, tree: &ModuleTree) -> Option<LinkId> {
tree.module(self).parent
}
pub(crate) fn parent(self, tree: &ModuleTree) -> Option<ModuleId> {
fn parent(self, tree: &ModuleTree) -> Option<ModuleId> {
let link = self.parent_link(tree)?;
Some(tree.link(link).owner)
}

View file

@ -266,7 +266,6 @@ impl AnalysisImpl {
&self,
position: FilePosition,
) -> Cancelable<Vec<(FileId, FileSymbol)>> {
let module_tree = self.module_tree(position.file_id)?;
let file = self.db.file_syntax(position.file_id);
let syntax = file.syntax();
if let Some(name_ref) = find_node_at_offset::<ast::NameRef>(syntax, position.offset) {
@ -292,25 +291,23 @@ impl AnalysisImpl {
if let Some(name) = find_node_at_offset::<ast::Name>(syntax, position.offset) {
if let Some(module) = name.syntax().parent().and_then(ast::Module::cast) {
if module.has_semi() {
let file_ids = self.resolve_module(&*module_tree, position.file_id, module);
let res = file_ids
.into_iter()
.map(|id| {
let name = module
.name()
.map(|n| n.text())
.unwrap_or_else(|| SmolStr::new(""));
let parent_module =
ModuleDescriptor::guess_from_file_id(&*self.db, position.file_id)?;
let child_name = module.name();
match (parent_module, child_name) {
(Some(parent_module), Some(child_name)) => {
if let Some(child) = parent_module.child(&child_name.text()) {
let file_id = child.source().file_id();
let symbol = FileSymbol {
name,
name: child_name.text(),
node_range: TextRange::offset_len(0.into(), 0.into()),
kind: MODULE,
};
(id, symbol)
})
.collect();
return Ok(res);
return Ok(vec![(file_id, symbol)]);
}
}
_ => (),
}
}
}
}
@ -519,27 +516,6 @@ impl AnalysisImpl {
query.limit(4);
self.world_symbols(query)
}
fn resolve_module(
&self,
module_tree: &ModuleTree,
file_id: FileId,
module: ast::Module,
) -> Vec<FileId> {
let name = match module.name() {
Some(name) => name.text(),
None => return Vec::new(),
};
let module_id = match module_tree.any_module_for_source(ModuleSource::SourceFile(file_id)) {
Some(id) => id,
None => return Vec::new(),
};
module_id
.child(module_tree, name.as_str())
.and_then(|it| it.source(&module_tree).as_file())
.into_iter()
.collect()
}
}
impl SourceChange {