Skip to content

Commit

Permalink
docs: Extract a function
Browse files Browse the repository at this point in the history
Summary: Repeat code

Reviewed By: IanChilds

Differential Revision: D64858311

fbshipit-source-id: a80047b4aadd103cf22dd21ee3ca8f88f5000e02
  • Loading branch information
JakobDegen authored and facebook-github-bot committed Oct 24, 2024
1 parent eec29c1 commit 412dedb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
17 changes: 11 additions & 6 deletions starlark/src/docs/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use crate::docs::DocMember;
use crate::docs::DocParam;
use crate::docs::DocProperty;
use crate::docs::DocString;
use crate::docs::DocType;
use crate::typing::Ty;

/// What to render from a [`DocString`].
Expand Down Expand Up @@ -174,6 +175,15 @@ pub(super) fn render_members<'a>(
format!("# {name}{summary}\n\n{members_details}")
}

pub(super) fn render_doc_type(name: &str, prefix: &str, t: &DocType) -> String {
render_members(
&name,
&t.docs,
&prefix,
t.members.iter().map(|(n, m)| (&**n, m.clone())),
)
}

/// Used by LSP.
pub fn render_doc_item(name: &str, item: &DocItem) -> String {
match item {
Expand All @@ -187,12 +197,7 @@ pub fn render_doc_item(name: &str, item: &DocItem) -> String {
.map(|m| (&**n, m))
}),
),
DocItem::Type(o) => render_members(
&format!("`{name}` type"),
&o.docs,
&format!("{name}."),
o.members.iter().map(|(n, m)| (&**n, m.clone())),
),
DocItem::Type(o) => render_doc_type(&format!("`{name}` type"), &format!("{name}."), o),
DocItem::Member(DocMember::Function(f)) => render_function(name, f),
DocItem::Member(DocMember::Property(p)) => render_property(name, p),
}
Expand Down
8 changes: 2 additions & 6 deletions starlark/src/docs/multipage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

use std::collections::HashMap;

use crate::docs::markdown::render_doc_type;
use crate::docs::markdown::render_members;
use crate::docs::DocItem;
use crate::docs::DocModule;
Expand Down Expand Up @@ -49,12 +50,7 @@ fn render_markdown_multipage_inner(
result.extend(render_markdown_multipage_inner(m, &name, &path));
}
DocItem::Type(t) => {
let rendered = render_members(
&name,
&t.docs,
&format!("{name}."),
t.members.iter().map(|(n, m)| (&**n, m.clone())),
);
let rendered = render_doc_type(&name, &format!("{name}."), &t);
result.insert(path, rendered);
}
DocItem::Member(m) => {
Expand Down

0 comments on commit 412dedb

Please sign in to comment.