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

Function buildCompletionCatalog

backend/plugin/parser/trino/completion.go:68–102  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
68func 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

Callers 1

CompletionFunction · 0.70

Calls 2

catalogNeededFunction · 0.85
loadCatalogMetadataFunction · 0.85

Tested by

no test coverage detected