Skip to content

Commit

Permalink
Add highlighting for comments in items declaration
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed Nov 13, 2023
1 parent 891c6ee commit 7bf2afd
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/librustdoc/html/render/print_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1502,7 +1502,7 @@ fn print_tuple_struct_fields<'a, 'cx: 'a>(
if s.iter()
.all(|field| matches!(*field.kind, clean::StrippedItem(box clean::StructFieldItem(..))))
{
return f.write_str("/* private fields */");
return f.write_str("<span class=\"comment\">/* private fields */</span>");
}

for (i, ty) in s.iter().enumerate() {
Expand Down Expand Up @@ -1659,7 +1659,7 @@ fn render_enum_fields(
}

if variants_stripped && !is_non_exhaustive {
w.write_str(" // some variants omitted\n");
w.write_str(" <span class=\"comment\">// some variants omitted</span>\n");
}
if toggle {
toggle_close(&mut w);
Expand Down Expand Up @@ -1804,15 +1804,21 @@ fn item_proc_macro(
let name = it.name.expect("proc-macros always have names");
match m.kind {
MacroKind::Bang => {
write!(buffer, "{name}!() {{ /* proc-macro */ }}").unwrap();
write!(buffer, "{name}!() {{ <span class=\"comment\">/* proc-macro */</span> }}")
.unwrap();
}
MacroKind::Attr => {
write!(buffer, "#[{name}]").unwrap();
}
MacroKind::Derive => {
write!(buffer, "#[derive({name})]").unwrap();
if !m.helpers.is_empty() {
buffer.write_str("\n{\n // Attributes available to this derive:\n").unwrap();
buffer
.write_str(
"\n{\n \
<span class=\"comment\">// Attributes available to this derive:</span>\n",
)
.unwrap();
for attr in &m.helpers {
writeln!(buffer, " #[{attr}]").unwrap();
}
Expand Down Expand Up @@ -2174,7 +2180,7 @@ fn render_union<'a, 'cx: 'a>(
}

if it.has_stripped_entries().unwrap() {
write!(f, " /* private fields */\n")?;
write!(f, " <span class=\"comment\">/* private fields */</span>\n")?;
}
if toggle {
toggle_close(&mut f);
Expand Down Expand Up @@ -2260,11 +2266,11 @@ fn render_struct_fields(

if has_visible_fields {
if has_stripped_entries {
write!(w, "\n{tab} /* private fields */");
write!(w, "\n{tab} <span class=\"comment\">/* private fields */</span>");
}
write!(w, "\n{tab}");
} else if has_stripped_entries {
write!(w, " /* private fields */ ");
write!(w, " <span class=\"comment\">/* private fields */</span> ");
}
if toggle {
toggle_close(&mut w);
Expand All @@ -2276,7 +2282,7 @@ fn render_struct_fields(
if fields.iter().all(|field| {
matches!(*field.kind, clean::StrippedItem(box clean::StructFieldItem(..)))
}) {
write!(w, "/* private fields */");
write!(w, "<span class=\"comment\">/* private fields */</span>");
} else {
for (i, field) in fields.iter().enumerate() {
if i > 0 {
Expand Down

0 comments on commit 7bf2afd

Please sign in to comment.