Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions crates/pseudoscript-doc/src/health.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,10 @@ pub(crate) fn build_health(
.iter()
.map(|d| {
let node = owning_node(graph, d);
let href = node
.and_then(|n| urls.get(&n.fqn))
.map_or_else(
|| format!("{prefix}{}", module_page_path(&d.module)),
|url| format!("{prefix}{}#{}", url.page, url.anchor),
);
let href = node.and_then(|n| urls.get(&n.fqn)).map_or_else(
|| format!("{prefix}{}", module_page_path(&d.module)),
|url| format!("{prefix}{}#{}", url.page, url.anchor),
);
HealthEntry {
module: d.module.clone(),
severity: d.severity.clone(),
Expand Down
10 changes: 8 additions & 2 deletions crates/pseudoscript-doc/src/highlight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,14 @@ mod tests {
#[test]
fn pds_blocks_highlight_keywords_strings_and_docs() {
let html = highlight("pds", "/// A shop.\npublic system Shop;\n");
assert!(html.contains("<span class=\"tok-kw\">public</span>"), "{html}");
assert!(html.contains("<span class=\"tok-kw\">system</span>"), "{html}");
assert!(
html.contains("<span class=\"tok-kw\">public</span>"),
"{html}"
);
assert!(
html.contains("<span class=\"tok-kw\">system</span>"),
"{html}"
);
assert!(html.contains("tok-doc"), "{html}");
assert!(html.contains("Shop"), "plain idents survive: {html}");
}
Expand Down
6 changes: 5 additions & 1 deletion crates/pseudoscript-doc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,11 @@ pub fn try_render_site_with(
shell::wrap(path, props, &props_json, &result),
));
}
files.push(search::build_search_index(graph, config, &crate::url::UrlMap::build(graph)));
files.push(search::build_search_index(
graph,
config,
&crate::url::UrlMap::build(graph),
));
files.push(SiteFile::new("style.css", assets::STYLE_CSS));
files.push(SiteFile::new("client.js", assets::CLIENT_JS));
files.push(SiteFile::new("universe.js", assets::UNIVERSE_JS));
Expand Down
46 changes: 40 additions & 6 deletions crates/pseudoscript-doc/src/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,15 @@ pub(crate) fn build_pages(
for module in &modules {
pages.push((
module_page_path(module),
build_module(graph, config, module, &modules, &urls, diagnostics, svg_theme),
build_module(
graph,
config,
module,
&modules,
&urls,
diagnostics,
svg_theme,
),
));
}
pages.push((
Expand Down Expand Up @@ -254,7 +262,13 @@ fn build_index(
.collect();
let page = PageBody::Index(IndexProps {
title: config.name.clone(),
context_diagram: build_svg_diagram(graph, View::Context, "Context", "System context", svg_theme),
context_diagram: build_svg_diagram(
graph,
View::Context,
"Context",
"System context",
svg_theme,
),
cards,
stats: build_stats(graph, diagnostics),
});
Expand Down Expand Up @@ -692,7 +706,12 @@ mod tests {
#[test]
fn pages_emit_in_order_index_docs_modules_universe_health() {
let g = graph(&[WorkspaceModule::new("m", "//! m\npublic system S;")]);
let pages = build_pages(&g, &config_with_docs(), &[], pseudoscript_emit::Theme::Adaptive);
let pages = build_pages(
&g,
&config_with_docs(),
&[],
pseudoscript_emit::Theme::Adaptive,
);
let paths: Vec<&str> = pages.iter().map(|(p, _)| p.as_str()).collect();
assert_eq!(paths[0], "index.html");
assert_eq!(paths[1], "docs/introduction.html");
Expand All @@ -704,7 +723,12 @@ mod tests {
#[test]
fn doc_page_carries_rendered_markdown_and_sidebar_group() {
let g = graph(&[WorkspaceModule::new("m", "//! m\npublic system S;")]);
let pages = build_pages(&g, &config_with_docs(), &[], pseudoscript_emit::Theme::Adaptive);
let pages = build_pages(
&g,
&config_with_docs(),
&[],
pseudoscript_emit::Theme::Adaptive,
);
let (_, doc) = pages
.iter()
.find(|(p, _)| p == "docs/introduction.html")
Expand All @@ -723,7 +747,12 @@ mod tests {
fn every_diagram_is_adaptive_inline_svg() {
let src = "//! m\n/// Sys.\npublic system S;\npublic container C for m::S {\n #[manual]\n public Run() {\n self.Step()\n }\n Step();\n}\n";
let g = graph(&[WorkspaceModule::new("m", src)]);
let pages = build_pages(&g, &DocConfig::default(), &[], pseudoscript_emit::Theme::Adaptive);
let pages = build_pages(
&g,
&DocConfig::default(),
&[],
pseudoscript_emit::Theme::Adaptive,
);
let (_, module) = pages
.iter()
.find(|(p, _)| p.starts_with("module/"))
Expand All @@ -745,7 +774,12 @@ mod tests {
fn universe_page_carries_snapshot_flows_and_hrefs() {
let src = "//! m\npublic system S;\npublic container C for m::S {\n #[manual]\n public Run() {\n m::D.Go()\n }\n}\npublic container D for m::S {\n public Go();\n}\n";
let g = graph(&[WorkspaceModule::new("m", src)]);
let pages = build_pages(&g, &DocConfig::default(), &[], pseudoscript_emit::Theme::Adaptive);
let pages = build_pages(
&g,
&DocConfig::default(),
&[],
pseudoscript_emit::Theme::Adaptive,
);
let (_, universe) = pages
.iter()
.find(|(p, _)| p == "universe.html")
Expand Down
15 changes: 13 additions & 2 deletions crates/pseudoscript-doc/src/render_md.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,14 @@ fn render_universe(out: &mut String, universe: &UniverseProps) {
if !universe.edges.is_empty() {
out.push_str("## Relationships\n\n");
for edge in &universe.edges {
let _ = writeln!(out, "- `{}` \u{2192} `{}` ({} call{})", edge.from, edge.to, edge.traffic, if edge.traffic == 1 { "" } else { "s" });
let _ = writeln!(
out,
"- `{}` \u{2192} `{}` ({} call{})",
edge.from,
edge.to,
edge.traffic,
if edge.traffic == 1 { "" } else { "s" }
);
}
out.push('\n');
}
Expand All @@ -104,7 +111,11 @@ fn render_universe(out: &mut String, universe: &UniverseProps) {
for flow in &universe.flows {
let _ = writeln!(out, "- **{}** (`{}`)", flow.name, flow.fqn);
for hop in &flow.hops {
let _ = writeln!(out, " - `{}` \u{2192} `{}` — {}", hop.from, hop.to, hop.label);
let _ = writeln!(
out,
" - `{}` \u{2192} `{}` — {}",
hop.from, hop.to, hop.label
);
}
}
out.push('\n');
Expand Down
22 changes: 15 additions & 7 deletions crates/pseudoscript-doc/src/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,16 @@ pub(crate) fn build_search_index(graph: &Graph, config: &DocConfig, urls: &UrlMa
}

for (name, href, summary) in [
("3D Universe", "universe.html", "The model in 3D — structure and flows"),
("Architecture Health", "health.html", "Errors, warnings, and principle lints"),
(
"3D Universe",
"universe.html",
"The model in 3D — structure and flows",
),
(
"Architecture Health",
"health.html",
"Errors, warnings, and principle lints",
),
] {
entries.push(SearchEntry {
fqn: href.to_owned(),
Expand All @@ -107,10 +115,7 @@ pub(crate) fn build_search_index(graph: &Graph, config: &DocConfig, urls: &UrlMa

entries.sort_by(|a, b| a.href.cmp(&b.href).then_with(|| a.fqn.cmp(&b.fqn)));
let json = serde_json::to_string(&entries).unwrap_or_else(|_| "[]".to_owned());
SiteFile::new(
"search-index.js",
format!("window.__PDS_SEARCH__={json};"),
)
SiteFile::new("search-index.js", format!("window.__PDS_SEARCH__={json};"))
}

/// Strips Markdown to plain text: the text and code events space-joined, with
Expand Down Expand Up @@ -161,6 +166,9 @@ mod tests {

#[test]
fn markdown_strips_to_plain_text() {
assert_eq!(markdown_text("# Hi\n\nSome **bold** `code`."), "Hi Some bold code .");
assert_eq!(
markdown_text("# Hi\n\nSome **bold** `code`."),
"Hi Some bold code ."
);
}
}
5 changes: 1 addition & 4 deletions crates/pseudoscript-doc/tests/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,7 @@ fn writes_universe_and_health_pages() {
);

let health = &site.file("health.md").expect("health.md").contents;
assert!(
health.contains("# Architecture health"),
"got:\n{health}"
);
assert!(health.contains("# Architecture health"), "got:\n{health}");
assert!(
health.contains("No findings."),
"the clean fixture reports no findings, got:\n{health}"
Expand Down
6 changes: 2 additions & 4 deletions crates/pseudoscript-ide/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -899,10 +899,8 @@ impl IdeSession {
.iter()
.map(|(fqn, m)| WorkspaceModule::new(fqn.clone(), m.source.clone()))
.collect();
let per_module = pseudoscript_model::check_workspace_modules_with_externals(
&modules,
&self.externals,
);
let per_module =
pseudoscript_model::check_workspace_modules_with_externals(&modules, &self.externals);
let diagnostics = pseudoscript_doc::prepare_diagnostics(&modules, &per_module);
let graph = self.graph();
let site = try_render_site_with(graph, &doc_config(config), &diagnostics, &engine)
Expand Down
15 changes: 6 additions & 9 deletions crates/pseudoscript/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -884,11 +884,10 @@ fn build_site(

// One per-module check pass feeds both the console report and the site's
// health page.
let per_module =
pseudoscript_model::check_workspace_modules_with_externals(
&project.modules,
&project.dependencies,
);
let per_module = pseudoscript_model::check_workspace_modules_with_externals(
&project.modules,
&project.dependencies,
);
report_diagnostics(
&per_module
.iter()
Expand All @@ -899,10 +898,8 @@ fn build_site(

let model = graph(&project.modules);
let site = match format {
DocFormat::Html => {
pseudoscript_doc::try_render_site(&model, &project.config, &diagnostics)
.context("rendering the documentation site")?
}
DocFormat::Html => pseudoscript_doc::try_render_site(&model, &project.config, &diagnostics)
.context("rendering the documentation site")?,
DocFormat::Md => {
pseudoscript_doc::render_markdown_site(&model, &project.config, &diagnostics)
}
Expand Down
5 changes: 4 additions & 1 deletion crates/pseudoscript/src/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,10 @@ impl DocTable {
/// Markdown from disk, relative to `root`.
fn resolve(self, root: &Path) -> Result<(DocConfig, PathBuf, Option<DocFormat>)> {
let name = self.name.unwrap_or_else(|| default_name(root));
let theme = self.theme.as_deref().map_or(Ok(Theme::System), parse_theme)?;
let theme = self
.theme
.as_deref()
.map_or(Ok(Theme::System), parse_theme)?;
let format = self.format.as_deref().map(parse_format).transpose()?;
let out = self.out.unwrap_or_else(|| "target/doc".to_owned());
let docs = self
Expand Down
Loading