mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-12 21:28:51 +00:00
reduce visibility
This commit is contained in:
parent
d095d9273e
commit
2a5254c106
4 changed files with 9 additions and 20 deletions
|
@ -80,7 +80,7 @@ pub use self::{
|
|||
path::{Path, PathKind},
|
||||
resolve::ScopeDef,
|
||||
source_binder::{PathResolution, ScopeEntryWithSyntax, SourceAnalyzer},
|
||||
source_id::{AstIdMap, ErasedFileAstId},
|
||||
source_id::AstIdMap,
|
||||
ty::{
|
||||
display::HirDisplay, ApplicationTy, CallableDef, Substs, TraitRef, Ty, TypeCtor, TypeWalk,
|
||||
},
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
//! FIXME: write short doc here
|
||||
|
||||
pub use hir_expand::{
|
||||
ast_id_map::{AstIdMap, ErasedFileAstId, FileAstId},
|
||||
ast_id_map::{AstIdMap, FileAstId},
|
||||
AstId,
|
||||
};
|
||||
|
|
|
@ -8,11 +8,10 @@
|
|||
use std::{
|
||||
hash::{Hash, Hasher},
|
||||
marker::PhantomData,
|
||||
ops,
|
||||
};
|
||||
|
||||
use ra_arena::{impl_arena_id, Arena, RawId};
|
||||
use ra_syntax::{ast, AstNode, SyntaxNode, SyntaxNodePtr};
|
||||
use ra_syntax::{ast, AstNode, AstPtr, SyntaxNode, SyntaxNodePtr};
|
||||
|
||||
/// `AstId` points to an AST node in a specific file.
|
||||
#[derive(Debug)]
|
||||
|
@ -40,14 +39,8 @@ impl<N: AstNode> Hash for FileAstId<N> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<N: AstNode> From<FileAstId<N>> for ErasedFileAstId {
|
||||
fn from(id: FileAstId<N>) -> Self {
|
||||
id.raw
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
pub struct ErasedFileAstId(RawId);
|
||||
struct ErasedFileAstId(RawId);
|
||||
impl_arena_id!(ErasedFileAstId);
|
||||
|
||||
/// Maps items' `SyntaxNode`s to `ErasedFileAstId`s and back.
|
||||
|
@ -90,18 +83,15 @@ impl AstIdMap {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn get<N: AstNode>(&self, id: FileAstId<N>) -> AstPtr<N> {
|
||||
self.arena[id.raw].cast::<N>().unwrap()
|
||||
}
|
||||
|
||||
fn alloc(&mut self, item: &SyntaxNode) -> ErasedFileAstId {
|
||||
self.arena.alloc(SyntaxNodePtr::new(item))
|
||||
}
|
||||
}
|
||||
|
||||
impl ops::Index<ErasedFileAstId> for AstIdMap {
|
||||
type Output = SyntaxNodePtr;
|
||||
fn index(&self, index: ErasedFileAstId) -> &SyntaxNodePtr {
|
||||
&self.arena[index]
|
||||
}
|
||||
}
|
||||
|
||||
/// Walks the subtree in bfs order, calling `f` for each node.
|
||||
fn bfs(node: &SyntaxNode, mut f: impl FnMut(SyntaxNode)) {
|
||||
let mut curr_layer = vec![node.clone()];
|
||||
|
|
|
@ -172,7 +172,6 @@ impl<N: AstNode> AstId<N> {
|
|||
|
||||
pub fn to_node(&self, db: &impl AstDatabase) -> N {
|
||||
let root = db.parse_or_expand(self.file_id).unwrap();
|
||||
let node = db.ast_id_map(self.file_id)[self.file_ast_id.into()].to_node(&root);
|
||||
N::cast(node).unwrap()
|
||||
db.ast_id_map(self.file_id).get(self.file_ast_id).to_node(&root)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue