mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-04 18:58:04 +00:00
Support option group documentation (#7593)
This commit is contained in:
parent
2ecf59726f
commit
01843af21a
5 changed files with 62 additions and 3 deletions
|
@ -10,7 +10,12 @@ use syn::{
|
|||
};
|
||||
|
||||
pub(crate) fn derive_impl(input: DeriveInput) -> syn::Result<proc_macro2::TokenStream> {
|
||||
let DeriveInput { ident, data, .. } = input;
|
||||
let DeriveInput {
|
||||
ident,
|
||||
data,
|
||||
attrs: struct_attributes,
|
||||
..
|
||||
} = input;
|
||||
|
||||
match data {
|
||||
Data::Struct(DataStruct {
|
||||
|
@ -50,12 +55,39 @@ pub(crate) fn derive_impl(input: DeriveInput) -> syn::Result<proc_macro2::TokenS
|
|||
};
|
||||
}
|
||||
|
||||
Ok(quote! {
|
||||
let docs: Vec<&Attribute> = struct_attributes
|
||||
.iter()
|
||||
.filter(|attr| attr.path().is_ident("doc"))
|
||||
.collect();
|
||||
|
||||
// Convert the list of `doc` attributes into a single string.
|
||||
let doc = dedent(
|
||||
&docs
|
||||
.into_iter()
|
||||
.map(parse_doc)
|
||||
.collect::<syn::Result<Vec<_>>>()?
|
||||
.join("\n"),
|
||||
)
|
||||
.trim_matches('\n')
|
||||
.to_string();
|
||||
|
||||
let documentation = if doc.is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some(quote!(
|
||||
fn documentation() -> Option<&'static str> {
|
||||
Some(&#doc)
|
||||
}
|
||||
))
|
||||
};
|
||||
|
||||
Ok(quote! {
|
||||
impl crate::options_base::OptionsMetadata for #ident {
|
||||
fn record(visit: &mut dyn crate::options_base::Visit) {
|
||||
#(#output);*
|
||||
}
|
||||
|
||||
#documentation
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue