mirror of https://github.com/zkat/miette.git
fix(graphical): fix issue with duplicate labels when span len is 0 (#159)
Fixes: https://github.com/zkat/miette/issues/130
This commit is contained in:
parent
084ed138b7
commit
1a36fa7ec8
|
|
@ -776,12 +776,13 @@ impl Line {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn span_applies(&self, span: &FancySpan) -> bool {
|
fn span_applies(&self, span: &FancySpan) -> bool {
|
||||||
|
let spanlen = if span.len() == 0 { 1 } else { span.len() };
|
||||||
// Span starts in this line
|
// Span starts in this line
|
||||||
(span.offset() >= self.offset && span.offset() < self.offset + self.length)
|
(span.offset() >= self.offset && span.offset() < self.offset + self.length)
|
||||||
// Span passes through this line
|
// Span passes through this line
|
||||||
|| (span.offset() < self.offset && span.offset() + span.len() > self.offset + self.length) //todo
|
|| (span.offset() < self.offset && span.offset() + spanlen > self.offset + self.length) //todo
|
||||||
// Span ends on this line
|
// Span ends on this line
|
||||||
|| (span.offset() + span.len() > self.offset && span.offset() + span.len() <= self.offset + self.length)
|
|| (span.offset() + spanlen > self.offset && span.offset() + spanlen <= self.offset + self.length)
|
||||||
}
|
}
|
||||||
|
|
||||||
// A 'flyby' is a multi-line span that technically covers this line, but
|
// A 'flyby' is a multi-line span that technically covers this line, but
|
||||||
|
|
|
||||||
|
|
@ -881,3 +881,35 @@ Error: oops::my::bad
|
||||||
assert_eq!(expected, out);
|
assert_eq!(expected, out);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn zero_length_eol_span() {
|
||||||
|
#[derive(Error, Debug, Diagnostic)]
|
||||||
|
#[error("oops!")]
|
||||||
|
#[diagnostic(severity(Error))]
|
||||||
|
struct MyBad {
|
||||||
|
#[source_code]
|
||||||
|
src: NamedSource,
|
||||||
|
#[label("This bit here")]
|
||||||
|
bad_bit: SourceSpan,
|
||||||
|
}
|
||||||
|
let err = MyBad {
|
||||||
|
src: NamedSource::new("issue", "this is the first line\nthis is the second line"),
|
||||||
|
bad_bit: (23, 0).into(),
|
||||||
|
};
|
||||||
|
let out = fmt_report(err.into());
|
||||||
|
println!("Error: {}", out);
|
||||||
|
|
||||||
|
let expected = r#"
|
||||||
|
× oops!
|
||||||
|
╭─[issue:1:1]
|
||||||
|
1 │ this is the first line
|
||||||
|
2 │ this is the second line
|
||||||
|
· ▲
|
||||||
|
· ╰── This bit here
|
||||||
|
╰────
|
||||||
|
"#
|
||||||
|
.to_string();
|
||||||
|
|
||||||
|
assert_eq!(expected, out);
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue