Proper span representation with syntax context

This commit is contained in:
Lukas Wirth 2023-10-06 14:47:11 +02:00
parent 890eb17b4e
commit e36b3f7b8c
16 changed files with 414 additions and 470 deletions

View file

@ -39,7 +39,7 @@ use std::collections::{HashMap, VecDeque};
use serde::{Deserialize, Serialize};
use text_size::TextRange;
use tt::Span;
use tt::{Span, SyntaxContext};
use crate::msg::{ENCODE_CLOSE_SPAN_VERSION, VARIABLE_SIZED_SPANS};
@ -47,25 +47,30 @@ pub trait SerializableSpan<const L: usize>: Span {
fn into_u32(self) -> [u32; L];
fn from_u32(input: [u32; L]) -> Self;
}
impl SerializableSpan<1> for tt::TokenId {
fn into_u32(self) -> [u32; 1] {
[self.0]
}
fn from_u32([input]: [u32; 1]) -> Self {
tt::TokenId(input)
}
}
// impl SerializableSpan<1> for tt::TokenId {
// fn into_u32(self) -> [u32; 1] {
// [self.0]
// }
// fn from_u32([input]: [u32; 1]) -> Self {
// tt::TokenId(input)
// }
// }
impl<FileId> SerializableSpan<3> for tt::SpanData<FileId>
impl<Anchor, Ctx> SerializableSpan<3> for tt::SpanData<Anchor, Ctx>
where
FileId: From<u32> + Into<u32>,
Anchor: From<u32> + Into<u32>,
Self: Span,
Ctx: SyntaxContext,
{
fn into_u32(self) -> [u32; 3] {
[self.anchor.into(), self.range.start().into(), self.range.end().into()]
}
fn from_u32([file_id, start, end]: [u32; 3]) -> Self {
tt::SpanData { anchor: file_id.into(), range: TextRange::new(start.into(), end.into()) }
tt::SpanData {
anchor: file_id.into(),
range: TextRange::new(start.into(), end.into()),
ctx: Ctx::DUMMY,
}
}
}