Repository navigation
feat(docs): runnable example REPL per stdlib entry - #94
Merged
Merged
Conversation
Deploying dang with
|
| Latest commit: |
fdcdb93
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://37050242.dang-3kk.pages.dev |
| Branch Preview URL: | https://docs-feedback-stdlib-example.dang-3kk.pages.dev |
Add an Example field to BuiltinDef and an .Example(code) builder method on the function, method, and static-method builders. The string is a tiny, self-contained snippet of Dang that exercises the builtin; the docs reference renders it as a pre-seeded, runnable REPL. Document the new field in the builtin-dsl skill, including the rule that every builtin must declare one and the backtick-escaping needed when an example contains a Dang regex literal. Signed-off-by: Alex Suraci <[email protected]>
Give every stdlib function, method, and static method an .Example(...): a one-line snippet a reader would actually type, evaluated in the core language so it runs in the browser REPL without GraphQL imports. Two tests in stdlib_examples_test.go keep these honest: one fails if any builtin lacks an example, the other parses, type-checks, and evaluates each example through the same path as the docs REPL, so a snippet can never drift from the implementation it documents. Signed-off-by: Alex Suraci <[email protected]>
Each generated stdlib card now carries its builtin's example beneath the signature and description, chroma-highlighted at build time so it reads as a normal code block and still works without JavaScript. The example is a lazy REPL: it stays a static snippet until the reader presses Run, at which point playground.js upgrades it in place into a live REPL seeded with the code and evaluates it once. Deferring keeps a page full of examples cheap — no textareas or wasm until something is actually run. highlightSignature becomes the more general highlightDang, now shared by the signature cards and the examples. Signed-off-by: Alex Suraci <[email protected]>
The stdlib example chrome already draws a border and rounded corners around each block, but the inner pre.dang-repl-fallback inherited its own border and border-radius from the general pre rule, doubling up the outline. Reset border and border-radius to none so the snippet relies on the surrounding chrome. Signed-off-by: Alex Suraci <[email protected]>
vito
force-pushed
the
docs-feedback-stdlib-example-repls
branch
from
June 5, 2026 15:59
0f0f1ce to
8d81fda
Compare
The lazy stdlib example REPLs evaluate their seed synchronously on Run, before loadTreeSitter() resolves, so the first transcript entry was rendered as plain text and never repainted — the example appeared to lose its syntax highlighting on Run. Re-highlight existing transcript entries (not just the live input) when tree-sitter finishes loading. Signed-off-by: Alex Suraci <[email protected]>
The stdlib reference is the one page with no eager REPL or playground, so its lazy examples are the first thing to load tree-sitter — and they build and run the seed synchronously on Run, before highlighting is ready, leaving the first transcript entry unpainted. Warm the shared highlighter when the reader hovers or focuses the Run button so it is ready by click time. The page stays lazy: nothing loads until the reader reaches for Run. Signed-off-by: Alex Suraci <[email protected]>
The input kept showing the submitted source for the whole duration of evaluation (while it read "Running…"), since it was only cleared in the loadDang().then callback. Clear it right after the source is captured and echoed into the transcript, so the prompt empties immediately on submit instead of after the eval returns. Signed-off-by: Alex Suraci <[email protected]>
The REPL input now keeps a per-session history of submitted sources. ArrowUp recalls older entries and ArrowDown walks back toward the live draft, which is preserved so it returns intact. Recall only triggers when the caret is on the first line (up) or last line (down), so multi-line editing still moves the caret normally. Reset clears the history. Signed-off-by: Alex Suraci <[email protected]>
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.
What
Docs feedback: "it would be great if each stdlib function had a runnable example."
This expands the Builtin DSL so each function/method can declare example usage, and uses that metadata to render a pre-seeded, runnable REPL for every entry on the stdlib reference page.
How
BuiltinDefgains anExamplefield and an.Example(code)builder on the function, method, and static-method builders."a,b,c".split(","),[1, 2, 3].map { x => x * 2 },Random.int(1, 7), …), written in the core language so it runs in the browser REPL.playground.jsupgrades it in place into a live REPL seeded with the code and evaluates it once (state then carries across entries, like the CLI). Deferring keeps a page full of examples cheap — no textareas or wasm until something is actually run, and it degrades to a plain code block without JavaScript.pkg/dang/stdlib_examples_test.gofails if any builtin lacks an example, and parses + type-checks + evaluates every example through the same path as the docs REPL, so a snippet can never drift from the implementation.The page stays scannable (signature + description + one tiny example), matching the section's
> Metaintent, rather than stacking ~56 always-on editors.Notes
go test ./pkg/dang/passes. The twotests/failures in this worktree (TestNeovimHighlights,TestZedHighlightQueryCompatibility) are pre-existing — they read untrackededitors/files absent here — and are unrelated to this change.