mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 04:44:57 +00:00
minor: Add some basic docs for spans/hygiene handling
This commit is contained in:
parent
9efa23c4da
commit
eb7a4f293e
5 changed files with 184 additions and 129 deletions
|
@ -3,9 +3,14 @@ use std::fmt::{self, Write};
|
|||
|
||||
use salsa::InternId;
|
||||
|
||||
mod hygiene;
|
||||
mod map;
|
||||
|
||||
pub use crate::map::{RealSpanMap, SpanMap};
|
||||
pub use self::{
|
||||
hygiene::{SyntaxContextData, SyntaxContextId, Transparency},
|
||||
map::{RealSpanMap, SpanMap},
|
||||
};
|
||||
|
||||
pub use syntax::{TextRange, TextSize};
|
||||
pub use vfs::FileId;
|
||||
|
||||
|
@ -23,7 +28,7 @@ pub struct FileRange {
|
|||
|
||||
pub type ErasedFileAstId = la_arena::Idx<syntax::SyntaxNodePtr>;
|
||||
|
||||
// The first inde is always the root node's AstId
|
||||
// The first index is always the root node's AstId
|
||||
pub const ROOT_ERASED_FILE_AST_ID: ErasedFileAstId =
|
||||
la_arena::Idx::from_raw(la_arena::RawIdx::from_u32(0));
|
||||
|
||||
|
@ -68,41 +73,6 @@ impl fmt::Display for Span {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
pub struct SyntaxContextId(InternId);
|
||||
|
||||
impl salsa::InternKey for SyntaxContextId {
|
||||
fn from_intern_id(v: salsa::InternId) -> Self {
|
||||
SyntaxContextId(v)
|
||||
}
|
||||
fn as_intern_id(&self) -> salsa::InternId {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for SyntaxContextId {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "{}", self.0.as_u32())
|
||||
}
|
||||
}
|
||||
|
||||
// inherent trait impls please tyvm
|
||||
impl SyntaxContextId {
|
||||
pub const ROOT: Self = SyntaxContextId(unsafe { InternId::new_unchecked(0) });
|
||||
|
||||
pub fn is_root(self) -> bool {
|
||||
self == Self::ROOT
|
||||
}
|
||||
|
||||
pub fn into_u32(self) -> u32 {
|
||||
self.0.as_u32()
|
||||
}
|
||||
|
||||
pub fn from_u32(u32: u32) -> Self {
|
||||
Self(InternId::from(u32))
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct SpanAnchor {
|
||||
pub file_id: FileId,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue