mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-11-03 05:13:35 +00:00
Remove ItemTreeId
This commit is contained in:
parent
7011fd054f
commit
e9f8ecab45
4 changed files with 52 additions and 86 deletions
|
|
@ -523,10 +523,15 @@ impl AttrsWithOwner {
|
|||
let mod_data = &def_map[module.local_id];
|
||||
|
||||
let raw_attrs = match mod_data.origin {
|
||||
ModuleOrigin::File { definition, declaration_tree_id, .. } => {
|
||||
ModuleOrigin::File {
|
||||
definition,
|
||||
declaration_tree_id,
|
||||
file_item_tree_id,
|
||||
..
|
||||
} => {
|
||||
let decl_attrs = declaration_tree_id
|
||||
.item_tree(db)
|
||||
.raw_attrs(AttrOwner::ModItem(declaration_tree_id.value.into()))
|
||||
.raw_attrs(AttrOwner::ModItem(file_item_tree_id.into()))
|
||||
.clone();
|
||||
let tree = db.file_item_tree(definition.into());
|
||||
let def_attrs = tree.raw_attrs(AttrOwner::TopLevel).clone();
|
||||
|
|
@ -536,10 +541,12 @@ impl AttrsWithOwner {
|
|||
let tree = db.file_item_tree(definition.into());
|
||||
tree.raw_attrs(AttrOwner::TopLevel).clone()
|
||||
}
|
||||
ModuleOrigin::Inline { definition_tree_id, .. } => definition_tree_id
|
||||
.item_tree(db)
|
||||
.raw_attrs(AttrOwner::ModItem(definition_tree_id.value.into()))
|
||||
.clone(),
|
||||
ModuleOrigin::Inline { definition_tree_id, file_item_tree_id, .. } => {
|
||||
definition_tree_id
|
||||
.item_tree(db)
|
||||
.raw_attrs(AttrOwner::ModItem(file_item_tree_id.into()))
|
||||
.clone()
|
||||
}
|
||||
ModuleOrigin::BlockExpr { id, .. } => {
|
||||
let tree = db.block_item_tree(id);
|
||||
tree.raw_attrs(AttrOwner::TopLevel).clone()
|
||||
|
|
|
|||
|
|
@ -404,59 +404,6 @@ impl TreeId {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct ItemTreeId<N> {
|
||||
tree: TreeId,
|
||||
pub value: FileItemTreeId<N>,
|
||||
}
|
||||
|
||||
impl<N> ItemTreeId<N> {
|
||||
pub fn new(tree: TreeId, idx: FileItemTreeId<N>) -> Self {
|
||||
Self { tree, value: idx }
|
||||
}
|
||||
|
||||
pub fn file_id(self) -> HirFileId {
|
||||
self.tree.file
|
||||
}
|
||||
|
||||
pub fn tree_id(self) -> TreeId {
|
||||
self.tree
|
||||
}
|
||||
|
||||
pub fn item_tree(self, db: &dyn DefDatabase) -> Arc<ItemTree> {
|
||||
self.tree.item_tree(db)
|
||||
}
|
||||
|
||||
pub fn resolved<R>(self, db: &dyn DefDatabase, cb: impl FnOnce(&N) -> R) -> R
|
||||
where
|
||||
ItemTree: Index<FileItemTreeId<N>, Output = N>,
|
||||
{
|
||||
cb(&self.tree.item_tree(db)[self.value])
|
||||
}
|
||||
}
|
||||
|
||||
impl<N> Copy for ItemTreeId<N> {}
|
||||
impl<N> Clone for ItemTreeId<N> {
|
||||
fn clone(&self) -> Self {
|
||||
*self
|
||||
}
|
||||
}
|
||||
|
||||
impl<N> PartialEq for ItemTreeId<N> {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.tree == other.tree && self.value == other.value
|
||||
}
|
||||
}
|
||||
|
||||
impl<N> Eq for ItemTreeId<N> {}
|
||||
|
||||
impl<N> Hash for ItemTreeId<N> {
|
||||
fn hash<H: Hasher>(&self, state: &mut H) {
|
||||
self.tree.hash(state);
|
||||
self.value.hash(state);
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! mod_items {
|
||||
( $( $typ:ident in $fld:ident -> $ast:ty ),+ $(,)? ) => {
|
||||
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
|
||||
|
|
|
|||
|
|
@ -80,7 +80,7 @@ use crate::{
|
|||
LocalModuleId, Lookup, MacroExpander, MacroId, ModuleId, ProcMacroId, UseId,
|
||||
db::DefDatabase,
|
||||
item_scope::{BuiltinShadowMode, ItemScope},
|
||||
item_tree::{ItemTreeId, Mod, TreeId},
|
||||
item_tree::{FileItemTreeId, Mod, TreeId},
|
||||
nameres::{diagnostics::DefDiagnostic, path_resolution::ResolveMode},
|
||||
per_ns::PerNs,
|
||||
visibility::{Visibility, VisibilityExplicitness},
|
||||
|
|
@ -289,11 +289,13 @@ pub enum ModuleOrigin {
|
|||
File {
|
||||
is_mod_rs: bool,
|
||||
declaration: FileAstId<ast::Module>,
|
||||
declaration_tree_id: ItemTreeId<Mod>,
|
||||
declaration_tree_id: TreeId,
|
||||
file_item_tree_id: FileItemTreeId<Mod>,
|
||||
definition: EditionedFileId,
|
||||
},
|
||||
Inline {
|
||||
definition_tree_id: ItemTreeId<Mod>,
|
||||
definition_tree_id: TreeId,
|
||||
file_item_tree_id: FileItemTreeId<Mod>,
|
||||
definition: FileAstId<ast::Module>,
|
||||
},
|
||||
/// Pseudo-module introduced by a block scope (contains only inner items).
|
||||
|
|
@ -309,7 +311,7 @@ impl ModuleOrigin {
|
|||
&ModuleOrigin::File { declaration, declaration_tree_id, .. } => {
|
||||
Some(AstId::new(declaration_tree_id.file_id(), declaration))
|
||||
}
|
||||
&ModuleOrigin::Inline { definition, definition_tree_id } => {
|
||||
&ModuleOrigin::Inline { definition, definition_tree_id, file_item_tree_id: _ } => {
|
||||
Some(AstId::new(definition_tree_id.file_id(), definition))
|
||||
}
|
||||
ModuleOrigin::CrateRoot { .. } | ModuleOrigin::BlockExpr { .. } => None,
|
||||
|
|
@ -341,12 +343,14 @@ impl ModuleOrigin {
|
|||
let sf = db.parse(editioned_file_id).tree();
|
||||
InFile::new(editioned_file_id.into(), ModuleSource::SourceFile(sf))
|
||||
}
|
||||
&ModuleOrigin::Inline { definition, definition_tree_id } => InFile::new(
|
||||
definition_tree_id.file_id(),
|
||||
ModuleSource::Module(
|
||||
AstId::new(definition_tree_id.file_id(), definition).to_node(db),
|
||||
),
|
||||
),
|
||||
&ModuleOrigin::Inline { definition, definition_tree_id, file_item_tree_id: _ } => {
|
||||
InFile::new(
|
||||
definition_tree_id.file_id(),
|
||||
ModuleSource::Module(
|
||||
AstId::new(definition_tree_id.file_id(), definition).to_node(db),
|
||||
),
|
||||
)
|
||||
}
|
||||
ModuleOrigin::BlockExpr { block, .. } => {
|
||||
InFile::new(block.file_id, ModuleSource::BlockExpr(block.to_node(db)))
|
||||
}
|
||||
|
|
@ -773,10 +777,12 @@ impl ModuleData {
|
|||
ErasedAstId::new(definition.into(), ROOT_ERASED_FILE_AST_ID).to_range(db),
|
||||
)
|
||||
}
|
||||
&ModuleOrigin::Inline { definition, definition_tree_id } => InFile::new(
|
||||
definition_tree_id.file_id(),
|
||||
AstId::new(definition_tree_id.file_id(), definition).to_range(db),
|
||||
),
|
||||
&ModuleOrigin::Inline { definition, definition_tree_id, file_item_tree_id: _ } => {
|
||||
InFile::new(
|
||||
definition_tree_id.file_id(),
|
||||
AstId::new(definition_tree_id.file_id(), definition).to_range(db),
|
||||
)
|
||||
}
|
||||
ModuleOrigin::BlockExpr { block, .. } => InFile::new(block.file_id, block.to_range(db)),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,8 +35,8 @@ use crate::{
|
|||
db::DefDatabase,
|
||||
item_scope::{GlobId, ImportId, ImportOrExternCrate, PerNsGlobImports},
|
||||
item_tree::{
|
||||
self, FieldsShape, FileItemTreeId, ImportAlias, ImportKind, ItemTree, ItemTreeId,
|
||||
ItemTreeNode, Macro2, MacroCall, MacroRules, Mod, ModItem, ModKind, TreeId, UseTreeKind,
|
||||
self, FieldsShape, FileItemTreeId, ImportAlias, ImportKind, ItemTree, ItemTreeNode, Macro2,
|
||||
MacroCall, MacroRules, Mod, ModItem, ModKind, TreeId, UseTreeKind,
|
||||
},
|
||||
macro_call_as_call_id,
|
||||
nameres::{
|
||||
|
|
@ -140,7 +140,8 @@ struct ImportSource {
|
|||
id: UseId,
|
||||
is_prelude: bool,
|
||||
kind: ImportKind,
|
||||
item_tree_id: ItemTreeId<item_tree::Use>,
|
||||
tree: TreeId,
|
||||
item: FileItemTreeId<item_tree::Use>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Eq, PartialEq)]
|
||||
|
|
@ -154,19 +155,20 @@ struct Import {
|
|||
impl Import {
|
||||
fn from_use(
|
||||
tree: &ItemTree,
|
||||
item_tree_id: ItemTreeId<item_tree::Use>,
|
||||
tree_id: TreeId,
|
||||
item: FileItemTreeId<item_tree::Use>,
|
||||
id: UseId,
|
||||
is_prelude: bool,
|
||||
mut cb: impl FnMut(Self),
|
||||
) {
|
||||
let it = &tree[item_tree_id.value];
|
||||
let it = &tree[item];
|
||||
let visibility = &tree[it.visibility];
|
||||
it.use_tree.expand(|idx, path, kind, alias| {
|
||||
cb(Self {
|
||||
path,
|
||||
alias,
|
||||
visibility: visibility.clone(),
|
||||
source: ImportSource { use_tree: idx, id, is_prelude, kind, item_tree_id },
|
||||
source: ImportSource { use_tree: idx, id, is_prelude, kind, tree: tree_id, item },
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
@ -860,7 +862,8 @@ impl DefCollector<'_> {
|
|||
kind: kind @ (ImportKind::Plain | ImportKind::TypeOnly),
|
||||
id,
|
||||
use_tree,
|
||||
item_tree_id,
|
||||
tree,
|
||||
item,
|
||||
..
|
||||
} => {
|
||||
let name = match &import.alias {
|
||||
|
|
@ -893,8 +896,8 @@ impl DefCollector<'_> {
|
|||
let Some(ImportOrExternCrate::ExternCrate(_)) = def.import else {
|
||||
return false;
|
||||
};
|
||||
let item_tree = item_tree_id.item_tree(self.db);
|
||||
let use_kind = item_tree[item_tree_id.value].use_tree.kind();
|
||||
let item_tree = tree.item_tree(self.db);
|
||||
let use_kind = item_tree[item].use_tree.kind();
|
||||
let UseTreeKind::Single { path, .. } = use_kind else {
|
||||
return false;
|
||||
};
|
||||
|
|
@ -1643,7 +1646,7 @@ impl DefCollector<'_> {
|
|||
Import {
|
||||
ref path,
|
||||
source:
|
||||
ImportSource { use_tree, id, is_prelude: _, kind: _, item_tree_id: _ },
|
||||
ImportSource { use_tree, id, is_prelude: _, kind: _, tree: _, item: _ },
|
||||
..
|
||||
},
|
||||
..
|
||||
|
|
@ -1771,7 +1774,8 @@ impl ModCollector<'_, '_> {
|
|||
let is_prelude = attrs.by_key(sym::prelude_import).exists();
|
||||
Import::from_use(
|
||||
self.item_tree,
|
||||
ItemTreeId::new(self.tree_id, item_tree_id),
|
||||
self.tree_id,
|
||||
item_tree_id,
|
||||
id,
|
||||
is_prelude,
|
||||
|import| {
|
||||
|
|
@ -2207,13 +2211,15 @@ impl ModCollector<'_, '_> {
|
|||
let origin = match definition {
|
||||
None => ModuleOrigin::Inline {
|
||||
definition: declaration,
|
||||
definition_tree_id: ItemTreeId::new(self.tree_id, mod_tree_id),
|
||||
definition_tree_id: self.tree_id,
|
||||
file_item_tree_id: mod_tree_id,
|
||||
},
|
||||
Some((definition, is_mod_rs)) => ModuleOrigin::File {
|
||||
declaration,
|
||||
definition,
|
||||
is_mod_rs,
|
||||
declaration_tree_id: ItemTreeId::new(self.tree_id, mod_tree_id),
|
||||
declaration_tree_id: self.tree_id,
|
||||
file_item_tree_id: mod_tree_id,
|
||||
},
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue