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},
|
path::{Path, PathKind},
|
||||||
resolve::ScopeDef,
|
resolve::ScopeDef,
|
||||||
source_binder::{PathResolution, ScopeEntryWithSyntax, SourceAnalyzer},
|
source_binder::{PathResolution, ScopeEntryWithSyntax, SourceAnalyzer},
|
||||||
source_id::{AstIdMap, ErasedFileAstId},
|
source_id::AstIdMap,
|
||||||
ty::{
|
ty::{
|
||||||
display::HirDisplay, ApplicationTy, CallableDef, Substs, TraitRef, Ty, TypeCtor, TypeWalk,
|
display::HirDisplay, ApplicationTy, CallableDef, Substs, TraitRef, Ty, TypeCtor, TypeWalk,
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
//! FIXME: write short doc here
|
//! FIXME: write short doc here
|
||||||
|
|
||||||
pub use hir_expand::{
|
pub use hir_expand::{
|
||||||
ast_id_map::{AstIdMap, ErasedFileAstId, FileAstId},
|
ast_id_map::{AstIdMap, FileAstId},
|
||||||
AstId,
|
AstId,
|
||||||
};
|
};
|
||||||
|
|
|
@ -8,11 +8,10 @@
|
||||||
use std::{
|
use std::{
|
||||||
hash::{Hash, Hasher},
|
hash::{Hash, Hasher},
|
||||||
marker::PhantomData,
|
marker::PhantomData,
|
||||||
ops,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
use ra_arena::{impl_arena_id, Arena, RawId};
|
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.
|
/// `AstId` points to an AST node in a specific file.
|
||||||
#[derive(Debug)]
|
#[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)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||||
pub struct ErasedFileAstId(RawId);
|
struct ErasedFileAstId(RawId);
|
||||||
impl_arena_id!(ErasedFileAstId);
|
impl_arena_id!(ErasedFileAstId);
|
||||||
|
|
||||||
/// Maps items' `SyntaxNode`s to `ErasedFileAstId`s and back.
|
/// Maps items' `SyntaxNode`s to `ErasedFileAstId`s and back.
|
||||||
|
@ -90,15 +83,12 @@ impl AstIdMap {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn alloc(&mut self, item: &SyntaxNode) -> ErasedFileAstId {
|
pub fn get<N: AstNode>(&self, id: FileAstId<N>) -> AstPtr<N> {
|
||||||
self.arena.alloc(SyntaxNodePtr::new(item))
|
self.arena[id.raw].cast::<N>().unwrap()
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ops::Index<ErasedFileAstId> for AstIdMap {
|
fn alloc(&mut self, item: &SyntaxNode) -> ErasedFileAstId {
|
||||||
type Output = SyntaxNodePtr;
|
self.arena.alloc(SyntaxNodePtr::new(item))
|
||||||
fn index(&self, index: ErasedFileAstId) -> &SyntaxNodePtr {
|
|
||||||
&self.arena[index]
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -172,7 +172,6 @@ impl<N: AstNode> AstId<N> {
|
||||||
|
|
||||||
pub fn to_node(&self, db: &impl AstDatabase) -> N {
|
pub fn to_node(&self, db: &impl AstDatabase) -> N {
|
||||||
let root = db.parse_or_expand(self.file_id).unwrap();
|
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);
|
db.ast_id_map(self.file_id).get(self.file_ast_id).to_node(&root)
|
||||||
N::cast(node).unwrap()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue