diagnostic formatting: respect tab characters
This commit is contained in:
parent
4e9a4d1204
commit
cf2ea4df78
1 changed files with 16 additions and 2 deletions
|
@ -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::<String>()
|
||||
.bright_white());
|
||||
}
|
||||
|
||||
print!("\t{}", "|".bright_magenta());
|
||||
|
|
Loading…
Reference in a new issue