From 6c6f283352c728a4dcef45f7feadc3fabbbed44c Mon Sep 17 00:00:00 2001 From: Michael Sippel Date: Wed, 14 Aug 2024 00:27:21 +0200 Subject: [PATCH] diagnostic formatting: respect tab characters --- ltcc/src/diagnostic.rs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/ltcc/src/diagnostic.rs b/ltcc/src/diagnostic.rs index 7764509..5624509 100644 --- a/ltcc/src/diagnostic.rs +++ b/ltcc/src/diagnostic.rs @@ -28,7 +28,6 @@ pub fn print_diagnostic( println!("\n{}:", path.green()); for (i, l) in lines.enumerate() { - line_region.end += l.chars().count(); last_lines.push((i+1, l.clone())); @@ -44,12 +43,27 @@ pub fn print_diagnostic( let column_begin = region.begin - line_region.begin; let column_end = region.end - line_region.begin; + + let tab_width = 4; + + let column_begin_c = column_begin + (tab_width-1)*l.chars().take(column_begin).filter(|&c|c=='\t').count(); + let column_end_c = column_end + (tab_width-1)*l.chars().filter(|&c|c=='\t').count(); + // display the source line for (j,ll) in last_lines.iter() { print!("{}\t{}{}", format!("{}",j).to_string().bright_black(), "|".bright_black().bold(), - ll.bright_white()); + ll.chars().map(|c| { + if c == '\t' { + std::iter::repeat(' ').take(tab_width) + } else { + std::iter::repeat(c).take(1) + } + }) + .flatten() + .collect::() + .bright_white()); } print!("\t{}", "|".bright_magenta());