Skip to content

feat: sqlCompletion helper to register all completion sources at once#167

Merged
mscolnick merged 1 commit into
mainfrom
ms/completion-register-helper
Jul 23, 2026
Merged

feat: sqlCompletion helper to register all completion sources at once#167
mscolnick merged 1 commit into
mainfrom
ms/completion-register-helper

Conversation

@mscolnick

@mscolnick mscolnick commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

What

Registering the SQL completion sources had gotten unwieldy — each of the three schema-aware sources required its own dialect.language.data.of({ autocomplete }) call:

dialect.language.data.of({ autocomplete: createCteCompletionSource({ parser }) }),
dialect.language.data.of({ autocomplete: aliasColumnCompletionSource({ schema, parser, contextAnalyzer }) }),
dialect.language.data.of({ autocomplete: unqualifiedColumnCompletionSource({ schema, parser, contextAnalyzer }) }),

This PR adds a convenience helper that does it in one call:

sqlCompletion({ dialect, schema, parser, contextAnalyzer }),

Details

  • New sqlCompletion(config) (src/sql/completion-extension.ts) registers all three completion sources:
    • createCteCompletionSource — CTE names + their output columns
    • aliasColumnCompletionSourceu. → columns of users
    • unqualifiedColumnCompletionSourceSELECT eemail from FROM/JOIN tables
  • Shares a single parser and query-context analyzer across the sources so each edit is analyzed once.
  • Per-source toggles (enableCteCompletion / enableAliasCompletion / enableColumnCompletion, all default true), mirroring the enable* pattern in sqlExtension.
  • Exported from src/index.ts (sqlCompletion, SqlCompletionConfig).
  • Demo updated to use the helper.

It's a separate helper from sqlExtension because completion sources must be registered against a specific dialect's language, which sqlExtension doesn't take.

Testing

  • New src/sql/__tests__/completion-extension.test.ts verifies the helper registers all three sources by default and honors the enable/disable toggles.
  • Updated the exports snapshot in src/__tests__/index.test.ts.
  • pnpm run typecheck, pnpm exec oxlint, tests, and pnpm run demo build all pass.

Summary by cubic

Introduce sqlCompletion({ dialect, schema, parser, contextAnalyzer }) to register CTE, alias-qualified, and unqualified column completions with one call. This reduces setup to a single extension and reuses one parser/context analyzer for better performance.

  • New Features
    • Added sqlCompletion(config) to register createCteCompletionSource, aliasColumnCompletionSource, and unqualifiedColumnCompletionSource against the provided dialect.
    • Shares a single parser and QueryContextAnalyzer; supports enableCteCompletion, enableAliasCompletion, and enableColumnCompletion toggles (default true).
    • Exported sqlCompletion and SqlCompletionConfig; updated demo to use the helper; added tests to verify defaults and toggles.

Written for commit c67e464. Summary will update on new commits.

Review in cubic

Registering the CTE, alias-qualified, and unqualified column completion
sources required three separate dialect.language.data.of({ autocomplete })
calls. Add a sqlCompletion({ dialect, schema, parser, contextAnalyzer })
helper that wires up all three, sharing a single parser and query-context
analyzer, with per-source enable toggles. Update the demo to use it.
Copilot AI review requested due to automatic review settings July 23, 2026 18:37

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions

github-actions Bot commented Jul 23, 2026

Copy link
Copy Markdown

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 90.97% 1663 / 1828
🔵 Statements 91.12% 1736 / 1905
🔵 Functions 94.71% 233 / 246
🔵 Branches 82.71% 1302 / 1574
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
src/index.ts 0% 0% 0% 0%
src/sql/completion-extension.ts 100% 100% 100% 100%
Generated in workflow #655 for commit 68ecb20 by the Vitest Coverage Report Action

@mscolnick
mscolnick merged commit 68ecb20 into main Jul 23, 2026
6 checks passed
@mscolnick
mscolnick deleted the ms/completion-register-helper branch July 23, 2026 18: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.

2 participants