tamer: diagnost::resolver::ResolvedSpan: Clear methods for all data

This (a) makes it clear the intent of these methods and (b) will allow
introducing a trait for mocking it.

DEV-12151
main
Mike Gerwitz 2022-04-26 10:22:31 -04:00
parent b9ff7770aa
commit ec93488365
2 changed files with 21 additions and 3 deletions

View File

@ -134,7 +134,7 @@ impl MaybeResolvedSpan {
fn header(&self) -> SpanHeader {
match self {
Self::Resolved(rspan) => {
SpanHeader(rspan.span.ctx(), HeaderLineNum::Resolved(&rspan))
SpanHeader(rspan.ctx(), HeaderLineNum::Resolved(&rspan))
}
Self::Unresolved(span, _) => {
@ -260,7 +260,7 @@ struct HeaderColNum<'s>(&'s ResolvedSpan);
impl<'s> Display for HeaderColNum<'s> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let Self(rspan) = self;
let span = rspan.span;
let span = rspan.unresolved_span();
match rspan.col_num() {
Some(col) => write!(f, ":{}", col),

View File

@ -122,7 +122,7 @@ impl<T> AsRef<Vec<T>> for NonEmptyVec<T> {
#[derive(Debug, PartialEq, Eq)]
pub struct ResolvedSpan {
/// The original [`Span`] whose resolution was requested.
pub span: Span,
span: Span,
/// The lines of source code that correspond to this [`Span`],
/// if known.
@ -135,17 +135,35 @@ pub struct ResolvedSpan {
}
impl ResolvedSpan {
/// Line number representing the offset of the [`Span`].
pub fn line_num(&self) -> NonZeroU32 {
self.lines.first().num
}
/// Column number(s) relative to the beginning of the line.
///
/// The column may not be able to be resolved if the line contains
/// invalid UTF-8 data.
pub fn col_num(&self) -> Option<Column> {
self.lines.first().column
}
/// A [`Span`] representing the first line.
///
/// Note that many spans have only one line associated with them.
pub fn first_line_span(&self) -> Span {
self.lines.first().span
}
/// [`Context`] of the [`Span`] used for resolution.
pub fn ctx(&self) -> Context {
self.span.ctx()
}
/// The original [`Span`] before resolution.
pub fn unresolved_span(&self) -> Span {
self.span
}
}
/// Source column offsets.