mir_types/location.rs
1use std::fmt;
2use std::sync::Arc;
3
4use serde::{Deserialize, Serialize};
5
6/// Source location: file path and a Unicode code-point span.
7///
8/// Columns are 0-based Unicode scalar value (code-point) counts, equivalent to
9/// LSP `utf-32` position encoding. Convert to UTF-16 code units at the LSP
10/// boundary for clients that do not advertise `utf-32` support.
11#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
12pub struct Location {
13 pub file: Arc<str>,
14 /// 1-based start line.
15 pub line: u32,
16 /// 1-based end line (inclusive). Equal to `line` for single-line spans.
17 pub line_end: u32,
18 /// 0-based Unicode code-point column of the span start.
19 pub col_start: u16,
20 /// 0-based Unicode code-point column of the span end (exclusive).
21 pub col_end: u16,
22}
23
24impl fmt::Display for Location {
25 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
26 write!(f, "{}:{}:{}", self.file, self.line, self.col_start)
27 }
28}