mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-29 05:15:04 +00:00
Proper span representation with syntax context
This commit is contained in:
parent
890eb17b4e
commit
e36b3f7b8c
16 changed files with 414 additions and 470 deletions
|
@ -32,27 +32,37 @@ impl TokenId {
|
|||
Self::UNSPECIFIED
|
||||
}
|
||||
}
|
||||
impl Span for TokenId {
|
||||
const DUMMY: Self = TokenId(!0);
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
|
||||
pub struct SpanData<Anchor> {
|
||||
pub struct SpanData<Anchor, Ctx> {
|
||||
/// The text range of this span, relative to the anchor.
|
||||
/// 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,
|
||||
pub anchor: Anchor,
|
||||
/// The syntax context of the span.
|
||||
pub ctx: Ctx,
|
||||
}
|
||||
|
||||
impl<Anchor: Span> Span for SpanData<Anchor> {
|
||||
const DUMMY: Self =
|
||||
SpanData { range: TextRange::empty(TextSize::new(0)), anchor: Anchor::DUMMY };
|
||||
impl<Anchor: SpanAnchor, Ctx: SyntaxContext> Span for SpanData<Anchor, Ctx> {
|
||||
const DUMMY: Self = SpanData {
|
||||
range: TextRange::empty(TextSize::new(0)),
|
||||
anchor: Anchor::DUMMY,
|
||||
ctx: Ctx::DUMMY,
|
||||
};
|
||||
}
|
||||
|
||||
pub trait SpanAnchor: std::fmt::Debug + Copy + Sized + Eq {
|
||||
const DUMMY: Self;
|
||||
}
|
||||
|
||||
pub trait Span: std::fmt::Debug + Copy + Sized + Eq {
|
||||
const DUMMY: Self;
|
||||
}
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub struct SyntaxContext(pub u32);
|
||||
|
||||
pub trait SyntaxContext: std::fmt::Debug + Copy + Sized + Eq {
|
||||
const DUMMY: Self;
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub enum TokenTree<S> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue