Skip to content

fix(editor): detect SQL clause at cursor so JOIN suggests tables (#1646)#1653

Merged
datlechin merged 2 commits into
mainfrom
fix/join-autocomplete-clause-detection
Jun 11, 2026
Merged

fix(editor): detect SQL clause at cursor so JOIN suggests tables (#1646)#1653
datlechin merged 2 commits into
mainfrom
fix/join-autocomplete-clause-detection

Conversation

@datlechin

Copy link
Copy Markdown
Member

Closes #1646.

Problem

In a multi-join query, triggering autocomplete after INNER JOIN suggested columns from the already-referenced tables instead of available table names.

Root cause

SQLContextAnalyzer.determineClauseType classified the cursor's clause by taking the first regex in a fixed-priority list whose greedy \bKEYWORD\s+[^;]*$ body reached the cursor. That returns the highest-priority keyword present anywhere in the statement, not the clause keyword nearest the cursor. Since .on is listed before the JOIN patterns, ... ON a = b INNER JOIN | matched the earlier ON and was classified as the ON clause, which only suggests columns. The same flaw misfired on SETWHERE, HAVINGORDER BY, and every multi-join chain.

Fix

  • Replaced the greedy linear-clause regexes with a nearest-clause-keyword backward scanner. It tokenizes the text before the cursor and walks back to the governing clause keyword, skipping closed parentheses, passing through an enclosing function or grouping paren, and tracking CASE … END. The structural and DDL regexes (parenthesis-bounded or statement-anchored) stay as a first pass.
  • Added expectsObjectName to SQLContext, set when the cursor is in the table-operand slot of FROM/JOIN/INTO, and used it so tables lead the list after a join instead of keywords burying them.
  • The ON clause now offers clause-transition keywords (the JOIN family, WHERE, GROUP BY, ORDER BY, ...), so typing the next INNER JOIN after a complete join condition surfaces it instead of fuzzy-matching columns.
  • Comma-separated FROM a, b, c now puts every table in scope for column completion.

No PluginKit or ABI impact; SQLContext is app-internal. The SQLSchemaProvider actor and its load-task invariant are untouched.

Tests

  • New SQLClauseDetectionTests covers the full matrix: linear clauses, nearest-clause-wins (the bug and its siblings), case-insensitivity, CASE … END, parentheses and subqueries, quoted identifiers, the operand slot, string and comment guards, multi-statement, and table extraction.
  • Extended SQLContextAnalyzerTests and SQLCompletionProviderTests: tables appear and rank first after JOIN, ON offers transition keywords, and a comma-separated FROM scopes real columns to every table.

Docs and changelog

  • docs/features/autocomplete.mdx: multi-join example and a note that the clause is detected at the cursor.
  • CHANGELOG entry under Unreleased.

@mintlify

mintlify Bot commented Jun 11, 2026

Copy link
Copy Markdown

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated (UTC)
TablePro 🟢 Ready View Preview Jun 11, 2026, 7:38 AM

💡 Tip: Enable Workflows to automatically generate PRs for you.

@datlechin datlechin merged commit 42ecf68 into main Jun 11, 2026
1 check passed
@datlechin datlechin deleted the fix/join-autocomplete-clause-detection branch June 11, 2026 07:45
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.

Autocomplete after INNER JOIN does not suggest available tables

1 participant