mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-30 05:45:24 +00:00
refactor: Replace Vec
in options metadata with static array (#3433)
This commit is contained in:
parent
1e081cf9a6
commit
cc8b13d3a7
7 changed files with 204 additions and 81 deletions
|
@ -44,15 +44,17 @@ pub fn derive_impl(input: DeriveInput) -> syn::Result<proc_macro2::TokenStream>
|
|||
};
|
||||
}
|
||||
|
||||
Ok(quote! {
|
||||
use crate::settings::options_base::{OptionEntry, OptionField, ConfigurationOptions};
|
||||
let options_len = output.len();
|
||||
|
||||
#[automatically_derived]
|
||||
impl ConfigurationOptions for #ident {
|
||||
fn get_available_options() -> Vec<(&'static str, OptionEntry)> {
|
||||
vec![#(#output),*]
|
||||
}
|
||||
}
|
||||
Ok(quote! {
|
||||
use crate::settings::options_base::{OptionEntry, OptionField, OptionGroup};
|
||||
|
||||
impl #ident {
|
||||
pub const fn metadata() -> OptionGroup {
|
||||
const OPTIONS: [(&'static str, OptionEntry); #options_len] = [#(#output),*];
|
||||
OptionGroup::new(&OPTIONS)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
_ => Err(syn::Error::new(
|
||||
|
@ -86,7 +88,7 @@ fn handle_option_group(field: &Field) -> syn::Result<proc_macro2::TokenStream> {
|
|||
let kebab_name = LitStr::new(&ident.to_string().replace('_', "-"), ident.span());
|
||||
|
||||
Ok(quote_spanned!(
|
||||
ident.span() => (#kebab_name, OptionEntry::Group(#path::get_available_options()))
|
||||
ident.span() => (#kebab_name, OptionEntry::Group(#path::metadata()))
|
||||
))
|
||||
}
|
||||
_ => Err(syn::Error::new(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue