Skip to content

fix(datagrid): suggest columns at every clause position in raw SQL filter (#1346)#1384

Merged
datlechin merged 2 commits into
mainfrom
fix/1346-raw-sql-filter-completion
May 22, 2026
Merged

fix(datagrid): suggest columns at every clause position in raw SQL filter (#1346)#1384
datlechin merged 2 commits into
mainfrom
fix/1346-raw-sql-filter-completion

Conversation

@datlechin
Copy link
Copy Markdown
Member

Fixes #1346.

Problem

In the raw SQL filter input, autocomplete only suggested a column for the leading token. After typing AND (or OR), 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 CompletionEngine instead of the field's hand-rolled whole-string matcher. A raw filter executes as SELECT ... 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.
  • Optional forcedTableReferences on getCompletions, and SQLContext.replacingTableReferences(_:).

Filter:

  • RawSQLFilterCompletionProvider wraps the engine for the current connection and table.
  • FilterValueTextField gains FilterCompletionSource (.staticValues for the value field, .sqlTokens for 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 / FilterPanelView wire the provider for the raw field, gated to SQL dialects and rebuilt when the table changes. New MainContentCoordinator.currentTableName.

Tests

CompletionEngineFilterTests covers: 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.

@datlechin datlechin merged commit 6bdef58 into main May 22, 2026
2 checks passed
@datlechin datlechin deleted the fix/1346-raw-sql-filter-completion branch May 22, 2026 13:11
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.

Raw SQL filter only suggests the first column, no completion after AND

1 participant