diff --git a/src/source.rs b/src/source.rs index 9038ee4..7707511 100644 --- a/src/source.rs +++ b/src/source.rs @@ -94,6 +94,7 @@ pub struct Source = String> { lines: Vec, len: usize, byte_len: usize, + display_line_offset: usize, } impl> Source { @@ -121,6 +122,7 @@ impl> From for Source { }], len: 0, byte_len: 0, + display_line_offset: 0, }; } @@ -162,11 +164,23 @@ impl> From for Source { lines, len: char_offset, byte_len: byte_offset, + display_line_offset: 0, } } } impl> Source { + /// Add an offset to the printed line numbers + pub fn with_display_line_offset(mut self, offset: usize) -> Self { + self.display_line_offset = offset; + self + } + + /// Get the offset added to printed line numbers + pub fn display_line_offset(&self) -> usize { + self.display_line_offset + } + /// Get the length of the total number of characters in the source. pub fn len(&self) -> usize { self.len diff --git a/src/write.rs b/src/write.rs index c667fa1..562327e 100644 --- a/src/write.rs +++ b/src/write.rs @@ -258,7 +258,12 @@ impl Report<'_, S> { }), }; let (line_no, col_no) = line_and_col - .map(|(_, idx, col)| (format!("{}", idx + 1), format!("{}", col + 1))) + .map(|(_, idx, col)| { + ( + format!("{}", idx + 1 + src.display_line_offset()), + format!("{}", col + 1), + ) + }) .unwrap_or_else(|| ('?'.to_string(), '?'.to_string())); let line_ref = format!(":{}:{}", line_no, col_no); writeln!(