ts_error/diagnostic/
span.rs

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