Skip to content

fix(editor): detect SQL clause from text before the token being typed#1660

Merged
datlechin merged 1 commit into
mainfrom
fix/completion-clause-prefix
Jun 12, 2026
Merged

fix(editor): detect SQL clause from text before the token being typed#1660
datlechin merged 1 commit into
mainfrom
fix/completion-clause-prefix

Conversation

@datlechin

Copy link
Copy Markdown
Member

What

Fixes the macOS Tests failures on main introduced by #1653 (red since 42ecf68): "SELECT keyword returns completions" and "Replacement range does not exceed text length".

Root cause

SQLContextAnalyzer ran clause detection on the text including the token under the cursor. With SELECT| the word SELECT is both the completion prefix and, to the analyzer, a committed clause keyword. The resolved clause became .select, whose candidate set (columns, functions) contains nothing matching the prefix "select", so the engine returned zero items and getCompletions returned nil. Same failure for ... WHERE|.

Fix

Clause detection now runs on the text before the prefix token (substring(to: prefixStart)). The token being typed stays what it is: the filter prefix. Typing SELE or a full SELECT keeps suggesting the SELECT keyword; positions with a trailing space (JOIN |, FROM users |) are unchanged, so the table suggestions #1653 added still work.

One test from #1653 placed the cursor touching the end of FROM| and asserted .from. Its intent (block comments do not break clause detection) is preserved by moving the cursor after the trailing space, where FROM is committed.

Testing

All five autocomplete suites pass locally (698 cases): CompletionEngineTests, CompletionEngineFilterTests, SQLClauseDetectionTests, SQLContextAnalyzerTests, SQLCompletionProviderTests. The three remaining local failures (testMySQLProviderTypes, testProviderAcceptsDatabaseType, testCommaFromScopesColumnsToAllTables) fail identically on clean main without this change; they need driver plugins present and pass on CI.

No CHANGELOG entry: this fixes behavior that is itself still unreleased (#1653).

@datlechin datlechin merged commit 6109cd7 into main Jun 12, 2026
4 checks passed
@datlechin datlechin deleted the fix/completion-clause-prefix branch June 12, 2026 03:39
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