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

Method prefixToken

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

prefixToken returns the token immediately before (or containing) the cursor position when that token is an identifier-like token that the user is still typing. Returns false if no such token exists.

()

Source from the content-addressed store, hash-verified

236// position when that token is an identifier-like token that the user is still
237// typing. Returns false if no such token exists.
238func (c *Completer) prefixToken() (pgparser.Token, bool) {
239 // caretTokenIndex points to the first token at or past cursorByteOffset.
240 // The partial-prefix token is the one just before it (when the cursor is
241 // right after it) or the token itself (when the cursor is inside it).
242 idx := c.caretTokenIndex
243
244 // Check if the cursor is inside the token at caretTokenIndex.
245 if idx < len(c.tokens) {
246 tok := c.tokens[idx]
247 if tok.Loc < c.cursorByteOffset && c.cursorByteOffset <= tok.End && isIdentLikeToken(tok.Type) {
248 return tok, true
249 }
250 }
251
252 // Check the token before caretTokenIndex (cursor is right after it).
253 if idx > 0 {
254 tok := c.tokens[idx-1]
255 if tok.End == c.cursorByteOffset && isIdentLikeToken(tok.Type) {
256 return tok, true
257 }
258 }
259
260 return pgparser.Token{}, false
261}
262
263// isIdentLikeToken returns true for token types that represent identifiers or
264// unreserved keywords that a user might be partially typing.

Callers 1

completionMethod · 0.95

Calls 1

isIdentLikeTokenFunction · 0.85

Tested by

no test coverage detected