Skip to content

fix(editor): refresh autocomplete when switching schema#1547

Merged
datlechin merged 1 commit into
mainfrom
fix/autocomplete-schema-switch
Jun 1, 2026
Merged

fix(editor): refresh autocomplete when switching schema#1547
datlechin merged 1 commit into
mainfrom
fix/autocomplete-schema-switch

Conversation

@datlechin

Copy link
Copy Markdown
Member

Problem

After switching schema in the sidebar, the SQL editor's autocomplete kept suggesting tables and columns from the previous schema.

Root cause

DatabaseManager.switchSchema fires AppEvents.currentSchemaChanged. The only subscriber was SchemaService, which reloads its own @Observable table store, so the sidebar updated. But the autocomplete provider (SQLSchemaProvider) is refreshed only through MainContentCoordinator.reconcilePostSchemaLoad() -> provider.resetForDatabase(...), and that bridge is called only from refreshTables() and loadSchema(), never on a schema switch. So the shared provider stayed frozen on the old schema's tables and columnCache, and every editor tab kept serving stale completions. The same gap affected schema switches from the MCP/AI tools, not just the sidebar picker.

Fix

MainContentCoordinator now subscribes to currentSchemaChanged (filtered to its connection) and runs the existing refreshTables() path on a switch. That reloads the schema-scoped table list, resets the shared autocomplete provider (clears the stale column cache and restarts a schema-scoped eager column load through the metadata pool, which is already keyed on the current schema), and prunes stale sidebar selection state.

The table reload shares loadDedup (keyed on connection id) with SchemaService's own event-driven reload, so the two reloads triggered by the same event coalesce into a single fetchTables. Being reactive to the event, it also covers MCP/AI-driven switches.

Tests

This is MainActor + Combine + actor wiring (the existing reconcile path has no unit coverage either), so it's verified manually: connect to PostgreSQL, switch schema, confirm autocomplete lists the new schema's tables/columns rather than the previous one's.

@datlechin datlechin merged commit 127f1d4 into main Jun 1, 2026
3 checks passed
@datlechin datlechin deleted the fix/autocomplete-schema-switch branch June 1, 2026 16:24
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.

1 participant