Skip to content

feat(vnext): add CodeMirror completion adapter#199

Merged
Light2Dark merged 1 commit into
dev-refactorfrom
codex/vnext-codemirror-adapter
Jul 25, 2026
Merged

feat(vnext): add CodeMirror completion adapter#199
Light2Dark merged 1 commit into
dev-refactorfrom
codex/vnext-codemirror-adapter

Conversation

@Light2Dark

@Light2Dark Light2Dark commented Jul 25, 2026

Copy link
Copy Markdown
Member

Summary

  • add an explicit @marimo-team/codemirror-sql/vnext/codemirror entry point with one caller-owned service and one session per EditorView
  • translate composite CodeMirror document, context, and embedded-region effects into one atomic session update
  • map current relation results to exact CodeMirror edits with revision, document, selection, context, and embedded-region guards
  • coalesce exact-token catalog refreshes across active menus and empty loading results without synchronous provider-driven dispatch
  • contain Escape, close, blur, visibility, expiry, service-first disposal, stale rejection, and repeated teardown races

Why

The framework-independent service now has the identity and lease contracts needed for a thin editor boundary. This adapter makes those contracts usable without leaking CodeMirror into the core, while preserving marimo's external completion sources and treating transformed-document regions explicitly rather than guessing their mapping.

Validation

  • 2,028 tests pass; 1 intentional expected failure
  • adapter coverage: 97.70% statements, 95.86% branches, 100% functions, 99.01% lines
  • all strict and loose-optional TypeScript configurations pass
  • oxlint and test-integrity checks pass
  • packed-consumer source covers the new package subpath; hosted package CI will run the isolated install
  • two independent exact-commit adversarial reviews approved 8d72a4c

Summary by cubic

Adds a CodeMirror 6 adapter for the vNext SQL language service, exposed as @marimo-team/codemirror-sql/vnext/codemirror. This enables exact, guarded completion edits and atomic document/context/region updates without leaking CodeMirror into the core.

  • New Features

    • New sqlEditor adapter with one document session per EditorView; caller owns the shared service.
    • Atomic updates: merges document changes with support.contextEffect and support.embeddedRegionsEffect.
    • Exact completion edits with revision/context/selection guards; maps unrelated embedded regions through its own edit; ignores overlaps.
    • Coalesced refresh intents keyed by service tokens; cancels on Escape, blur (configurable), visibility loss, selection change, or lease expiry; no synchronous provider-driven dispatch.
    • Single autocompletion configuration; supports externalSources for extra providers.
    • New docs: docs/vnext/codemirror-adapter.md; subpath export added in package.json; smoke test updated.
  • Migration

    • Import from @marimo-team/codemirror-sql/vnext/codemirror, create a service from @marimo-team/codemirror-sql/vnext, then add support.extension to the editor.
    • Do not install a second autocompletion extension; pass extra providers via externalSources.
    • Update context/regions via support.setContext or by dispatching support.contextEffect and support.embeddedRegionsEffect. If embedded regions exist, include the complete resulting set on every document-changing transaction.

Written for commit 8d72a4c. Summary will update on new commits.

Review in cubic

@github-actions

Copy link
Copy Markdown

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 99.01% (🎯 91%) 202 / 204
🔵 Statements 97.7% (🎯 91%) 213 / 218
🔵 Functions 100% (🎯 90%) 42 / 42
🔵 Branches 95.86% (🎯 85%) 139 / 145
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
src/vnext/codemirror/index.ts 0% 0% 0% 0%
src/vnext/codemirror/sql-editor.ts 97.7% 95.86% 100% 99.01% 187, 325, 391, 442, 446
Generated in workflow #758 for commit 8d72a4c by the Vitest Coverage Report Action

@Light2Dark
Light2Dark marked this pull request as ready for review July 25, 2026 17:28
@Light2Dark
Light2Dark merged commit 246fa6f into dev-refactor Jul 25, 2026
8 checks passed
@Light2Dark
Light2Dark deleted the codex/vnext-codemirror-adapter branch July 25, 2026 17:28
Light2Dark added a commit that referenced this pull request Jul 25, 2026
## Summary

- expose an opt-in, type-safe completion info resolver on the vNext
CodeMirror adapter
- give every resolver an AbortSignal and require explicit DOM resource
cleanup
- abort pending work and destroy resolved UI on option, document,
context, region, or view changes
- contain resolver/cleanup failures and reject cleanup reentrancy
- document the React-root integration pattern and export the public
resolver types

## Verification

- 43 test files; 2,036 passed and 1 expected failure
- changed coverage: 98.15% statements, 95.90% branches, 100% functions,
99.20% lines
- all strict/loose/demo TypeScript configurations pass
- oxlint and test-integrity checks pass
- build and runtime export smoke pass
- two independent exact-head adversarial reviews approve
`e07f8e525d6e6f2c7f73e24acd4e1f0b1ff90cc0`

Stacked on #199, now merged into `dev-refactor`.

<!-- This is an auto-generated description by cubic. -->
---
## Summary by cubic
Adds opt-in rich completion info to the vNext CodeMirror adapter.
Introduces a type-safe `infoResolver` that returns a disposable DOM
panel, with automatic abort and cleanup on selection or editor changes.

- **New Features**
- `autocomplete.infoResolver(item, { signal })` lets you render rich
info and return `{ dom, destroy }`; pending work is aborted and resolved
resources are destroyed on option selection changes,
document/context/region updates, or view disposal.
- Stale results are ignored; null results omit the panel; resolver and
cleanup failures are contained; reentrancy during cleanup is rejected.
- Docs updated with a React root example; exported
`SqlCompletionInfoResolver`, `SqlCompletionInfoResolverContext`, and
`SqlDisposableCompletionInfo` from `src/vnext/codemirror/index.ts`.

- **Migration**
  - Opt in by passing `sqlEditor({ autocomplete: { infoResolver } })`.
- Your resolver should use the provided `AbortSignal` and return `{ dom,
destroy }` or `null`.

<sup>Written for commit e07f8e5.
Summary will update on new commits.</sup>

<a
href="https://cubic.dev/pr/marimo-team/codemirror-sql/pull/200?utm_source=github"
target="_blank" rel="noopener noreferrer"
data-no-image-dialog="true"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img
alt="Review in cubic"
src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a>

<!-- End of auto-generated description by cubic. -->
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.

1 participant