fix(editor): detect SQL clause from text before the token being typed#1660
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.
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
SQLContextAnalyzerran clause detection on the text including the token under the cursor. WithSELECT|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 andgetCompletionsreturned 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. TypingSELEor a fullSELECTkeeps 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).