fix(autocomplete): suggest clause keywords and correct columns after …#295
fix(autocomplete): suggest clause keywords and correct columns after …#295thomaswasle wants to merge 1 commit into
Conversation
| 'except', 'select', 'from', 'into', 'values', 'update', 'delete', 'insert', | ||
| 'create', 'drop', 'alter', 'and', 'or', 'not', 'is', 'in', 'between', | ||
| 'like', 'as', 'distinct', 'case', 'when', 'then', 'else', 'end', 'by', | ||
| 'asc', 'desc', 'null', 'with', 'exists', 'all', 'any', |
There was a problem hiding this comment.
CRITICAL: Missing 'using' in SQL_RESERVED set
USING is a standard SQL keyword in JOIN ... USING(...) clauses. The fromPattern regex captures the word after a table name as a potential alias, so FROM a JOIN b USING(id) incorrectly registers using as the alias for b. This breaks dot-trigger autocomplete for that table.
| 'asc', 'desc', 'null', 'with', 'exists', 'all', 'any', | |
| 'asc', 'desc', 'null', 'with', 'exists', 'all', 'any', 'using', |
|
|
||
| if (actualTableName) { | ||
| const columns = await getTableColumns(connectionId, actualTableName, schema); | ||
| const foundTable = tables.find(t => t.name.toLowerCase() === typedName); |
There was a problem hiding this comment.
WARNING: Alias dot-trigger uses wrong schema lookup in multiDb mode
When typedName is an alias (e.g. u aliasing users), this looks up the table list by the alias instead of the resolved actualTableName. In multiDb mode foundTable will be undefined, so schema falls back to activeSchema (which is null), and MySQL receives no schema filter.
The context-aware path already looks up by actual table name — the dot-trigger path should do the same.
| const foundTable = tables.find(t => t.name.toLowerCase() === typedName); | |
| const foundTable = tables.find(t => t.name.toLowerCase() === actualTableName.toLowerCase()); |
Code Review SummaryStatus: No Issues Found | Recommendation: Merge The previous issues have been resolved in the latest commit. Resolved Issues (2)
Files Reviewed (5 files)
Reviewed by kimi-k2.6-20260420 · 273,521 tokens |
…WHERE
- Remove the `contextColumnSuggestions.length === 0` guard on keyword
suggestions so WHERE, ORDER BY, GROUP BY, LIMIT etc. are always offered
alongside column/table completions when a FROM clause is present
- Add SQL_RESERVED set to parseTablesFromQuery so keywords like WHERE/ON/
HAVING are never mistaken for table aliases, which was corrupting the
alias map and blocking column lookups
- Tag each TableInfo with its source database in multiDb mode (Editor.tsx)
and use t.schema ?? schema in getTableColumns calls so MySQL multiDb
connections pass the correct schema rather than falling back to
information_schema
- Fall back to a synthetic {name} entry when the loaded tables list is
empty so column fetches are still attempted before the first tables
payload arrives
- Skip caching empty column results to avoid poisoning the cache with
transient empty responses caused by schema mismatches or a not-yet-ready
connection
78ac1e6 to
c87419e
Compare
closes #293.
Summary
Keywords never suggested after FROM clause — The completion provider only
offered keyword completions when no context columns were available. Removed the
contextColumnSuggestions.length === 0guard so clause keywords (WHERE, ORDER BY,GROUP BY, LIMIT, …) are always included alongside column and table suggestions.
SQL keywords captured as table aliases —
parseTablesFromQuerymatchedFROM users WHEREand registeredWHEREas the alias, poisoning the alias map. Added aSQL_RESERVEDset; any captured alias that is a reserved word is discarded and thetable name is used as its own alias.
Wrong columns in MySQL multiDb mode — When
activeSchemais null (multiDb),getTableColumnswas called without a schema, causing MySQL to fall back toinformation_schemaand return system columns instead of the user's table columns.Fixed by adding an optional
schema?: stringfield toTableInfoand populating itwith the source database name when building
effectiveTablesin multiDb mode. Boththe context-aware and dot-trigger paths now pass
t.schema ?? schema.Column cache poisoning — The fallback that attempts column fetches before the
tables list loads could receive an empty response (schema mismatch / connection not
yet ready) and cache it, blocking all subsequent fetches for that table. Empty results
are now never written to the cache.
Files changed
src/utils/autocomplete.tst.schemain context-aware path; skip caching empty resultssrc/utils/sqlAnalysis.tsSQL_RESERVEDset; filter captured aliases against itsrc/contexts/DatabaseContext.tsschema?: stringtoTableInfosrc/pages/Editor.tsxeffectiveTablesin multiDb modeTest plan
SELECT * FROM <table>→ columns from the correct databaseappear
SELECT * FROM <table> WHERE→ clause keywords (AND, OR,…) and column names both appear
SELECT * FROM <table> WHERE <partial>→ matching column names filtercorrectly
table.→ columns from the correct per-database table appear