feat(editor): complete database, schema, and table segments in qualified names#1581
Conversation
…ied names Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
All contributors have signed the CLA ✍️ ✅ |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f6feb14f0e
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if let tableName = await schemaProvider.resolveAlias(dotPrefix, in: context.tableReferences) { | ||
| items = await schemaProvider.columnCompletionItems(for: tableName) | ||
| let schema = context.tableReferences.first { | ||
| $0.tableName.caseInsensitiveCompare(tableName) == .orderedSame | ||
| }?.schema |
There was a problem hiding this comment.
Preserve the matched alias's schema
When two schemas contain the same table name and both are referenced with aliases (for example FROM s1.users u1 JOIN s2.users u2 ... WHERE u2.|), resolveAlias("u2") returns only "users", and this lookup then takes the schema from the first users reference. That makes completions for u2. fetch s1.users columns instead of s2.users, so schema-qualified alias columns are wrong in this common duplicate-table-name case; the resolution needs to keep the matched TableReference (or at least its schema) rather than re-finding by table name.
Useful? React with 👍 / 👎.
| await provider.setNamespaces( | ||
| schemas: services.schemaService.schemas(for: connectionId), | ||
| databases: currentDb.map { [$0] } ?? [] | ||
| ) |
There was a problem hiding this comment.
Pass all loaded database names to autocomplete
This only registers the current active database as a known database, even though loadSchema() has just loaded the full database list via DatabaseTreeMetadataService. In connections with multiple databases, SELECT * FROM OTHER_| cannot suggest any non-active database names, so the new database-segment completion advertised for Snowflake/BigQuery is limited to one database; use the loaded database metadata here instead of currentDb.map { [$0] }.
Useful? React with 👍 / 👎.
|
I have read the CLA Document and I hereby sign the CLA. |
…ame autocomplete with tests
datlechin
left a comment
There was a problem hiding this comment.
This look so good. Thank you
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f694518a7c
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if let tableName = await schemaProvider.resolveAlias(dotPrefix, in: context.tableReferences) { | ||
| items = await schemaProvider.columnCompletionItems(for: tableName) | ||
| let schema = context.tableReferences.first { | ||
| $0.tableName.caseInsensitiveCompare(tableName) == .orderedSame | ||
| }?.schema | ||
| items = await schemaProvider.columnCompletionItems(for: tableName, schema: schema) |
There was a problem hiding this comment.
Prefer schemas over tables in qualified FROM completions
When the schema segment also matches a loaded table name, typing a qualified table name such as FROM sales.| resolves sales through resolveAlias first and returns columns for the sales table instead of tables in the sales schema. This makes the new schema-segment completion fail for common names like sales/analytics whenever a table with the same name has cached/fetchable columns; in namespace contexts the known schema/database branch needs to win before falling back to table/alias column completion.
Useful? React with 👍 / 👎.
Summary
Improves SQL autocomplete for connections that organize objects as database → schema → table (BigQuery today, Snowflake with #1580):
SchemaService.runHierarchicalLoadpublishes.loaded([])and per-schema tables never reachedSQLSchemaProvider); it now receives the union of all loaded per-schema tables plus schema and database namesANALYTICS_PR→ database,ANALYTICS_PROD.→ schemas,ANALYTICS_PROD.DBT_MARTS.→ tables — including schemas never expanded in the sidebar, fetched on demand through the metadata poolFROM db.schema.orders o WHERE o.previously fetched columns from the active schema and came back empty;TableReferencenow carries the schema segment end to endSAFE_CASTon BigQuery,JSONB_AGGon PostgreSQL)No behavior change for flat-schema connections beyond the dialect functions appearing in completions.
Testing
testProviderAcceptsDatabaseType/testMySQLProviderTypeswhen suites run together reproduce identically onmainand predate this PRswiftlint lint --strictclean on all changed filesChecklist
CHANGELOG.mdupdated under[Unreleased]docs/features/autocomplete.mdx)Related: #1420, #1580
🤖 Generated with Claude Code