Completion returns Redshift auto-completion candidates backed by omni's parser-native completer. Bytebase metadata is copied into an omni Redshift catalog with minimal DDL so the completer can resolve schemas, relations, columns, sequences, and Redshift-specific grammar slots.
(ctx context.Context, cCtx base.CompletionContext, statement string, caretLine int, caretOffset int)
| 24 | // catalog with minimal DDL so the completer can resolve schemas, relations, |
| 25 | // columns, sequences, and Redshift-specific grammar slots. |
| 26 | func Completion(ctx context.Context, cCtx base.CompletionContext, statement string, caretLine int, caretOffset int) ([]base.Candidate, error) { |
| 27 | cat := buildCompletionCatalog(ctx, cCtx) |
| 28 | |
| 29 | sql, line, offset := completionStatementAtCaret(statement, caretLine, caretOffset) |
| 30 | byteOffset := caretToByteOffset(sql, line, offset) |
| 31 | omniCandidates := redshiftcompletion.Complete(sql, byteOffset, cat) |
| 32 | |
| 33 | result := make([]base.Candidate, 0, len(omniCandidates)) |
| 34 | seen := make(map[string]bool, len(omniCandidates)) |
| 35 | for _, c := range omniCandidates { |
| 36 | candidate := base.Candidate{ |
| 37 | Text: completionCandidateText(c), |
| 38 | Type: convertCandidateType(c.Type), |
| 39 | Definition: c.Definition, |
| 40 | Comment: c.Comment, |
| 41 | } |
| 42 | key := candidate.String() |
| 43 | if seen[key] { |
| 44 | continue |
| 45 | } |
| 46 | seen[key] = true |
| 47 | result = append(result, candidate) |
| 48 | } |
| 49 | slices.SortFunc(result, func(a, b base.Candidate) int { |
| 50 | return strings.Compare(a.String(), b.String()) |
| 51 | }) |
| 52 | return result, nil |
| 53 | } |
| 54 | |
| 55 | // completionStatementAtCaret drops statements before the caret so table refs |
| 56 | // from earlier statements in the same editor buffer cannot leak into completion. |
nothing calls this directly
no test coverage detected