fix(editor): refresh autocomplete when switching schema#1547
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
After switching schema in the sidebar, the SQL editor's autocomplete kept suggesting tables and columns from the previous schema.
Root cause
DatabaseManager.switchSchemafiresAppEvents.currentSchemaChanged. The only subscriber wasSchemaService, which reloads its own@Observabletable store, so the sidebar updated. But the autocomplete provider (SQLSchemaProvider) is refreshed only throughMainContentCoordinator.reconcilePostSchemaLoad()->provider.resetForDatabase(...), and that bridge is called only fromrefreshTables()andloadSchema(), never on a schema switch. So the shared provider stayed frozen on the old schema'stablesandcolumnCache, 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
MainContentCoordinatornow subscribes tocurrentSchemaChanged(filtered to its connection) and runs the existingrefreshTables()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) withSchemaService's own event-driven reload, so the two reloads triggered by the same event coalesce into a singlefetchTables. 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.