MCPcopy Index your code
hub / github.com/bytebase/bytebase / caretToByteOffset

Function caretToByteOffset

backend/plugin/parser/mongodb/completion.go:101–116  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
101func 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[|).
119func isAfterOpenBracket(statement string, byteOffset int) bool {

Callers 1

CompletionFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected