fix(datagrid): suggest columns at every clause position in raw SQL filter (#1346)#1384
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.
Fixes #1346.
Problem
In the raw SQL filter input, autocomplete only suggested a column for the leading token. After typing
AND(orOR), no column suggestions appeared for the next condition.Root cause
The raw SQL field is rendered by
FilterValueTextField, which matched the whole field string as one completion prefix and replaced the whole field on accept. That is correct for the per-column value field it was first built for, but wrong for a multi-token WHERE clause, so completion only ever worked on the first token.Approach
Drive the raw SQL field through the existing
CompletionEngineinstead of the field's hand-rolled whole-string matcher. A raw filter executes asSELECT ... FROM <table> WHERE (<rawSQL>), so the fix completes the actual query the filter denotes: it classifies the fragment as a WHERE clause and scopes columns to the current table. Token extraction, clause detection, string-literal suppression, ranking, and the replacement range all come from the engine. The custom suggestion dropdown is kept (consistent with the per-column value field).Changes
Engine (additive, the SQL editor's path is untouched):
CompletionEngine.filterCompletions(fragment:cursorPosition:tableName:)returns fragment-relative items and replacement range, with columns scoped to the table.forcedTableReferencesongetCompletions, andSQLContext.replacingTableReferences(_:).Filter:
RawSQLFilterCompletionProviderwraps the engine for the current connection and table.FilterValueTextFieldgainsFilterCompletionSource(.staticValuesfor the value field,.sqlTokensfor raw SQL). The token path runs the engine async (generation-guarded so stale or after-blur results can't reappear) and splices the chosen completion into just the current token's range, leaving the rest of the expression and the caret intact. The value field is unchanged.FilterRowView/FilterPanelViewwire the provider for the raw field, gated to SQL dialects and rebuilt when the table changes. NewMainContentCoordinator.currentTableName.Tests
CompletionEngineFilterTestscovers: columns after AND, replacement range covers the current token (the regression), columns at the first token, single-table scoping (no columns from other tables), logical keywords after a condition, and no completion inside a string literal.Docs
CHANGELOG entry under Unreleased; filtering docs note the autocomplete behavior.