mirror of https://github.com/kdl-org/kdl-rs.git
fix(lsp): clamp char index to rope length in char_to_position
Prevents a panic when a diagnostic span's end offset lands past the end of the rope. Fixes kdl-org/vscode-kdl#29
This commit is contained in:
parent
6841734233
commit
e56b6c1cba
|
|
@ -160,6 +160,7 @@ impl LanguageServer for Backend {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn char_to_position(char_idx: usize, rope: &Rope) -> Position {
|
fn char_to_position(char_idx: usize, rope: &Rope) -> Position {
|
||||||
|
let char_idx = char_idx.min(rope.len_chars());
|
||||||
let line_idx = rope.char_to_line(char_idx);
|
let line_idx = rope.char_to_line(char_idx);
|
||||||
let line_char_idx = rope.line_to_char(line_idx);
|
let line_char_idx = rope.line_to_char(line_idx);
|
||||||
let column_idx = char_idx - line_char_idx;
|
let column_idx = char_idx - line_char_idx;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue