Skip to content

Commit

Permalink
Account for characters that are larger than 1 byte when displaying wa…
Browse files Browse the repository at this point in the history
…rnings and errors (#2267)
  • Loading branch information
mohammadfawaz authored Jul 8, 2022
1 parent 3a0010b commit fa003ff
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions forc-util/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,23 +383,25 @@ fn construct_window<'a>(
let mut lines_to_start_of_snippet = 0;
let mut calculated_start_ix = None;
let mut calculated_end_ix = None;
for (ix, character) in input.chars().enumerate() {
let mut pos = 0;
for character in input.chars() {
if character == '\n' {
current_line += 1
}

if current_line + NUM_LINES_BUFFER >= start.line && calculated_start_ix.is_none() {
calculated_start_ix = Some(ix);
calculated_start_ix = Some(pos);
lines_to_start_of_snippet = current_line;
}

if current_line >= end.line + NUM_LINES_BUFFER && calculated_end_ix.is_none() {
calculated_end_ix = Some(ix);
calculated_end_ix = Some(pos);
}

if calculated_start_ix.is_some() && calculated_end_ix.is_some() {
break;
}
pos += character.len_utf8();
}
let calculated_start_ix = calculated_start_ix.unwrap_or(0);
let calculated_end_ix = calculated_end_ix.unwrap_or(input.len());
Expand Down

0 comments on commit fa003ff

Please sign in to comment.