From c5a434029353de9fe911bef09f83b23c90b1dbab Mon Sep 17 00:00:00 2001 From: giles Date: Thu, 12 Mar 2026 00:22:25 +0000 Subject: [PATCH] Fix spec-explorer-data: pass metadata from SX routing instead of env lookup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- sx/sx/boundary.sx | 5 +++++ sx/sxc/pages/docs.sx | 12 +++++++++--- sx/sxc/pages/helpers.py | 31 +++---------------------------- 3 files changed, 17 insertions(+), 31 deletions(-) diff --git a/sx/sx/boundary.sx b/sx/sx/boundary.sx index d39c940..9279936 100644 --- a/sx/sx/boundary.sx +++ b/sx/sx/boundary.sx @@ -109,3 +109,8 @@ :params () :returns "dict" :service "sx") + +(define-page-helper "spec-explorer-data" + :params (filename title desc) + :returns "dict" + :service "sx") diff --git a/sx/sxc/pages/docs.sx b/sx/sxc/pages/docs.sx index 1150ad6..1b44b28 100644 --- a/sx/sxc/pages/docs.sx +++ b/sx/sxc/pages/docs.sx @@ -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 diff --git a/sx/sxc/pages/helpers.py b/sx/sxc/pages/helpers.py index 1a33980..34e679a 100644 --- a/sx/sxc/pages/helpers.py +++ b/sx/sxc/pages/helpers.py @@ -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