Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Render token type names using Token! macro in documentation #1765

Merged
merged 1 commit into from
Oct 23, 2024
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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ required-features = ["full", "parsing"]
[package.metadata.docs.rs]
all-features = true
targets = ["x86_64-unknown-linux-gnu"]
rustdoc-args = ["--generate-link-to-definition"]
rustdoc-args = ["--generate-link-to-definition", "--extend-css=src/gen/token.css"]

[package.metadata.playground]
features = ["full", "visit", "visit-mut", "fold", "extra-traits"]
Expand Down
1 change: 1 addition & 0 deletions codegen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ json = ["syn-codegen/serde"]
anyhow = "1"
color-backtrace = "0.6"
indexmap = { version = "2", features = ["serde"] }
indoc = "2"
inflections = "1.1"
prettyplease = "0.2.3"
proc-macro2 = { version = "1.0.20", features = ["span-locations"] }
Expand Down
49 changes: 49 additions & 0 deletions codegen/src/css.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
use crate::workspace_path;
use anyhow::Result;
use indoc::{formatdoc, indoc};
use std::fs;
use syn_codegen::Definitions;

pub fn generate(defs: &Definitions) -> Result<()> {
let mut styles = String::new();
for ty in defs.tokens.keys() {
styles += &format!("a.struct[title=\"struct syn::token::{ty}\"],\n");
}
styles.truncate(styles.len() - 2);
styles += indoc! {"
{
\tdisplay: inline-block;
\tcolor: transparent;
\twhite-space: nowrap;
}
"};
styles.push('\n');
for ty in defs.tokens.keys() {
styles += &format!("a.struct[title=\"struct syn::token::{ty}\"]::before,\n");
}
styles.truncate(styles.len() - 2);
styles += indoc! {"
{
\tdisplay: inline-block;
\tcolor: var(--type-link-color);
\twidth: 0;
}
"};
for (ty, repr) in &defs.tokens {
let padding = ".".repeat((repr.len() + 8).saturating_sub(ty.len()));
styles += &formatdoc! {"

a.struct[title=\"struct syn::token::{ty}\"]::before {{
\tcontent: \"Token![{repr}]\";
}}

a.struct[title=\"struct syn::token::{ty}\"]::after {{
\tcontent: \"{padding}\";
}}
"};
}

let css_path = workspace_path::get("src/gen/token.css");
fs::write(css_path, styles)?;
Ok(())
}
2 changes: 2 additions & 0 deletions codegen/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

mod cfg;
mod clone;
mod css;
mod debug;
mod eq;
mod file;
Expand Down Expand Up @@ -52,5 +53,6 @@ fn main() -> anyhow::Result<()> {
visit::generate(&defs)?;
visit_mut::generate(&defs)?;
snapshot::generate(&defs)?;
css::generate(&defs)?;
Ok(())
}
Loading
Loading