caretToByteOffset converts a 1-based line and 0-based column offset to a byte offset. Note: caretOffset is treated as a rune (code point) offset, not UTF-16 code units. This matches the existing behavior of the completion callers in this codebase.
(statement string, caretLine int, caretOffset int)
| 99 | // Note: caretOffset is treated as a rune (code point) offset, not UTF-16 code units. |
| 100 | // This matches the existing behavior of the completion callers in this codebase. |
| 101 | func caretToByteOffset(statement string, caretLine int, caretOffset int) int { |
| 102 | line := 1 |
| 103 | col := 0 |
| 104 | for i, r := range statement { |
| 105 | if line == caretLine && col == caretOffset { |
| 106 | return i |
| 107 | } |
| 108 | if r == '\n' { |
| 109 | line++ |
| 110 | col = 0 |
| 111 | } else { |
| 112 | col++ |
| 113 | } |
| 114 | } |
| 115 | return len(statement) |
| 116 | } |
| 117 | |
| 118 | // isAfterOpenBracket checks if the cursor position is inside bracket notation (db[|). |
| 119 | func isAfterOpenBracket(statement string, byteOffset int) bool { |