Apps

Schema Builder

# Schema — codebase type manager Schema indexes the `deftype` / `defunion` / `defprotocol` / `defimpl` declarations in your project and package roots, shows how each type is used, and edits type structure and field constraints in place. It is built from `deft/ui/components` with the composition helpers (`div`/`props`/`child`/`children`). The center canvas is a `surface` widget on GL hosts (retro/hydra); ANSI hosts show the same relations as a text outline. ## Launching ```sh retro app deft/schema-builder retra app deft/schema-builder ```` Or open it from a `.dft` buffer in the editor: hover a `deftype` / `defunion` line, then click the `◇` gutter icon. The editor opens Schema focused on that type (save the buffer first if it has unsaved edits). ## Layout - Header — Types/Protocols mode tabs, filter, stats, Reindex. - Sidebar — filtered list of types or protocols with field / protocol / usage counts and the defining file. - Canvas — `g` toggles overview/focus. Focus shows the selected type, its parent, children, field-type targets and attached protocol hubs. Drag to pan, wheel to zoom, `f` to fit. Click a field row to select it. - Inspector — Fields / Protocols / Usages / Source tabs. ## Indexing Roots are the project cwd plus every prelude `:pkgs` root outside the cwd (plus `:schema-builder/index-roots` from config). `.git`, `.zig-cache`, `zig-out`, `node_modules`, etc. are pruned. Indexing runs incrementally (60 files per tick) so the panel stays interactive; the status bar shows progress. Attached protocols include direct `defimpl`s and ones inherited from a parent. The protocol view lists every implementor, direct and inherited. ## Usages The Usages tab collects: - `%Type{…}` constructors - `^Type` parameter hints - field `:type` / `:of` references - child types inheriting from the type - `defimpl Type Protocol` attachments Enter (or the Open button) jumps to the reference in the editor. ## Editing The Fields tab edits the selected field: - `required`, `many`, `coerce` checkboxes - `type`, `of`, `default`, `min`, `max`, `pattern`, `one-of`, `validate`, `description` through the constraint list and input row - add / rename / delete fields - change or clear the type's parent (`<<`) Text edits are debounced and written through a source-span rewriter that touches only the affected key/value, preserving comments and unknown (including storage-specific) keys. The file is reparsed after each write. New types are inserted into the selected type's file. Schema refuses to write a file that has unsaved editor changes (`file` changed on disk` / `has unsaved edits`). Save the editor first.` ## Editor sync - Schema writes → publishes `"file-changed"` → clean editor buffers reload. - Editor saves → publishes `"file-changed"` → Schema refreshes the file. - The editor publishes `"editor-buffers"` (open files + dirty state), which Schema uses for its write guard. External reload drops the editor undo history for that file. ## Keys | Key | Action | |---|---| | `/` | focus the filter | | `Enter` | open the selected type / usage in the editor | | `a` | add a field | | `n` | new type (in the selected type's file) | | `p` | change parent | | `Delete` | delete the selected field | | `g` | toggle overview / focus | | `f` | fit graph | | `e` | open the selected type | | `Ctrl+R` | reindex | | `Ctrl+S` | flush a pending constraint write |