mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-13 13:48:50 +00:00
Merge item tree traits
The Source trait isn't needed anymore since we no longer merge extern crate items with use items.
This commit is contained in:
parent
b5fd02d93c
commit
f9a1a9cd3c
3 changed files with 16 additions and 21 deletions
|
@ -27,7 +27,7 @@ use crate::{
|
|||
LogicOp, MatchArm, Ordering, Pat, PatId, RecordFieldPat, RecordLitField, Statement,
|
||||
},
|
||||
item_scope::BuiltinShadowMode,
|
||||
item_tree::{FileItemTreeId, ItemTree, ItemTreeSource},
|
||||
item_tree::{FileItemTreeId, ItemTree, ItemTreeNode},
|
||||
path::{GenericArgs, Path},
|
||||
type_ref::{Mutability, Rawness, TypeRef},
|
||||
AdtId, ConstLoc, ContainerId, DefWithBodyId, EnumLoc, FunctionLoc, Intern, ModuleDefId,
|
||||
|
@ -557,7 +557,7 @@ impl ExprCollector<'_> {
|
|||
}
|
||||
}
|
||||
|
||||
fn find_inner_item<S: ItemTreeSource>(&self, id: AstId<ast::ModuleItem>) -> FileItemTreeId<S> {
|
||||
fn find_inner_item<S: ItemTreeNode>(&self, id: AstId<ast::ModuleItem>) -> FileItemTreeId<S> {
|
||||
let index =
|
||||
self.item_trees.iter().position(|(file, _)| *file == id.file_id).unwrap_or_else(|| {
|
||||
panic!("couldn't find item tree for file {:?}", id.file_id);
|
||||
|
|
|
@ -153,7 +153,7 @@ impl ItemTree {
|
|||
self.inner_items.values().flatten().copied()
|
||||
}
|
||||
|
||||
pub fn source<S: ItemTreeSource>(
|
||||
pub fn source<S: ItemTreeNode>(
|
||||
&self,
|
||||
db: &dyn DefDatabase,
|
||||
of: FileItemTreeId<S>,
|
||||
|
@ -173,6 +173,10 @@ impl ItemTree {
|
|||
|
||||
/// Trait implemented by all nodes in the item tree.
|
||||
pub trait ItemTreeNode: Clone {
|
||||
type Source: AstNode + Into<ast::ModuleItem>;
|
||||
|
||||
fn ast_id(&self) -> FileAstId<Self::Source>;
|
||||
|
||||
/// Looks up an instance of `Self` in an item tree.
|
||||
fn lookup(tree: &ItemTree, index: Idx<Self>) -> &Self;
|
||||
|
||||
|
@ -183,13 +187,6 @@ pub trait ItemTreeNode: Clone {
|
|||
fn id_to_mod_item(id: FileItemTreeId<Self>) -> ModItem;
|
||||
}
|
||||
|
||||
/// Trait for item tree nodes that allow accessing the original AST node.
|
||||
pub trait ItemTreeSource: ItemTreeNode {
|
||||
type Source: AstNode + Into<ast::ModuleItem>;
|
||||
|
||||
fn ast_id(&self) -> FileAstId<Self::Source>;
|
||||
}
|
||||
|
||||
pub struct FileItemTreeId<N: ItemTreeNode> {
|
||||
index: Idx<N>,
|
||||
_p: PhantomData<N>,
|
||||
|
@ -242,6 +239,12 @@ macro_rules! mod_items {
|
|||
|
||||
$(
|
||||
impl ItemTreeNode for $typ {
|
||||
type Source = $ast;
|
||||
|
||||
fn ast_id(&self) -> FileAstId<Self::Source> {
|
||||
self.ast_id
|
||||
}
|
||||
|
||||
fn lookup(tree: &ItemTree, index: Idx<Self>) -> &Self {
|
||||
&tree.$fld[index]
|
||||
}
|
||||
|
@ -259,14 +262,6 @@ macro_rules! mod_items {
|
|||
}
|
||||
}
|
||||
|
||||
impl ItemTreeSource for $typ {
|
||||
type Source = $ast;
|
||||
|
||||
fn ast_id(&self) -> FileAstId<Self::Source> {
|
||||
self.ast_id
|
||||
}
|
||||
}
|
||||
|
||||
impl Index<Idx<$typ>> for ItemTree {
|
||||
type Output = $typ;
|
||||
|
||||
|
|
|
@ -3,14 +3,14 @@
|
|||
use hir_expand::InFile;
|
||||
use ra_arena::map::ArenaMap;
|
||||
|
||||
use crate::{db::DefDatabase, item_tree::ItemTreeSource, AssocItemLoc, ItemLoc};
|
||||
use crate::{db::DefDatabase, item_tree::ItemTreeNode, AssocItemLoc, ItemLoc};
|
||||
|
||||
pub trait HasSource {
|
||||
type Value;
|
||||
fn source(&self, db: &dyn DefDatabase) -> InFile<Self::Value>;
|
||||
}
|
||||
|
||||
impl<N: ItemTreeSource> HasSource for AssocItemLoc<N> {
|
||||
impl<N: ItemTreeNode> HasSource for AssocItemLoc<N> {
|
||||
type Value = N::Source;
|
||||
|
||||
fn source(&self, db: &dyn DefDatabase) -> InFile<N::Source> {
|
||||
|
@ -23,7 +23,7 @@ impl<N: ItemTreeSource> HasSource for AssocItemLoc<N> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<N: ItemTreeSource> HasSource for ItemLoc<N> {
|
||||
impl<N: ItemTreeNode> HasSource for ItemLoc<N> {
|
||||
type Value = N::Source;
|
||||
|
||||
fn source(&self, db: &dyn DefDatabase) -> InFile<N::Source> {
|
||||
|
|
Loading…
Reference in a new issue