Skip to content

Commit

Permalink
Generate links to documentation
Browse files Browse the repository at this point in the history
We don't currently have the ability to generate documentation from
Apple's documentation, so for now, let's just link to it instead.

Part of #309.
  • Loading branch information
madsmtm committed Nov 25, 2024
1 parent 22aa38a commit a8e99f6
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
16 changes: 16 additions & 0 deletions crates/header-translator/src/id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,22 @@ impl ItemIdentifier {

ItemIdentifierPathInRelationTo(self, other)
}

/// Generate a markdown link to Apple's documentation.
///
/// This is best effort only, and doesn't work for functions and methods,
/// and possibly some renamed classes and traits. Additionally, the link
/// may redirect.
pub(crate) fn doc_link(&self) -> impl fmt::Display + '_ {
FormatterFn(|f| {
write!(
f,
"[Apple's documentation](https://developer.apple.com/documentation/{}/{}?language=objc)",
self.library_name().to_lowercase(),
self.name.to_lowercase()
)
})
}
}

impl ItemIdentifier<Option<String>> {
Expand Down
11 changes: 10 additions & 1 deletion crates/header-translator/src/stmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1659,6 +1659,7 @@ impl Stmt {
}

writeln!(f, "extern_class!(")?;
writeln!(f, " /// {}", id.doc_link())?;
write!(f, " #[unsafe(super(")?;
for (i, (superclass, generics)) in superclasses.iter().enumerate() {
if 0 < i {
Expand Down Expand Up @@ -1977,6 +1978,7 @@ impl Stmt {
} => {
writeln!(f, "extern_protocol!(")?;

writeln!(f, " /// {}", id.doc_link())?;
write!(f, " {}", self.cfg_gate_ln(config))?;
write!(f, " {availability}")?;
write!(f, " pub unsafe trait {}", id.name)?;
Expand Down Expand Up @@ -2048,6 +2050,7 @@ impl Stmt {
fields,
sendable,
} => {
writeln!(f, "/// {}", id.doc_link())?;
write!(f, "{}", self.cfg_gate_ln(config))?;
write!(f, "{availability}")?;
write!(f, "#[repr(C)]")?;
Expand Down Expand Up @@ -2103,6 +2106,8 @@ impl Stmt {
variants,
sendable,
} => {
writeln!(f, "/// {}", id.doc_link())?;

match kind {
// TODO: Once Rust gains support for more precisely
// specifying niches, use that to convert this into a
Expand Down Expand Up @@ -2265,6 +2270,7 @@ impl Stmt {
value,
is_last,
} => {
writeln!(f, "/// {}", id.doc_link())?;
write!(f, "{}", self.cfg_gate_ln(config))?;
write!(f, "{availability}")?;
write!(f, "pub const {}: {} = {value};", id.name, ty.enum_())?;
Expand All @@ -2279,8 +2285,9 @@ impl Stmt {
value: None,
} => {
writeln!(f, "extern \"C\" {{")?;
writeln!(f, " /// {}", id.doc_link())?;
write!(f, "{}", self.cfg_gate_ln(config))?;
writeln!(f, "pub static {}: {};", id.name, ty.var())?;
writeln!(f, " pub static {}: {};", id.name, ty.var())?;
writeln!(f, "}}")?;
}
Self::VarDecl {
Expand All @@ -2289,6 +2296,7 @@ impl Stmt {
ty,
value: Some(expr),
} => {
writeln!(f, "/// {}", id.doc_link())?;
write!(f, "{}", self.cfg_gate_ln(config))?;
write!(f, "pub static {}: {} = ", id.name, ty.var())?;

Expand Down Expand Up @@ -2385,6 +2393,7 @@ impl Stmt {
ty,
kind,
} => {
writeln!(f, "/// {}", id.doc_link())?;
match kind {
Some(UnexposedAttr::TypedEnum) => {
// TODO: Handle this differently
Expand Down
2 changes: 1 addition & 1 deletion crates/test-ui/ui/implement_protocol_missing_super.stderr

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion generated
Submodule generated updated 2413 files

0 comments on commit a8e99f6

Please sign in to comment.