mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 12:21:58 +00:00
parent
e7ce633d8c
commit
65571d73a7
1 changed files with 3 additions and 1 deletions
|
|
@ -369,8 +369,10 @@ fn get_valid_extensions() -> Vec<&'static str> {
|
|||
#[allow(clippy::cast_possible_truncation)]
|
||||
fn offset_to_position(offset: usize, source_text: &str) -> Option<Position> {
|
||||
let rope = Rope::from_str(source_text);
|
||||
let line = rope.try_char_to_line(offset).ok()?;
|
||||
let line = rope.try_byte_to_line(offset).ok()?;
|
||||
let first_char_of_line = rope.try_line_to_char(line).ok()?;
|
||||
// Original offset is byte, but Rope uses char offset
|
||||
let offset = rope.try_byte_to_char(offset).ok()?;
|
||||
let column = offset - first_char_of_line;
|
||||
Some(Position::new(line as u32, column as u32))
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue