Completion returns auto-completion candidates for a Trino statement at the given caret position. It is backed by the omni Trino completer (github.com/bytebase/omni/trino/completion), which tokenizes the input up to the caret, classifies the completion context, and produces candidates from a three-le
(ctx context.Context, cCtx base.CompletionContext, statement string, caretLine int, caretOffset int)
| 37 | // legacy completer's "every column in the default schema, ranked by priority". |
| 38 | // Those fields are therefore left empty here. |
| 39 | func Completion(ctx context.Context, cCtx base.CompletionContext, statement string, caretLine int, caretOffset int) ([]base.Candidate, error) { |
| 40 | cat := buildCompletionCatalog(ctx, cCtx, statement) |
| 41 | |
| 42 | byteOffset := caretToByteOffset(statement, caretLine, caretOffset) |
| 43 | cands := completion.Complete(statement, byteOffset, cat) |
| 44 | |
| 45 | result := make([]base.Candidate, 0, len(cands)) |
| 46 | for _, c := range cands { |
| 47 | result = append(result, base.Candidate{ |
| 48 | Text: c.Text, |
| 49 | Type: convertCandidateType(c.Type), |
| 50 | }) |
| 51 | } |
| 52 | return result, nil |
| 53 | } |
| 54 | |
| 55 | // buildCompletionCatalog constructs an omni Trino catalog from the completion |
| 56 | // context's metadata. Each bytebase database becomes a Trino catalog; its |