1use codespan_reporting::diagnostic;
2
3use super::Span;
4
5#[derive(Debug, Eq, PartialEq, Clone)]
6pub struct Label {
7 pub message: String,
8 pub primary: bool,
9 pub span: Span,
10}
11
12impl Label {
13 pub fn primary(message: impl ToString, span: impl Into<Span>) -> Self {
14 Self {
15 message: message.to_string(),
16 primary: true,
17 span: span.into(),
18 }
19 }
20
21 pub fn context(message: impl ToString, span: impl Into<Span>) -> Self {
22 Self {
23 message: message.to_string(),
24 primary: false,
25 span: span.into(),
26 }
27 }
28}
29
30impl From<Label> for diagnostic::Label<()> {
31 fn from(label: Label) -> Self {
32 let style = match label.primary {
33 true => diagnostic::LabelStyle::Primary,
34 false => diagnostic::LabelStyle::Secondary,
35 };
36
37 diagnostic::Label {
38 style,
39 file_id: (),
40 range: label.span.start()..label.span.end(),
41 message: label.message,
42 }
43 }
44}