mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 22:31:43 +00:00
Change ids strategy
this is a part of larghish hir refactoring which aims to * replace per-source-root module trees with per crate trees * switch from a monotyped DedId to type-specific ids
This commit is contained in:
parent
cfb085ded8
commit
3ab1519cb2
26 changed files with 365 additions and 430 deletions
|
@ -13,7 +13,7 @@ use ra_syntax::{
|
|||
};
|
||||
|
||||
use crate::{
|
||||
HirDatabase, Function, SourceItemId,
|
||||
HirDatabase, Function, SourceItemId, ModuleDef,
|
||||
DefKind, DefLoc, AsName, Module,
|
||||
};
|
||||
|
||||
|
@ -84,9 +84,13 @@ pub fn module_from_child_node(
|
|||
|
||||
fn module_from_source(db: &impl HirDatabase, source: SourceItemId) -> Option<Module> {
|
||||
let source_root_id = db.file_source_root(source.file_id.as_original_file());
|
||||
let module_tree = db.module_tree(source_root_id);
|
||||
let module_id = module_tree.find_module_by_source(source)?;
|
||||
Some(Module::from_module_id(db, source_root_id, module_id))
|
||||
db.source_root_crates(source_root_id)
|
||||
.iter()
|
||||
.find_map(|&krate| {
|
||||
let module_tree = db.module_tree(krate);
|
||||
let module_id = module_tree.find_module_by_source(source)?;
|
||||
Some(Module { krate, module_id })
|
||||
})
|
||||
}
|
||||
|
||||
pub fn function_from_position(db: &impl HirDatabase, position: FilePosition) -> Option<Function> {
|
||||
|
@ -110,8 +114,8 @@ pub fn function_from_module(
|
|||
module: &Module,
|
||||
fn_def: &ast::FnDef,
|
||||
) -> Function {
|
||||
let loc = module.def_id.loc(db);
|
||||
let file_id = loc.source_item_id.file_id;
|
||||
let (file_id, _) = module.definition_source(db);
|
||||
let file_id = file_id.into();
|
||||
let file_items = db.file_items(file_id);
|
||||
let item_id = file_items.id_of(file_id, fn_def.syntax());
|
||||
let source_item_id = SourceItemId {
|
||||
|
@ -119,9 +123,8 @@ pub fn function_from_module(
|
|||
item_id: Some(item_id),
|
||||
};
|
||||
let def_loc = DefLoc {
|
||||
module: module.clone(),
|
||||
kind: DefKind::Function,
|
||||
source_root_id: loc.source_root_id,
|
||||
module_id: loc.module_id,
|
||||
source_item_id,
|
||||
};
|
||||
Function::new(def_loc.id(db))
|
||||
|
@ -141,14 +144,17 @@ pub fn macro_symbols(db: &impl HirDatabase, file_id: FileId) -> Vec<(SmolStr, Te
|
|||
Some(it) => it,
|
||||
None => return Vec::new(),
|
||||
};
|
||||
let loc = module.def_id.loc(db);
|
||||
let items = db.lower_module_module(loc.source_root_id, loc.module_id);
|
||||
let items = db.lower_module_module(module);
|
||||
let mut res = Vec::new();
|
||||
|
||||
for macro_call_id in items
|
||||
.declarations
|
||||
.iter()
|
||||
.filter_map(|(_, it)| it.take_types())
|
||||
.filter_map(|(_, it)| it.clone().take_types())
|
||||
.filter_map(|it| match it {
|
||||
ModuleDef::Def(it) => Some(it),
|
||||
_ => None,
|
||||
})
|
||||
.filter_map(|it| it.loc(db).source_item_id.file_id.as_macro_call_id())
|
||||
{
|
||||
if let Some(exp) = db.expand_macro_invocation(macro_call_id) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue