CodeMirror: upgrade to latest 6.x, full schema autocomplete, embeddable <datasette-sql-editor>#2833
Draft
asg017 wants to merge 11 commits into
Draft
CodeMirror: upgrade to latest 6.x, full schema autocomplete, embeddable <datasette-sql-editor>#2833asg017 wants to merge 11 commits into
asg017 wants to merge 11 commits into
Conversation
codemirror 6.0.1 -> 6.0.2, @codemirror/lang-sql 6.3.3 -> 6.10.0 (autocomplete 6.20.3, view 6.43.6, state 6.7.1). defaultTableName/defaultSchemaName were never valid SQLConfig options; the real names are defaultTable/defaultSchema. Also enables caseInsensitiveIdentifiers on the SQLite dialect. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
cm-editor-6.0.1.{js,bundle.js} -> cm-editor.{js,bundle.js}; new
npm run build:codemirror replaces the documented rollup one-liner.
Cache busting already handled by the static() template helper's
?_hash= content hash.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
_editor_schema() emits lang-sql Completion objects (column type as detail, boost above keywords) and gives views their real columns via PRAGMA table_xinfo in a self/children container labelled 'view'. _table_columns() is unchanged for the write-template path. Note the table_columns field in the database JSON context now carries this richer shape. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Per-view Compartment wraps the sql() extension; window.editor.updateSchema(
{schema, defaultTable, defaultSchema}) reconfigures autocomplete live.
Declares @codemirror/state as a direct dependency since it is now
imported directly.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Neutral {database, tables: [{name, view, columns: [{name, type}]}]}
shape, gated on view-database + execute-sql with no table-name leak on
403, hidden tables excluded. /-/schema.json was already taken by the
DDL endpoint, hence editor-schema.json. _editor_schema() now maps from
the shared _schema_tables() introspection helper.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The table page's 'View and edit SQL' link now carries ?_table=<name>; QueryView validates it against the actor-visible tables/views for the database before exposing it as default_table, so the editor completes that table's columns unprefixed. Stored/canned queries are unaffected. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Follow-up to d12f0d2: the test regexes the inlined schema= JS and still asserted the old flat list-of-strings shape. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Single source of truth for the CodeMirror setup: SQLiteDialect, createSqlEditor() (delegable history with host undo/redo forwarding, hostChange annotation for echo suppression, submit/escape callbacks, fixed-tooltip mode, per-editor Compartment updateSchema), and datasetteSchema() which fetches /-/editor-schema.json and maps it to a lang-sql SQLNamespace identical to the server-inlined shape. cm-editor.js is now a thin consumer; rollup emits both the IIFE and an importable ESM bundle. Submit key is Mod-Enter (Cmd on mac as before, now also Ctrl elsewhere) plus Shift-Enter. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Light-DOM element built on createSqlEditor(): form participation via
ElementInternals (name= field, reset support), schema fetched from
{base-url}/{database}/-/editor-schema.json or schema-url= without ever
blocking editing, cancelable submit event on Mod/Shift-Enter driving
form.requestSubmit(), readOnly/value/schema/view properties, format()
via the sql-formatter global, theming through CSS custom properties
with appearance-preserving fallbacks. Auto-registers the tag on import
(guarded). Manual-QA page at demos/sql-editor-element.html.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The five SQL pages now render the element wrapping a plain <textarea name=sql> fallback that keeps working without JavaScript (the element adopts and removes it on mount). The element also gained a parser-timing guard: when its definition loads from <head> the browser connects it at the start tag before its children are parsed, so mounting defers to DOMContentLoaded in that case. window.editor back-compat preserved; cm global deprecation deferred. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #2833 +/- ##
=====================================
Coverage 0.00% 0.00%
=====================================
Files 73 73
Lines 12208 12262 +54
=====================================
- Misses 12208 12262 +54 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This was referenced Jul 10, 2026
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.
Note
This PR is the integration view of the whole branch. For review, the work is split into a stack of four PRs: #2834 (upgrade + build) -> #2835 (schema autocomplete + endpoint) -> #2836 (ESM primitives) -> #2837 (element + core-page dogfood). Review those; this one tracks the combined branch and interactive QA.
Modernizes Datasette's CodeMirror SQL editor across three workstreams. Draft while interactive QA and the docs ticket finish; may be split into a PR stack (see checklist at bottom).
1. Upgrade to current CodeMirror 6.x
codemirror6.0.1 → 6.0.2,@codemirror/lang-sql6.3.3 → 6.10.0 (autocomplete 6.20.3, view 6.43.6, state 6.7.1) — all semver-compatible, no CM7 existssql()was called withdefaultTableName/defaultSchemaName, which were never valid lang-sql options (real names:defaultTable/defaultSchema)caseInsensitiveIdentifiers: trueon the curated SQLite dialect (stops auto-quoting mixed-case identifiers)cm-editor.bundle.js),rollup.config.mjs+npm run build:codemirrorreplacing the documented one-liner; cache busting already handled bystatic()'s?_hash=2. Full schema autocomplete
detail), rank columns above keywords (boost), distinguish views and give them their real columns viaPRAGMA table_xinfo(previously empty)?_table=so that table's columns complete unprefixed (defaultTable)GET /{database}/-/editor-schema.jsonendpoint: neutral{database, tables: [{name, view, columns: [{name, type}]}]}shape, gated onview-database+execute-sql, hidden tables excluded, 403 leaks no table names. (Namededitor-schema.jsonbecause/-/schema.jsonis the existing DDL endpoint.)window.editor.updateSchema({schema, defaultTable})reconfigures autocomplete live via a Compartment3. Embeddable editor for plugins
datasette/static/datasette-sql-editor.js— ESM primitives module (also built to an importabledatasette-sql-editor.bundle.js):createSqlEditor()with delegable history (host undo/redo for ProseMirror/collab hosts like datasette-paper),hostChangeannotation for echo suppression, submit/escape callbacks, fixed-tooltip mode;datasetteSchema()fetches the new endpoint and maps it identically to the server-inlined shape; CM modules re-exported so plugins share one CodeMirror instance per page<datasette-sql-editor>— form-associated, light-DOM custom element:name/database/schema-url/default-table/readonlyattributes,value/schema/view/readOnlyproperties,format(), cancelablesubmitevent drivingform.requestSubmit(), CSS-custom-property theming, never blocks editing on schema-fetch failure<textarea name=sql>fallback that keeps working with JS disabled (adopted + removed on mount). Includes a parser-timing guard (definition loading from<head>connects the element before its children parse).window.editorback-compat preserved;cmglobal left in place (deprecation is a separate decision)demos/sql-editor-element.html(uv run datasette fixtures.db --static demos:demos/)Testing
_table=validation, migrated markup)?_hash=, endpoint payloads; element behavior (window.editor, form value, fallback adoption, parser-timing) verified in headless ChromeRemaining before ready-for-review
🤖 Generated with Claude Code