aboutsummaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorDamian Tarnawski <gthetarnav@gmail.com>2025-07-05 00:09:54 +0200
committerDamian Tarnawski <gthetarnav@gmail.com>2025-07-05 00:09:54 +0200
commit2a37eeda1f681c7b0d0eb29b32e43cf3d7f5d374 (patch)
tree7b706b4526a3dae206f87a66a9b2f671cf2f588b /src/common
parent384aaa75affae6fdceca2811ddd9a0b57d842e2d (diff)
Better handle inlay hints with named params passed not in order
Diffstat (limited to 'src/common')
-rw-r--r--src/common/position.odin39
1 files changed, 20 insertions, 19 deletions
diff --git a/src/common/position.odin b/src/common/position.odin
index 1eecfdc..ca3976a 100644
--- a/src/common/position.odin
+++ b/src/common/position.odin
@@ -3,6 +3,7 @@ package common
import "core:fmt"
import "core:log"
import "core:odin/ast"
+import "core:odin/tokenizer"
import "core:strings"
import "core:unicode/utf8"
@@ -101,31 +102,31 @@ go_backwards_to_endline :: proc(offset: int, document_text: []u8) -> int {
return index + 1
}
-/*
- Get the range of a token in utf16 space
-*/
-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)
+token_pos_to_position :: proc(pos: tokenizer.Pos, document_text: string) -> (position: Position) {
+ pos_offset := min(len(document_text) - 1, pos.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)
+ offset = 0
+ log.errorf("Failed to find offset in token_pos_to_position: %v", pos)
}
- range.start.line = node.pos.line - 1
- range.start.character = get_character_offset_u8_to_u16(node.pos.column - 1, transmute([]u8)document_text[offset:])
-
- offset = go_backwards_to_endline(end_offset - 1, transmute([]u8)document_text)
-
- range.end.line = node.end.line - 1
- range.end.character = get_character_offset_u8_to_u16(node.end.column - 1, transmute([]u8)document_text[offset:])
+ return {
+ line = pos.line-1,
+ character = get_character_offset_u8_to_u16(pos.column-1, transmute([]u8)document_text[offset:]),
+ }
+}
- return range
+/*
+ Get the range of a token in utf16 space
+*/
+get_token_range :: proc(node: ast.Node, document_text: string) -> (range: Range) {
+ range.start = token_pos_to_position(node.pos, document_text)
+ end_pos := node.end
+ end_pos.offset -= 1
+ range.end = token_pos_to_position(end_pos, document_text)
+ return
}
get_absolute_range :: proc(range: Range, document_text: []u8) -> (AbsoluteRange, bool) {