Fix docs outline for nested definitions (#5823)

This commit is contained in:
Laurenz 2025-02-06 11:18:35 +01:00 committed by GitHub
parent ca702c7f82
commit d61f57365b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -550,8 +550,6 @@ fn func_outline(model: &FuncModel, id_base: &str) -> Vec<OutlineItem> {
.collect(), .collect(),
}); });
} }
outline.extend(scope_outline(&model.scope));
} else { } else {
outline.extend(model.params.iter().map(|param| OutlineItem { outline.extend(model.params.iter().map(|param| OutlineItem {
id: eco_format!("{id_base}-{}", urlify(param.name)), id: eco_format!("{id_base}-{}", urlify(param.name)),
@ -560,27 +558,30 @@ fn func_outline(model: &FuncModel, id_base: &str) -> Vec<OutlineItem> {
})); }));
} }
outline.extend(scope_outline(&model.scope, id_base));
outline outline
} }
/// Produce an outline for a function scope. /// Produce an outline for a function scope.
fn scope_outline(scope: &[FuncModel]) -> Option<OutlineItem> { fn scope_outline(scope: &[FuncModel], id_base: &str) -> Option<OutlineItem> {
if scope.is_empty() { if scope.is_empty() {
return None; return None;
} }
Some(OutlineItem { let dash = if id_base.is_empty() { "" } else { "-" };
id: "definitions".into(), let id = eco_format!("{id_base}{dash}definitions");
name: "Definitions".into(),
children: scope let children = scope
.iter() .iter()
.map(|func| { .map(|func| {
let id = urlify(&eco_format!("definitions-{}", func.name)); let id = urlify(&eco_format!("{id}-{}", func.name));
let children = func_outline(func, &id); let children = func_outline(func, &id);
OutlineItem { id, name: func.title.into(), children } OutlineItem { id, name: func.title.into(), children }
}) })
.collect(), .collect();
})
Some(OutlineItem { id, name: "Definitions".into(), children })
} }
/// Create a page for a group of functions. /// Create a page for a group of functions.
@ -687,7 +688,7 @@ fn type_outline(model: &TypeModel) -> Vec<OutlineItem> {
}); });
} }
outline.extend(scope_outline(&model.scope)); outline.extend(scope_outline(&model.scope, ""));
outline outline
} }