Skip to content

fix(autocomplete): suggest clause keywords and correct columns after …#295

Open
thomaswasle wants to merge 1 commit into
TabularisDB:mainfrom
thomaswasle:bug/fix-broken-autocomplete-console
Open

fix(autocomplete): suggest clause keywords and correct columns after …#295
thomaswasle wants to merge 1 commit into
TabularisDB:mainfrom
thomaswasle:bug/fix-broken-autocomplete-console

Conversation

@thomaswasle
Copy link
Copy Markdown
Contributor

@thomaswasle thomaswasle commented Jun 6, 2026

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 === 0 guard so clause keywords (WHERE, ORDER BY,
    GROUP BY, LIMIT, …) are always included alongside column and table suggestions.

  • SQL keywords captured as table aliasesparseTablesFromQuery matched FROM users WHERE and registered WHERE as the alias, poisoning the alias map. Added a
    SQL_RESERVED set; any captured alias that is a reserved word is discarded and the
    table name is used as its own alias.

  • Wrong columns in MySQL multiDb mode — When activeSchema is null (multiDb),
    getTableColumns was called without a schema, causing MySQL to fall back to
    information_schema and return system columns instead of the user's table columns.
    Fixed by adding an optional schema?: string field to TableInfo and populating it
    with the source database name when building effectiveTables in multiDb mode. Both
    the 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

File Change
src/utils/autocomplete.ts Remove keyword gate; add schema-aware table lookup for dot-trigger; use t.schema in context-aware path; skip caching empty results
src/utils/sqlAnalysis.ts Add SQL_RESERVED set; filter captured aliases against it
src/contexts/DatabaseContext.ts Add optional schema?: string to TableInfo
src/pages/Editor.tsx Annotate each table with its source database when building effectiveTables in multiDb mode

Test plan

  • MySQL multiDb: type SELECT * FROM <table> → columns from the correct database
    appear
  • MySQL multiDb: type SELECT * FROM <table> WHERE → clause keywords (AND, OR,
    …) and column names both appear
  • Type SELECT * FROM <table> WHERE <partial> → matching column names filter
    correctly
  • Dot-trigger table. → columns from the correct per-database table appear
  • Single-database connections: keywords still appear; dot-trigger still works
  • Non-MySQL drivers: no regression in keyword or column suggestions

Comment thread src/utils/sqlAnalysis.ts Outdated
'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',
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

Suggested change
'asc', 'desc', 'null', 'with', 'exists', 'all', 'any',
'asc', 'desc', 'null', 'with', 'exists', 'all', 'any', 'using',

Comment thread src/utils/autocomplete.ts Outdated

if (actualTableName) {
const columns = await getTableColumns(connectionId, actualTableName, schema);
const foundTable = tables.find(t => t.name.toLowerCase() === typedName);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

Suggested change
const foundTable = tables.find(t => t.name.toLowerCase() === typedName);
const foundTable = tables.find(t => t.name.toLowerCase() === actualTableName.toLowerCase());

@kilo-code-bot
Copy link
Copy Markdown

kilo-code-bot Bot commented Jun 6, 2026

Code Review Summary

Status: No Issues Found | Recommendation: Merge

The previous issues have been resolved in the latest commit.

Resolved Issues (2)
Severity File Line Issue
CRITICAL src/utils/sqlAnalysis.ts 10 Missing 'using' in SQL_RESERVED set
WARNING src/utils/autocomplete.ts 157 Alias dot-trigger uses wrong schema lookup in multiDb mode
Files Reviewed (5 files)
  • src/utils/autocomplete.ts — no issues
  • src/utils/sqlAnalysis.ts — no issues
  • src/contexts/DatabaseContext.ts — no issues
  • src/pages/Editor.tsx — no issues
  • src-tauri/Cargo.lock — generated file, skipped

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
@thomaswasle thomaswasle force-pushed the bug/fix-broken-autocomplete-console branch from 78ac1e6 to c87419e Compare June 6, 2026 18:09
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.

[Bug]: No keyword autocomplete (WHERE / ORDER BY / ...) after SELECT * FROM <table>

1 participant