Repository navigation
feat: SQL IntelliSense in SqlView + VS Code (#26) - #40
Merged
Merged
Conversation
Wire @codemirror/autocomplete to the existing flowscope `completionItems` WASM API so typing in an editable `SqlView` pops a context-aware suggestion list: dialect keywords, built-in functions, operators, and any table/CTE/ column names recovered from the current parse. Passes `encoding: 'utf16'` to the engine so CodeMirror character offsets cross the boundary without conversion. Adds `dialect`, `completionSchema`, and `disableCompletion` props to `SqlView` and plumbs the project dialect through from `EditorArea`. Ships reusable `createSqlCompletionSource` + `mapCompletionItem` helpers so a later VS Code `CompletionItemProvider` can consume the same mapping.
Register a `vscode.CompletionItemProvider` for `.sql` documents that forwards the cursor position to the flowscope `completion_items_json` WASM binding and maps each returned item to a VS Code completion (kind icons, detail text, replacement range, score-derived `sortText`). `flowscope.enableCompletion` (default true) lets users disable it. The provider shares semantics with the React-side helper (`.` trigger, UTF-16 cursor offsets, `shouldShow` short-circuit) so the two surfaces behave consistently.
Bind Tab to `acceptCompletion` alongside the default Enter binding. `acceptCompletion` returns false when no popup is open, so default Tab handling (indentation / focus traversal) stays intact outside an active completion session.
The previous Tab binding sat at default precedence, which put it after basicSetup's `indentWithTab` in the keymap chain. Since `indentMore` always returns true, Tab always indented and `acceptCompletion` never ran. Wrap the binding in `Prec.highest` so it's tried first. `acceptCompletion` still returns false when no popup is open, so indent behavior is preserved outside an active completion session.
- Clamp token spans to document length and only replace identifier/keyword tokens, so trigger punctuation (`.`, `(`, `,`) stays in place. - Honor VS Code's CancellationToken at entry, pre-WASM, and post-WASM. - Validate the `flowscope.dialect` setting against the Dialect union and fall back to `generic` with a warning on unknown values. - Sanitize completion error logs to emit only `error.message` (prefixed with `[FlowScope]`) and expose an optional `onCompletionError` on `SqlView` / `LineageExplorer` for hosts that want structured reporting. - Correct the misleading `triggerCharacters` comment and clarify `BOOST_SCALE`'s expected input/output range.
Treat completion results with an error field as failures instead of silent empty results. Report the error through the React completion hook and warn in the VS Code provider, with a regression test for the React source.
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.
Summary
Adds SQL IntelliSense to both the React
SqlView(CodeMirror 6) and the VS Code extension, backed by flowscope's existingcompletion_items_jsonWASM entry point. Typing in an editable SQL surface now surfaces dialect keywords, built-in functions, operators, and any table / CTE / column names recovered from the current parse.Closes #26.
What's in the box
React package —
packages/react/src/completion/sqlCompletionSource.ts—CompletionSourcefactory. Reads full document + UTF-16 cursor offset from theCompletionContext, callscompletionItems({ encoding: 'utf16', … }), maps the result to a CodeMirrorCompletionResultusing the engine's token span for the replace range andvalidFor: /^[\w$]*$/so CM filters locally while the user keeps typing the same identifier.mapCompletionItem.ts— pureCompletionItem → Completionmapper. Kind → CM type (table →class, column →property, …), score rescaled by 100 for CM'sboost,applypopulated only wheninsertTextdiverges fromlabel.onErrorcallback; the source never throws into CM.SqlView props
dialect?: Dialect,completionSchema?: SchemaMetadata,disableCompletion?: boolean.Prec.highest—acceptCompletionwins overbasicSetup'sindentWithTabwhen the popup is open and falls through to indent otherwise.App wiring
EditorAreapassescurrentProject.dialectthrough toSqlView.VS Code extension —
vscode/src/providers/completion.tsFlowScopeCompletionProviderimplementingvscode.CompletionItemProvider, registered forlanguage: 'sql'with.as an extra trigger character.document.offsetAt(position)for UTF-16 cursor offsets; sameencoding: 'utf16'pattern as the React side, so no byte conversion.vscode.CompletionItemKind(table →Struct, schemaTable →Module, column →Field, …). Enginescoreis inverted into a zero-paddedsortTextbucket so higher scores sort first.flowscope.enableCompletionsetting (default on).Types
CompletionRequest,CompletionItemsResult,CompletionItem,CompletionClause,CompletionToken, and related enums tovscode/src/types.tsto match@pondpilot/flowscope-core.What's intentionally not here
alias.columnsemantic resolver UI (IntelliSense: alias.column completion (semantic resolver) [epic] #27). The engine already populatescolumns_in_scope, so columns flow through naturally, but the dedicated dot-trigger UX designed in IntelliSense: alias.column completion (semantic resolver) [epic] #27 is still open.Test plan
yarn workspace @pondpilot/flowscope-react test— 182 passing (13 new: 6 formapCompletionItem, 7 forsqlCompletionSourcecovering UTF-16 offset forwarding, token → replace-range,shouldShowgating, default-dialect fallback, stale-request dropping, and error isolation).just typecheck— clean.just lint-ts— clean.WITH user_cohort AS (SELECT user_id FROM users) SELECT * FROM uin the demo app, confirmed popup surfacesuser_cohort,users,user_id, dialect keywords (UNION,USING,UNNEST,UPDATE), and matching functions.vscode/is thin so this wasn't automated).