MCPcopy Create free account
hub / github.com/bytebase/bytebase / lineColumnToByteOffset

Function lineColumnToByteOffset

backend/plugin/parser/tsql/completion.go:510–529  ·  view source on GitHub ↗
(sql string, line, column int)

Source from the content-addressed store, hash-verified

508}
509
510func lineColumnToByteOffset(sql string, line, column int) int {
511 currentLine := 1
512 for i := 0; i < len(sql); i++ {
513 if currentLine == line {
514 pos := i
515 for c := 0; c < column && pos < len(sql); c++ {
516 _, size := utf8.DecodeRuneInString(sql[pos:])
517 pos += size
518 }
519 if pos > len(sql) {
520 return len(sql)
521 }
522 return pos
523 }
524 if sql[i] == '\n' {
525 currentLine++
526 }
527 }
528 return len(sql)
529}
530
531func findCaretTokenIndex(tokens []mssqlparser.Token, byteOffset int) int {
532 for i, tok := range tokens {

Callers 1

computeSQLAndByteOffsetFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected