Skip to content

feat(docs): auto-generate the stdlib reference - #93

Merged
vito merged 4 commits into
mainfrom
auto-generate-stdlib-docs
Jun 5, 2026
Merged

vito merged 4 commits into
mainfrom
auto-generate-stdlib-docs

Conversation

@vito

@vito vito commented Jun 5, 2026

Copy link
Copy Markdown
Owner

What

Auto-generates the /stdlib reference page from Dang's builtin registry instead of maintaining it by hand.

Why

Reader feedback on /stdlib: rather than hand-maintaining the reference (where signatures and one-line descriptions can silently drift from the real builtins), generate it by importing Dang's builtins and iterating over all of them with a Booklit helper — modeled on how vito/bass does it.

How

  • docs/go/stdlib.go — a new Booklit plugin exposing \stdlib-functions, \stdlib-methods{Type}, and \stdlib-statics{Module}. It introspects the registry (ForEachFunction, MethodReceivers/ForEachMethod, StaticModules/ForEachStaticMethod), rendering each entry's signature from its registered parameter/block/return types and its description from .Doc(...). Entries are alphabetized per group.
  • docs/lit/reference/stdlib.md — replaces the hand-written entry lists with helper calls, keeping the prose intros, conceptual cross-links, and the prelude-installed Error types (which aren't in the registry).
  • docs/go.mod — depends on the root module via a replace directive.
  • docs/build.sh — runs Booklit with CGO_ENABLED=0, so pkg/dang compiles pure-Go (its tree-sitter usage is gated behind //go:build cgo).

Editing a builtin's .Doc(...) now updates the page; there's nothing left to hand-maintain.

The stdlib reference page was maintained by hand, so its signatures and
descriptions could silently drift from the actual builtins. Generate it
instead by importing pkg/dang and iterating the builtin registry
(ForEachFunction, MethodReceivers/ForEachMethod, StaticModules), modeled
on how vito/bass builds its stdlib page.

A new Booklit plugin (docs/go/stdlib.go) exposes \stdlib-functions,
\stdlib-methods{Type}, and \stdlib-statics{Module}, which render each
entry's signature from its registered parameter, block, and return types
and its one-line description from .Doc(...). The page now carries only
the prose intros, cross-links, and the prelude-installed Error types,
which aren't in the registry.

The docs module gains a replace-directive dependency on the root module,
and build.sh runs Booklit with CGO_ENABLED=0 so pkg/dang compiles
pure-Go without pulling in tree-sitter.

Signed-off-by: Alex Suraci <[email protected]>
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jun 5, 2026 •

Copy link
Copy Markdown

vito added 3 commits June 5, 2026 01:09
The generated stdlib reference was a flat bulleted list, which is hard to
scan and impossible to link to a single entry. Render it like vito/bass's
stdlib page instead: each definition is now a card titled by its
signature and carrying an id anchor, so any entry is directly linkable,
and long groups (String, List) are preceded by a quick-scan name to
one-liner index.

The Booklit plugin emits stdlib-module/stdlib-entry/stdlib-index styled
content backed by new templates in docs/html, with matching CSS in
page.tmpl that reuses the site's existing color variables. Bass-isms
that don't apply to Dang — per-line source links and type predicates —
are intentionally left out.

Signed-off-by: Alex Suraci <[email protected]>
Two refinements to the generated stdlib reference. First, the signature
cards are now tree-sitter highlighted client-side, reusing the same
grammar and highlight query that power the playground and REPL editors,
so signatures are colored consistently with the rest of the site rather
than via a separate chroma path. To parse cleanly under the real grammar
the signatures now use Dang's actual return-type syntax (`name(args):
Ret`) instead of the invented `->` arrow.

Second, each entry is emitted as a booklit.Target carrying its signature
as the title and its description as the content, so the bindings land in
the search index as linkable anchors; the per-group index and each card's
self-link now resolve through booklit.Reference instead of hand-written
hrefs.

Signed-off-by: Alex Suraci <[email protected]>
Switch the stdlib signature highlighting from the client-side tree-sitter
pass back to build-time chroma, using the same "dang" lexer and style as
the rest of the site's code. The signatures are declaration-shaped and
not always complete Dang programs, which the tree-sitter parser choked
on; chroma's regex lexer tokenizes them gracefully and inlines both the
colors and the dark code background onto the <code>, so the result is
self-contained and needs no extra CSS or JS.

Also fully qualify each entry's search-index title with its receiver or
module, so a result reads "List.uniq: [a]!" instead of the bare
".uniq: [a]!" while the card and index still show the dotted call form.

Signed-off-by: Alex Suraci <[email protected]>
@vito
vito merged commit 8667c4f into main Jun 5, 2026
6 checks passed
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