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

Function findCaretTokenIndex

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

findCaretTokenIndex returns the index of the first token whose start (Loc) is at or past byteOffset. This matches ANTLR Scanner.SeekPosition semantics: the caret token is the one that starts at or after the cursor position. Uses >= so that when the cursor is exactly at a token boundary, we pick that

(tokens []pgparser.Token, byteOffset int)

Source from the content-addressed store, hash-verified

178// that token (not the one before it).
179// Returns len(tokens) if all tokens are before byteOffset.
180func findCaretTokenIndex(tokens []pgparser.Token, byteOffset int) int {
181 for i, tok := range tokens {
182 if tok.Loc >= byteOffset {
183 return i
184 }
185 }
186 return len(tokens)
187}
188
189func (c *Completer) completion() ([]base.Candidate, error) {
190 // Check if the caret token is quoted.

Callers 2

NewTrickyCompleterFunction · 0.70
NewStandardCompleterFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected