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

Function skipHeadingSQLWithoutSemicolon

backend/plugin/parser/pg/completion.go:1452–1490  ·  view source on GitHub ↗

caretLine is 1-based and caretOffset is 0-based.

(statement string, caretLine int, caretOffset int)

Source from the content-addressed store, hash-verified

1450
1451// caretLine is 1-based and caretOffset is 0-based.
1452func skipHeadingSQLWithoutSemicolon(statement string, caretLine int, caretOffset int) (string, int, int) {
1453 tokens := pgparser.Tokenize(statement)
1454 caretByteOff := lineColumnToByteOffset(statement, caretLine, caretOffset)
1455
1456 latestSelectOffset := -1
1457 latestSelectLine := 0
1458 newCaretLine, newCaretOffset := caretLine, caretOffset
1459
1460 for _, tok := range tokens {
1461 if tok.Loc >= caretByteOff {
1462 break
1463 }
1464 if tok.Type == pgparser.SELECT {
1465 // Check that this SELECT starts at column 0 of its line.
1466 // Either it's the first byte of the string, or the byte immediately
1467 // before it is a newline.
1468 atColumn0 := tok.Loc == 0 || statement[tok.Loc-1] == '\n'
1469 if atColumn0 {
1470 latestSelectOffset = tok.Loc
1471 // Compute the line number of this token.
1472 line := 1
1473 for j := 0; j < tok.Loc; j++ {
1474 if statement[j] == '\n' {
1475 line++
1476 }
1477 }
1478 latestSelectLine = line
1479 newCaretLine = caretLine - latestSelectLine + 1
1480 newCaretOffset = caretOffset
1481 }
1482 }
1483 }
1484
1485 if latestSelectOffset < 0 {
1486 return statement, caretLine, caretOffset
1487 }
1488
1489 return statement[latestSelectOffset:], newCaretLine, newCaretOffset
1490}
1491
1492func (c *Completer) listAllSchemas() []string {
1493 if _, exists := c.metadataCache[c.defaultDatabase]; !exists {

Callers 1

computeSQLAndByteOffsetFunction · 0.70

Calls 1

lineColumnToByteOffsetFunction · 0.70

Tested by

no test coverage detected