Skip to content

feat(editor): complete database, schema, and table segments in qualified names#1581

Merged
datlechin merged 2 commits into
TableProApp:mainfrom
xantiagoma:feat/editor-qualified-autocomplete
Jun 4, 2026
Merged

feat(editor): complete database, schema, and table segments in qualified names#1581
datlechin merged 2 commits into
TableProApp:mainfrom
xantiagoma:feat/editor-qualified-autocomplete

Conversation

@xantiagoma
Copy link
Copy Markdown
Contributor

Summary

Improves SQL autocomplete for connections that organize objects as database → schema → table (BigQuery today, Snowflake with #1580):

  • For hierarchical-schema plugins the completion feed previously received an empty table list (SchemaService.runHierarchicalLoad publishes .loaded([]) and per-schema tables never reached SQLSchemaProvider); it now receives the union of all loaded per-schema tables plus schema and database names
  • Qualified names complete at every segment: ANALYTICS_PR → database, ANALYTICS_PROD. → schemas, ANALYTICS_PROD.DBT_MARTS. → tables — including schemas never expanded in the sidebar, fetched on demand through the metadata pool
  • Alias column completion respects schema-qualified tables: FROM db.schema.orders o WHERE o. previously fetched columns from the active schema and came back empty; TableReference now carries the schema segment end to end
  • The completion popup includes the active connection's dialect function list — previously dialect functions only fed syntax highlighting while the popup used a small generic set. This benefits every database plugin (e.g. SAFE_CAST on BigQuery, JSONB_AGG on PostgreSQL)

No behavior change for flat-schema connections beyond the dialect functions appearing in completions.

Testing

  • Live-verified against Snowflake and BigQuery-style hierarchical browsing: segment completion, on-demand schema tables, schema-qualified alias columns, dialect functions in the popup
  • All five autocomplete test suites pass in isolation (605 cases); the order-dependent failures of testProviderAcceptsDatabaseType / testMySQLProviderTypes when suites run together reproduce identically on main and predate this PR
  • swiftlint lint --strict clean on all changed files

Checklist

  • Tests updated
  • CHANGELOG.md updated under [Unreleased]
  • Docs updated (docs/features/autocomplete.mdx)
  • User-facing strings localized (n/a — no new UI strings)
  • No SwiftLint violations

Related: #1420, #1580

🤖 Generated with Claude Code

…ied names

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 4, 2026

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines 130 to +133
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
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Comment on lines +593 to +596
await provider.setNamespaces(
schemas: services.schemaService.schemas(for: connectionId),
databases: currentDb.map { [$0] } ?? []
)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

@xantiagoma
Copy link
Copy Markdown
Contributor Author

I have read the CLA Document and I hereby sign the CLA.

Copy link
Copy Markdown
Member

@datlechin datlechin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This look so good. Thank you

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines 136 to +140
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)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

@datlechin datlechin merged commit e48365f into TableProApp:main Jun 4, 2026
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants