Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/span/src/lib.rs')
-rw-r--r--crates/span/src/lib.rs52
1 files changed, 13 insertions, 39 deletions
diff --git a/crates/span/src/lib.rs b/crates/span/src/lib.rs
index 7763d75cc9..0fe3275863 100644
--- a/crates/span/src/lib.rs
+++ b/crates/span/src/lib.rs
@@ -3,9 +3,16 @@ use std::fmt::{self, Write};
use salsa::InternId;
+mod ast_id;
+mod hygiene;
mod map;
-pub use crate::map::{RealSpanMap, SpanMap};
+pub use self::{
+ ast_id::{AstIdMap, AstIdNode, ErasedFileAstId, FileAstId},
+ hygiene::{SyntaxContextData, SyntaxContextId, Transparency},
+ map::{RealSpanMap, SpanMap},
+};
+
pub use syntax::{TextRange, TextSize};
pub use vfs::FileId;
@@ -21,9 +28,10 @@ pub struct FileRange {
pub range: TextRange,
}
-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
+/// The root ast id always points to the encompassing file, using this in spans is discouraged as
+/// any range relative to it will be effectively absolute, ruining the entire point of anchored
+/// relative text ranges.
pub const ROOT_ERASED_FILE_AST_ID: ErasedFileAstId =
la_arena::Idx::from_raw(la_arena::RawIdx::from_u32(0));
@@ -42,6 +50,7 @@ pub struct SpanData<Ctx> {
/// We need the anchor for incrementality, as storing absolute ranges will require
/// recomputation on every change in a file at all times.
pub range: TextRange,
+ /// The anchor this span is relative to.
pub anchor: SpanAnchor,
/// The syntax context of the span.
pub ctx: Ctx,
@@ -68,41 +77,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,