ludic/tools/docgen/check.py
Orkuncakilkaya 3c7ec9b016
All checks were successful
docs / build-and-deploy (push) Successful in 2s
docs(api): per-symbol pages, fuzzy search, deep token linking, hover cards
Rebuild the API Reference around one page per symbol and richer, verified content.

Pages & navigation
- One HTML page per symbol (kw-*, type-*, phase-*, screen-*, fn-*, annot-*, op-*)
  instead of a single scrolling page; namespace overview pages (ns-screen …
  ns-color) and a searchable index (api.html) with client-side fuzzy search.
- Sticky-header scroll offset (scroll-margin) so a jumped-to entry/param/color is
  never hidden, plus a flash highlight on the scrolled-to target.

Deep linking in every snippet & example
- Namespace members split: `Screen`→namespace page, `fill_rectangle`→method page;
  `Color`→palette page, `Charcoal`→its swatch — separately.
- Named arguments (`width:`) link to that parameter's anchor on the method page.
- Hover any token for a summary card built from the real API data (symbols.json).

Content & coverage
- Full authoritative surface documented from the compiler: every keyword, type,
  the 6 phases (Start/Input/FixedUpdate/Update/LateUpdate/Render, each its own
  page), all 22 annotations, namespace methods with parameter docs, builtins,
  the world_* reflection ABI, networking, operators — 155 symbols.
- Longer, clearer explanations; "model"/"model instance" terminology, not "entity";
  descriptive identifiers in every example (Position{column,row}, Velocity{delta_x,
  delta_y}, Health{current,maximum}, Player/Enemy) — no Pos/Seg/x/dx.
- Accuracy fixes from compiler ground-truth: world_count() takes no arg,
  world_query_next(property, cursor) arg order, event fields bind by name; dropped
  `when` and `module` (not in the self-hosted parser).

Tooling
- inventory.json + check.py: coverage guard (every symbol has a page), duplicate-
  token guard, and broken-link guard — fail CI so docs can't drift.
- validate.py: compiles every ```ludic example against bin/ludicc (158 compile).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-29 17:53:22 +03:00

116 lines
4.7 KiB
Python

#!/usr/bin/env python3
"""check.py — coverage + integrity guard for the generated docs site.
Fails (exit 1) if:
* the pages contract is broken (index.html / api.html / .nojekyll missing);
* any symbol in tools/docgen/inventory.json lacks a source file AND a page;
* any per-symbol source file still carries only its one-line seed (i.e. was
scaffolded but never written up) — so "every symbol is really documented";
* a highlighter link target (page) does not exist in the output.
Usage: python3 tools/docgen/check.py [site-dir] (default build/pages)
"""
import json, os, re, sys
ROOT = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
LANG = os.path.join(ROOT, "docs", "language")
DOCGEN = os.path.join(ROOT, "tools", "docgen")
def parse_front(path):
t = open(path, encoding="utf-8").read()
meta = {}
if t.startswith("---"):
end = t.find("\n---", 3)
if end != -1:
for line in t[3:end].strip("\n").split("\n"):
if line.strip() and ":" in line:
k, v = line.split(":", 1); meta[k.strip()] = v.strip()
body = t[end+4:].strip()
else:
body = t
else:
body = t
return meta, body
def main(site):
problems, warnings = [], []
# 1) pages contract
for f in ("index.html", "api.html", ".nojekyll"):
if not os.path.exists(os.path.join(site, f)):
problems.append("missing required file: " + f)
# 2) coverage against the authoritative inventory
inv = json.load(open(os.path.join(DOCGEN, "inventory.json")))
# map id -> source path
id2src = {}
thin = []
for cat in sorted(os.listdir(LANG)):
cdir = os.path.join(LANG, cat)
if not os.path.isdir(cdir):
continue
for fn in os.listdir(cdir):
if not fn.endswith(".md") or fn == "_section.md":
continue
meta, body = parse_front(os.path.join(cdir, fn))
sid = meta.get("id", fn[:-3]); id2src[sid] = os.path.join(cdir, fn)
# a "thin" file = body (minus a Parameters block and its tip line) too short
tipline = meta.get("tip", "")
btext = re.sub(r"(?is)parameters:.*", "", body).strip()
btext = btext.replace(tipline, "").strip()
if len(btext) < 40:
thin.append(sid)
for cat, ids in inv.items():
for sid in ids:
if sid not in id2src:
problems.append("no source file for inventory symbol: %s (%s)" % (sid, cat))
elif site and not os.path.exists(os.path.join(site, sid + ".html")):
problems.append("no generated page for symbol: %s.html" % sid)
# 2b) duplicate token → symbol conflicts (same token documented on two pages)
tok2ids = {}
for cat in sorted(os.listdir(LANG)):
cdir = os.path.join(LANG, cat)
if not os.path.isdir(cdir):
continue
for fn in os.listdir(cdir):
if not fn.endswith(".md") or fn == "_section.md":
continue
meta, _ = parse_front(os.path.join(cdir, fn))
for tok in meta.get("tokens", "").split():
tok2ids.setdefault((meta.get("kind",""), tok), set()).add(meta.get("id",""))
for (kind, tok), ids in sorted(tok2ids.items()):
if len(ids) > 1:
problems.append("token %r (%s) documented on multiple pages: %s" % (tok, kind, ", ".join(sorted(ids))))
# 3) thin (un-expanded) symbols — warn, not fail (lets infra land before prose)
if thin:
warnings.append("%d symbols still have only seed text: %s%s"
% (len(thin), ", ".join(sorted(thin)[:12]), " …" if len(thin) > 12 else ""))
# 4) highlighter targets exist
sj = os.path.join(site, "symbols.json")
if os.path.exists(sj):
h = json.load(open(sj))["highlight"]
targets = set()
for grp in ("keywords", "types", "phases", "annotations"):
targets |= set(h.get(grp, {}).values())
for grp in ("builtins", "nsmethods"):
targets |= set(v["id"] for v in h.get(grp, {}).values())
targets |= set(h.get("namespaces", {}).values())
for tgt in sorted(targets):
if not os.path.exists(os.path.join(site, tgt + ".html")):
problems.append("highlighter links to %s.html but it was not generated" % tgt)
for w in warnings:
print(" warning:", w)
if problems:
print("docs check FAILED:")
for p in problems:
print(" -", p)
return 1
print("docs check OK: %s (%d symbols documented)" % (site, len(id2src)))
return 0
if __name__ == "__main__":
sys.exit(main(sys.argv[1] if len(sys.argv) > 1 else os.path.join(ROOT, "build", "pages")))