Skip to content

Commit e052af6

Browse files
authored
feat(vnext): add disposable completion info (#200)
## 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. -->
1 parent 246fa6f commit e052af6

5 files changed

Lines changed: 504 additions & 6 deletions

File tree

docs/vnext/codemirror-adapter.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,29 @@ The adapter installs one coherent `autocompletion` configuration. Additional
4747
sources belong in `autocomplete.externalSources`; consumers should not install
4848
a second independently configured `autocompletion` extension.
4949

50+
Rich completion details are opt-in through
51+
`autocomplete.infoResolver`. The resolver receives the immutable core item and
52+
an `AbortSignal`, and returns a DOM resource with an explicit `destroy`
53+
callback. The adapter aborts pending work and destroys resolved resources when
54+
the selected option, document input, context, regions, or view lifetime
55+
changes. Resolver failures are contained and simply omit the detail panel.
56+
57+
```ts
58+
const support = sqlEditor({
59+
autocomplete: {
60+
infoResolver: async (item, { signal }) => {
61+
const metadata = await loadMetadata(item, { signal });
62+
const dom = document.createElement("div");
63+
const root = createRoot(dom);
64+
root.render(renderMetadata(metadata));
65+
return { dom, destroy: () => root.unmount() };
66+
},
67+
},
68+
initialContext,
69+
service,
70+
});
71+
```
72+
5073
## Atomic inputs
5174

5275
Context and document changes can share one CodeMirror transaction:

0 commit comments

Comments
 (0)