use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "wasm", derive(tsify_next::Tsify))]
#[cfg_attr(feature = "wasm", tsify(into_wasm_abi, from_wasm_abi))]
pub enum SemanticOrigin {
BufferPosition {
buffer_id: u64,
line: u32,
col: u32,
},
BufferRange {
buffer_id: u64,
start_line: u32,
start_col: u32,
end_line: u32,
end_col: u32,
},
Buffer {
buffer_id: u64,
},
Session,
}
impl SemanticOrigin {
#[must_use]
pub const fn buffer_position(buffer_id: u64, line: u32, col: u32) -> Self {
Self::BufferPosition {
buffer_id,
line,
col,
}
}
#[must_use]
pub const fn buffer_range(
buffer_id: u64,
start_line: u32,
start_col: u32,
end_line: u32,
end_col: u32,
) -> Self {
Self::BufferRange {
buffer_id,
start_line,
start_col,
end_line,
end_col,
}
}
#[must_use]
pub const fn buffer(buffer_id: u64) -> Self {
Self::Buffer { buffer_id }
}
#[must_use]
pub const fn session() -> Self {
Self::Session
}
#[must_use]
pub const fn buffer_id(&self) -> Option<u64> {
match self {
Self::BufferPosition { buffer_id, .. }
| Self::BufferRange { buffer_id, .. }
| Self::Buffer { buffer_id } => Some(*buffer_id),
Self::Session => None,
}
}
#[must_use]
pub const fn is_session(&self) -> bool {
matches!(self, Self::Session)
}
}
#[cfg(test)]
#[path = "origin_tests.rs"]
mod tests;