Skip to main content

thrift_analyzer/analyzer/
base.rs

1//! Base types for the analyzer.
2
3use serde::{Deserialize, Serialize};
4
5/// Represents a location in a document.
6#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Default, Serialize, Deserialize)]
7pub struct Position {
8    /// Line number in a document (one-based).
9    pub line: u32,
10    /// Column offset on a line in a document (one-based).
11    pub column: u32,
12}
13
14/// Represents a range in a document.
15#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
16pub struct Range {
17    /// Start position of the range.
18    pub start: Position,
19    /// End position of the range.
20    pub end: Position,
21}
22
23impl Range {
24    pub fn contains(&self, pos: Position) -> bool {
25        self.start <= pos && pos <= self.end
26    }
27}
28
29/// Represents a range in the path.
30#[derive(Debug, Clone, Serialize, Deserialize)]
31pub struct Location {
32    pub path: String,
33    pub range: Range,
34}
35
36/// Represents a error in the document.
37#[derive(Debug, Clone, Serialize, Deserialize)]
38pub struct Error {
39    pub range: Range,
40    pub message: String,
41}