ts_error/diagnostic/
span.rs

1//! The span of some context.
2
3#[derive(Debug, Clone, Copy, PartialEq, Eq)]
4/// A span for diagnostics, maps to a location in a source file.
5pub struct Span {
6    /// One-indexed line number.
7    pub line: usize,
8    /// One-indexed column of the span start.
9    pub column: usize,
10    /// Number of graphemes the span goes for.
11    pub length: usize,
12}
13impl Default for Span {
14    fn default() -> Self {
15        Self {
16            line: 1,
17            column: 1,
18            length: 1,
19        }
20    }
21}
22impl Span {
23    /// Sets the line of the span, lines should be one-indexed.
24    pub fn line(mut self, line: usize) -> Self {
25        self.line = line;
26        self
27    }
28
29    /// Sets the column of the span, columns should be one-indexed.
30    pub fn column(mut self, column: usize) -> Self {
31        self.column = column;
32        self
33    }
34
35    /// Sets the length of the span.
36    pub fn length(mut self, length: usize) -> Self {
37        self.length = length;
38        self
39    }
40}