mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 05:45:12 +00:00
Use OO API instead of resolve_module
This commit is contained in:
parent
0ab3c65d98
commit
21508cfb2f
2 changed files with 19 additions and 52 deletions
|
@ -165,15 +165,6 @@ enum ModuleSourceNode {
|
||||||
#[derive(Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, Debug)]
|
#[derive(Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, Debug)]
|
||||||
pub(crate) struct ModuleId(u32);
|
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)]
|
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
|
||||||
struct LinkId(u32);
|
struct LinkId(u32);
|
||||||
|
|
||||||
|
@ -189,13 +180,13 @@ pub enum Problem {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ModuleId {
|
impl ModuleId {
|
||||||
pub(crate) fn source(self, tree: &ModuleTree) -> ModuleSource {
|
fn source(self, tree: &ModuleTree) -> ModuleSource {
|
||||||
tree.module(self).source
|
tree.module(self).source
|
||||||
}
|
}
|
||||||
fn parent_link(self, tree: &ModuleTree) -> Option<LinkId> {
|
fn parent_link(self, tree: &ModuleTree) -> Option<LinkId> {
|
||||||
tree.module(self).parent
|
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)?;
|
let link = self.parent_link(tree)?;
|
||||||
Some(tree.link(link).owner)
|
Some(tree.link(link).owner)
|
||||||
}
|
}
|
||||||
|
|
|
@ -266,7 +266,6 @@ impl AnalysisImpl {
|
||||||
&self,
|
&self,
|
||||||
position: FilePosition,
|
position: FilePosition,
|
||||||
) -> Cancelable<Vec<(FileId, FileSymbol)>> {
|
) -> Cancelable<Vec<(FileId, FileSymbol)>> {
|
||||||
let module_tree = self.module_tree(position.file_id)?;
|
|
||||||
let file = self.db.file_syntax(position.file_id);
|
let file = self.db.file_syntax(position.file_id);
|
||||||
let syntax = file.syntax();
|
let syntax = file.syntax();
|
||||||
if let Some(name_ref) = find_node_at_offset::<ast::NameRef>(syntax, position.offset) {
|
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(name) = find_node_at_offset::<ast::Name>(syntax, position.offset) {
|
||||||
if let Some(module) = name.syntax().parent().and_then(ast::Module::cast) {
|
if let Some(module) = name.syntax().parent().and_then(ast::Module::cast) {
|
||||||
if module.has_semi() {
|
if module.has_semi() {
|
||||||
let file_ids = self.resolve_module(&*module_tree, position.file_id, module);
|
let parent_module =
|
||||||
|
ModuleDescriptor::guess_from_file_id(&*self.db, position.file_id)?;
|
||||||
let res = file_ids
|
let child_name = module.name();
|
||||||
.into_iter()
|
match (parent_module, child_name) {
|
||||||
.map(|id| {
|
(Some(parent_module), Some(child_name)) => {
|
||||||
let name = module
|
if let Some(child) = parent_module.child(&child_name.text()) {
|
||||||
.name()
|
let file_id = child.source().file_id();
|
||||||
.map(|n| n.text())
|
let symbol = FileSymbol {
|
||||||
.unwrap_or_else(|| SmolStr::new(""));
|
name: child_name.text(),
|
||||||
let symbol = FileSymbol {
|
node_range: TextRange::offset_len(0.into(), 0.into()),
|
||||||
name,
|
kind: MODULE,
|
||||||
node_range: TextRange::offset_len(0.into(), 0.into()),
|
};
|
||||||
kind: MODULE,
|
return Ok(vec![(file_id, symbol)]);
|
||||||
};
|
}
|
||||||
(id, symbol)
|
}
|
||||||
})
|
_ => (),
|
||||||
.collect();
|
}
|
||||||
|
|
||||||
return Ok(res);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -519,27 +516,6 @@ impl AnalysisImpl {
|
||||||
query.limit(4);
|
query.limit(4);
|
||||||
self.world_symbols(query)
|
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 {
|
impl SourceChange {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue