buildCatalog creates an omni catalog from Bytebase completion context.
(ctx context.Context, cCtx base.CompletionContext)
| 71 | |
| 72 | // buildCatalog creates an omni catalog from Bytebase completion context. |
| 73 | func buildCatalog(ctx context.Context, cCtx base.CompletionContext) *catalog.Catalog { |
| 74 | cat := catalog.New() |
| 75 | |
| 76 | if cCtx.DefaultDatabase == "" || cCtx.Metadata == nil { |
| 77 | return cat |
| 78 | } |
| 79 | |
| 80 | _, metadata, err := cCtx.Metadata(ctx, cCtx.InstanceID, cCtx.DefaultDatabase) |
| 81 | if err != nil || metadata == nil { |
| 82 | return cat |
| 83 | } |
| 84 | |
| 85 | for _, schema := range metadata.ListSchemaNames() { |
| 86 | schemaMeta := metadata.GetSchemaMetadata(schema) |
| 87 | if schemaMeta == nil { |
| 88 | continue |
| 89 | } |
| 90 | for _, table := range schemaMeta.ListTableNames() { |
| 91 | cat.AddCollection(table) |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | return cat |
| 96 | } |
| 97 | |
| 98 | // caretToByteOffset converts a 1-based line and 0-based column offset to a byte offset. |
| 99 | // Note: caretOffset is treated as a rune (code point) offset, not UTF-16 code units. |
no test coverage detected