pub use lsp_types::PositionEncodingKind;
pub use typst::introspection::PagedPosition as TypstPosition;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
pub struct DocumentPosition {
pub page_no: usize,
pub x: f32,
pub y: f32,
}
impl From<TypstPosition> for DocumentPosition {
fn from(position: TypstPosition) -> Self {
Self {
page_no: position.page.into(),
x: position.point.x.to_pt() as f32,
y: position.point.y.to_pt() as f32,
}
}
}
pub type RawSourceSpan = u64;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct FileLocation {
pub filepath: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SourceLocation {
pub filepath: String,
pub pos: LspPosition,
}
impl SourceLocation {
pub fn from_flat(
flat: FlatSourceLocation,
i: &impl std::ops::Index<usize, Output = FileLocation>,
) -> Self {
Self {
filepath: i[flat.filepath as usize].filepath.clone(),
pos: flat.pos,
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct FlatSourceLocation {
pub filepath: u32,
pub pos: LspPosition,
}
pub type LspPosition = lsp_types::Position;
pub type LspRange = lsp_types::Range;
#[deprecated(note = "Use `LspPosition` instead.")]
pub type CharPosition = LspPosition;
#[deprecated(note = "Use `LspRange` instead.")]
pub type CharRange = LspRange;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SourceRange {
pub path: String,
pub range: LspRange,
}
pub type SourceSpan = typst::syntax::Span;
#[derive(Debug, Clone, Copy)]
pub struct SourceSpanOffset {
pub span: SourceSpan,
pub offset: usize,
}
impl From<SourceSpan> for SourceSpanOffset {
fn from(span: SourceSpan) -> Self {
Self { span, offset: 0 }
}
}
impl From<(SourceSpan, u16)> for SourceSpanOffset {
fn from((span, offset): (SourceSpan, u16)) -> Self {
Self {
span,
offset: offset as usize,
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ElementPoint {
pub kind: u32,
pub index: u32,
pub fingerprint: String,
}
impl From<(u32, u32, String)> for ElementPoint {
fn from((kind, index, fingerprint): (u32, u32, String)) -> Self {
Self {
kind,
index,
fingerprint,
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash)]
pub struct FsDataSource {
pub path: String,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash)]
pub struct MemoryDataSource {
pub name: String,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash)]
#[serde(tag = "kind")]
pub enum DataSource {
#[serde(rename = "fs")]
Fs(FsDataSource),
#[serde(rename = "memory")]
Memory(MemoryDataSource),
}