Fix spec-explorer-data: pass metadata from SX routing instead of env lookup

The helper was trying to look up all-spec-items from get_component_env(),
but that only contains defcomp/defmacro — not regular defines. Now the
SX routing layer calls find-spec and passes filename/title/desc directly.

Also adds boundary declaration for spec-explorer-data.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-12 00:22:25 +00:00
parent 4aa2133b39
commit c5a4340293
3 changed files with 17 additions and 31 deletions

View File

@@ -109,3 +109,8 @@
:params ()
:returns "dict"
:service "sx")
(define-page-helper "spec-explorer-data"
:params (filename title desc)
:returns "dict"
:service "sx")

View File

@@ -352,9 +352,15 @@
:else (cond
(starts-with? slug "explore/")
(let ((spec-slug (slice slug 8 (string-length slug)))
(data (spec-explorer-data spec-slug)))
(if data
(~spec-explorer-content :data data)
(spec (find-spec spec-slug)))
(if spec
(let ((data (spec-explorer-data
(get spec "filename")
(get spec "title")
(get spec "desc"))))
(if data
(~spec-explorer-content :data data)
(~spec-not-found :slug spec-slug)))
(~spec-not-found :slug spec-slug)))
:else (let ((spec (find-spec slug)))
(if spec

View File

@@ -142,9 +142,10 @@ def _read_spec_file(filename: str) -> str:
return ";; spec file not found"
def _spec_explorer_data(slug: str) -> dict | None:
def _spec_explorer_data(filename: str, title: str = "", desc: str = "") -> dict | None:
"""Parse a spec file into structured metadata for the spec explorer.
Receives filename/title/desc from the SX routing layer (via find-spec).
Returns sections with defines, effects, params, source, and translations.
"""
import os
@@ -152,22 +153,9 @@ def _spec_explorer_data(slug: str) -> dict | None:
from shared.sx.parser import parse_all
from shared.sx.types import Symbol, Keyword
# Look up spec metadata from nav-data (via find-spec helper)
from shared.sx.jinja_bridge import get_component_env
env = get_component_env()
all_specs = env.get("all-spec-items", [])
spec_meta = None
for item in all_specs:
if isinstance(item, dict) and item.get("slug") == slug:
spec_meta = item
break
if not spec_meta:
if not filename:
return None
filename = spec_meta.get("filename", "")
title = spec_meta.get("title", slug)
desc = spec_meta.get("desc", "")
# Read the raw source
ref_dir = os.path.join(os.path.dirname(__file__), "..", "..", "shared", "sx", "ref")
if not os.path.isdir(ref_dir):
@@ -304,19 +292,6 @@ def _spec_explorer_data(slug: str) -> dict | None:
i += 1
return result
def _assign_to_section(line_num: int) -> dict:
"""Find which section a line belongs to."""
best = sections[0]
for s in sections:
# Section starts at its first define or earlier
if s["defines"]:
first_line = s["defines"][0].get("line", 0)
else:
first_line = 0
# Use section order — defines after a section header belong to it
# Simple approach: find section by scanning source position
return best
# Process defines
all_defines: list[dict] = []
py_emitter = None