mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-11-17 18:57:04 +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 mod_data = &def_map[module.local_id];
|
||||||
|
|
||||||
let raw_attrs = match mod_data.origin {
|
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
|
let decl_attrs = declaration_tree_id
|
||||||
.item_tree(db)
|
.item_tree(db)
|
||||||
.raw_attrs(AttrOwner::ModItem(declaration_tree_id.value.into()))
|
.raw_attrs(AttrOwner::ModItem(file_item_tree_id.into()))
|
||||||
.clone();
|
.clone();
|
||||||
let tree = db.file_item_tree(definition.into());
|
let tree = db.file_item_tree(definition.into());
|
||||||
let def_attrs = tree.raw_attrs(AttrOwner::TopLevel).clone();
|
let def_attrs = tree.raw_attrs(AttrOwner::TopLevel).clone();
|
||||||
|
|
@ -536,10 +541,12 @@ impl AttrsWithOwner {
|
||||||
let tree = db.file_item_tree(definition.into());
|
let tree = db.file_item_tree(definition.into());
|
||||||
tree.raw_attrs(AttrOwner::TopLevel).clone()
|
tree.raw_attrs(AttrOwner::TopLevel).clone()
|
||||||
}
|
}
|
||||||
ModuleOrigin::Inline { definition_tree_id, .. } => definition_tree_id
|
ModuleOrigin::Inline { definition_tree_id, file_item_tree_id, .. } => {
|
||||||
|
definition_tree_id
|
||||||
.item_tree(db)
|
.item_tree(db)
|
||||||
.raw_attrs(AttrOwner::ModItem(definition_tree_id.value.into()))
|
.raw_attrs(AttrOwner::ModItem(file_item_tree_id.into()))
|
||||||
.clone(),
|
.clone()
|
||||||
|
}
|
||||||
ModuleOrigin::BlockExpr { id, .. } => {
|
ModuleOrigin::BlockExpr { id, .. } => {
|
||||||
let tree = db.block_item_tree(id);
|
let tree = db.block_item_tree(id);
|
||||||
tree.raw_attrs(AttrOwner::TopLevel).clone()
|
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 {
|
macro_rules! mod_items {
|
||||||
( $( $typ:ident in $fld:ident -> $ast:ty ),+ $(,)? ) => {
|
( $( $typ:ident in $fld:ident -> $ast:ty ),+ $(,)? ) => {
|
||||||
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
|
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
|
||||||
|
|
|
||||||
|
|
@ -80,7 +80,7 @@ use crate::{
|
||||||
LocalModuleId, Lookup, MacroExpander, MacroId, ModuleId, ProcMacroId, UseId,
|
LocalModuleId, Lookup, MacroExpander, MacroId, ModuleId, ProcMacroId, UseId,
|
||||||
db::DefDatabase,
|
db::DefDatabase,
|
||||||
item_scope::{BuiltinShadowMode, ItemScope},
|
item_scope::{BuiltinShadowMode, ItemScope},
|
||||||
item_tree::{ItemTreeId, Mod, TreeId},
|
item_tree::{FileItemTreeId, Mod, TreeId},
|
||||||
nameres::{diagnostics::DefDiagnostic, path_resolution::ResolveMode},
|
nameres::{diagnostics::DefDiagnostic, path_resolution::ResolveMode},
|
||||||
per_ns::PerNs,
|
per_ns::PerNs,
|
||||||
visibility::{Visibility, VisibilityExplicitness},
|
visibility::{Visibility, VisibilityExplicitness},
|
||||||
|
|
@ -289,11 +289,13 @@ pub enum ModuleOrigin {
|
||||||
File {
|
File {
|
||||||
is_mod_rs: bool,
|
is_mod_rs: bool,
|
||||||
declaration: FileAstId<ast::Module>,
|
declaration: FileAstId<ast::Module>,
|
||||||
declaration_tree_id: ItemTreeId<Mod>,
|
declaration_tree_id: TreeId,
|
||||||
|
file_item_tree_id: FileItemTreeId<Mod>,
|
||||||
definition: EditionedFileId,
|
definition: EditionedFileId,
|
||||||
},
|
},
|
||||||
Inline {
|
Inline {
|
||||||
definition_tree_id: ItemTreeId<Mod>,
|
definition_tree_id: TreeId,
|
||||||
|
file_item_tree_id: FileItemTreeId<Mod>,
|
||||||
definition: FileAstId<ast::Module>,
|
definition: FileAstId<ast::Module>,
|
||||||
},
|
},
|
||||||
/// Pseudo-module introduced by a block scope (contains only inner items).
|
/// Pseudo-module introduced by a block scope (contains only inner items).
|
||||||
|
|
@ -309,7 +311,7 @@ impl ModuleOrigin {
|
||||||
&ModuleOrigin::File { declaration, declaration_tree_id, .. } => {
|
&ModuleOrigin::File { declaration, declaration_tree_id, .. } => {
|
||||||
Some(AstId::new(declaration_tree_id.file_id(), declaration))
|
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))
|
Some(AstId::new(definition_tree_id.file_id(), definition))
|
||||||
}
|
}
|
||||||
ModuleOrigin::CrateRoot { .. } | ModuleOrigin::BlockExpr { .. } => None,
|
ModuleOrigin::CrateRoot { .. } | ModuleOrigin::BlockExpr { .. } => None,
|
||||||
|
|
@ -341,12 +343,14 @@ impl ModuleOrigin {
|
||||||
let sf = db.parse(editioned_file_id).tree();
|
let sf = db.parse(editioned_file_id).tree();
|
||||||
InFile::new(editioned_file_id.into(), ModuleSource::SourceFile(sf))
|
InFile::new(editioned_file_id.into(), ModuleSource::SourceFile(sf))
|
||||||
}
|
}
|
||||||
&ModuleOrigin::Inline { definition, definition_tree_id } => InFile::new(
|
&ModuleOrigin::Inline { definition, definition_tree_id, file_item_tree_id: _ } => {
|
||||||
|
InFile::new(
|
||||||
definition_tree_id.file_id(),
|
definition_tree_id.file_id(),
|
||||||
ModuleSource::Module(
|
ModuleSource::Module(
|
||||||
AstId::new(definition_tree_id.file_id(), definition).to_node(db),
|
AstId::new(definition_tree_id.file_id(), definition).to_node(db),
|
||||||
),
|
),
|
||||||
),
|
)
|
||||||
|
}
|
||||||
ModuleOrigin::BlockExpr { block, .. } => {
|
ModuleOrigin::BlockExpr { block, .. } => {
|
||||||
InFile::new(block.file_id, ModuleSource::BlockExpr(block.to_node(db)))
|
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),
|
ErasedAstId::new(definition.into(), ROOT_ERASED_FILE_AST_ID).to_range(db),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
&ModuleOrigin::Inline { definition, definition_tree_id } => InFile::new(
|
&ModuleOrigin::Inline { definition, definition_tree_id, file_item_tree_id: _ } => {
|
||||||
|
InFile::new(
|
||||||
definition_tree_id.file_id(),
|
definition_tree_id.file_id(),
|
||||||
AstId::new(definition_tree_id.file_id(), definition).to_range(db),
|
AstId::new(definition_tree_id.file_id(), definition).to_range(db),
|
||||||
),
|
)
|
||||||
|
}
|
||||||
ModuleOrigin::BlockExpr { block, .. } => InFile::new(block.file_id, block.to_range(db)),
|
ModuleOrigin::BlockExpr { block, .. } => InFile::new(block.file_id, block.to_range(db)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -35,8 +35,8 @@ use crate::{
|
||||||
db::DefDatabase,
|
db::DefDatabase,
|
||||||
item_scope::{GlobId, ImportId, ImportOrExternCrate, PerNsGlobImports},
|
item_scope::{GlobId, ImportId, ImportOrExternCrate, PerNsGlobImports},
|
||||||
item_tree::{
|
item_tree::{
|
||||||
self, FieldsShape, FileItemTreeId, ImportAlias, ImportKind, ItemTree, ItemTreeId,
|
self, FieldsShape, FileItemTreeId, ImportAlias, ImportKind, ItemTree, ItemTreeNode, Macro2,
|
||||||
ItemTreeNode, Macro2, MacroCall, MacroRules, Mod, ModItem, ModKind, TreeId, UseTreeKind,
|
MacroCall, MacroRules, Mod, ModItem, ModKind, TreeId, UseTreeKind,
|
||||||
},
|
},
|
||||||
macro_call_as_call_id,
|
macro_call_as_call_id,
|
||||||
nameres::{
|
nameres::{
|
||||||
|
|
@ -140,7 +140,8 @@ struct ImportSource {
|
||||||
id: UseId,
|
id: UseId,
|
||||||
is_prelude: bool,
|
is_prelude: bool,
|
||||||
kind: ImportKind,
|
kind: ImportKind,
|
||||||
item_tree_id: ItemTreeId<item_tree::Use>,
|
tree: TreeId,
|
||||||
|
item: FileItemTreeId<item_tree::Use>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Eq, PartialEq)]
|
#[derive(Debug, Eq, PartialEq)]
|
||||||
|
|
@ -154,19 +155,20 @@ struct Import {
|
||||||
impl Import {
|
impl Import {
|
||||||
fn from_use(
|
fn from_use(
|
||||||
tree: &ItemTree,
|
tree: &ItemTree,
|
||||||
item_tree_id: ItemTreeId<item_tree::Use>,
|
tree_id: TreeId,
|
||||||
|
item: FileItemTreeId<item_tree::Use>,
|
||||||
id: UseId,
|
id: UseId,
|
||||||
is_prelude: bool,
|
is_prelude: bool,
|
||||||
mut cb: impl FnMut(Self),
|
mut cb: impl FnMut(Self),
|
||||||
) {
|
) {
|
||||||
let it = &tree[item_tree_id.value];
|
let it = &tree[item];
|
||||||
let visibility = &tree[it.visibility];
|
let visibility = &tree[it.visibility];
|
||||||
it.use_tree.expand(|idx, path, kind, alias| {
|
it.use_tree.expand(|idx, path, kind, alias| {
|
||||||
cb(Self {
|
cb(Self {
|
||||||
path,
|
path,
|
||||||
alias,
|
alias,
|
||||||
visibility: visibility.clone(),
|
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),
|
kind: kind @ (ImportKind::Plain | ImportKind::TypeOnly),
|
||||||
id,
|
id,
|
||||||
use_tree,
|
use_tree,
|
||||||
item_tree_id,
|
tree,
|
||||||
|
item,
|
||||||
..
|
..
|
||||||
} => {
|
} => {
|
||||||
let name = match &import.alias {
|
let name = match &import.alias {
|
||||||
|
|
@ -893,8 +896,8 @@ impl DefCollector<'_> {
|
||||||
let Some(ImportOrExternCrate::ExternCrate(_)) = def.import else {
|
let Some(ImportOrExternCrate::ExternCrate(_)) = def.import else {
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
let item_tree = item_tree_id.item_tree(self.db);
|
let item_tree = tree.item_tree(self.db);
|
||||||
let use_kind = item_tree[item_tree_id.value].use_tree.kind();
|
let use_kind = item_tree[item].use_tree.kind();
|
||||||
let UseTreeKind::Single { path, .. } = use_kind else {
|
let UseTreeKind::Single { path, .. } = use_kind else {
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
@ -1643,7 +1646,7 @@ impl DefCollector<'_> {
|
||||||
Import {
|
Import {
|
||||||
ref path,
|
ref path,
|
||||||
source:
|
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();
|
let is_prelude = attrs.by_key(sym::prelude_import).exists();
|
||||||
Import::from_use(
|
Import::from_use(
|
||||||
self.item_tree,
|
self.item_tree,
|
||||||
ItemTreeId::new(self.tree_id, item_tree_id),
|
self.tree_id,
|
||||||
|
item_tree_id,
|
||||||
id,
|
id,
|
||||||
is_prelude,
|
is_prelude,
|
||||||
|import| {
|
|import| {
|
||||||
|
|
@ -2207,13 +2211,15 @@ impl ModCollector<'_, '_> {
|
||||||
let origin = match definition {
|
let origin = match definition {
|
||||||
None => ModuleOrigin::Inline {
|
None => ModuleOrigin::Inline {
|
||||||
definition: declaration,
|
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 {
|
Some((definition, is_mod_rs)) => ModuleOrigin::File {
|
||||||
declaration,
|
declaration,
|
||||||
definition,
|
definition,
|
||||||
is_mod_rs,
|
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