diff options
| author | DanielGavin <danielgavin5@hotmail.com> | 2024-05-21 22:00:56 +0200 |
|---|---|---|
| committer | DanielGavin <danielgavin5@hotmail.com> | 2024-05-21 22:00:56 +0200 |
| commit | 6971f37274a6ef8a3e8fc58e9bd1bd92b1743a38 (patch) | |
| tree | 3e21b0938f5da7b91c24e2a4e5bfb568306c2d6f /src/common | |
| parent | e9700998497e40d61695762742d6a315353cec8f (diff) | |
Add validation when calculating the offset for token_range.
Diffstat (limited to 'src/common')
| -rw-r--r-- | src/common/position.odin | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/src/common/position.odin b/src/common/position.odin index b222086..739f3aa 100644 --- a/src/common/position.odin +++ b/src/common/position.odin @@ -4,6 +4,7 @@ import "core:strings" import "core:unicode/utf8" import "core:fmt" import "core:odin/ast" +import "core:log" /* This file handles the conversion between utf-16 and utf-8 offsets in the text document @@ -129,12 +130,16 @@ go_backwards_to_endline :: proc(offset: int, document_text: []u8) -> int { get_token_range :: proc(node: ast.Node, document_text: string) -> Range { range: Range - pos_offset := min(len(document_text) - 1, node.pos.offset) end_offset := min(len(document_text) - 1, node.end.offset) offset := go_backwards_to_endline(pos_offset, transmute([]u8)document_text) + if offset < 0 { + offset := 0 + log.errorf("Failed to find offset in get_token_range: %v", node) + } + range.start.line = node.pos.line - 1 range.start.character = get_character_offset_u8_to_u16( node.pos.column - 1, |