buildCompletionCatalog constructs an omni Trino catalog from the completion context's metadata. Each bytebase database becomes a Trino catalog; its schemas, tables/views and columns are copied in. The session's current catalog/schema are set from the context defaults so unqualified names resolve the
(ctx context.Context, cCtx base.CompletionContext, statement string)
| 66 | // the LSP invokes completion on every keystroke, so eagerly loading all of them |
| 67 | // would fan out into hundreds of metadata fetches and stall completion. |
| 68 | func buildCompletionCatalog(ctx context.Context, cCtx base.CompletionContext, statement string) *catalog.Catalog { |
| 69 | if cCtx.Metadata == nil || cCtx.ListDatabaseNames == nil { |
| 70 | return nil |
| 71 | } |
| 72 | names, err := cCtx.ListDatabaseNames(ctx, cCtx.InstanceID) |
| 73 | if err != nil || len(names) == 0 { |
| 74 | return nil |
| 75 | } |
| 76 | |
| 77 | lowerStmt := strings.ToLower(statement) |
| 78 | defaultDB := catalog.Normalize(cCtx.DefaultDatabase) |
| 79 | |
| 80 | cat := catalog.New() |
| 81 | for _, dbName := range names { |
| 82 | norm := catalog.Normalize(dbName) |
| 83 | // Register the catalog name (cheap) so catalog-level completion lists it. |
| 84 | cat.EnsureCatalog(norm) |
| 85 | if !catalogNeeded(norm, defaultDB, lowerStmt) { |
| 86 | continue |
| 87 | } |
| 88 | _, meta, err := cCtx.Metadata(ctx, cCtx.InstanceID, dbName) |
| 89 | if err != nil || meta == nil { |
| 90 | continue |
| 91 | } |
| 92 | loadCatalogMetadata(cat, norm, meta) |
| 93 | } |
| 94 | |
| 95 | if cCtx.DefaultDatabase != "" { |
| 96 | cat.SetCurrentCatalog(catalog.Normalize(cCtx.DefaultDatabase)) |
| 97 | } |
| 98 | if cCtx.DefaultSchema != "" { |
| 99 | cat.SetCurrentSchema(catalog.Normalize(cCtx.DefaultSchema)) |
| 100 | } |
| 101 | return cat |
| 102 | } |
| 103 | |
| 104 | // loadCatalogMetadata copies one database's schemas, tables and views (with |
| 105 | // their column lists and view definitions) into the omni catalog under the |
no test coverage detected