mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-03 18:28:24 +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
|
@ -2412,8 +2412,15 @@ impl OptionsMetadata for FormatOrOutputFormat {
|
|||
fn record(visit: &mut dyn Visit) {
|
||||
FormatOptions::record(visit);
|
||||
}
|
||||
|
||||
fn documentation() -> Option<&'static str> {
|
||||
FormatOptions::documentation()
|
||||
}
|
||||
}
|
||||
|
||||
/// Experimental: Configures how `ruff format` formats your code.
|
||||
///
|
||||
/// Please provide feedback in [this discussion](https://github.com/astral-sh/ruff/discussions/7310).
|
||||
#[derive(
|
||||
Debug, PartialEq, Eq, Default, Serialize, Deserialize, ConfigurationOptions, CombineOptions,
|
||||
)]
|
||||
|
|
|
@ -16,6 +16,10 @@ pub trait OptionsMetadata {
|
|||
/// Visits the options metadata of this object by calling `visit` for each option.
|
||||
fn record(visit: &mut dyn Visit);
|
||||
|
||||
fn documentation() -> Option<&'static str> {
|
||||
None
|
||||
}
|
||||
|
||||
/// Returns the extracted metadata.
|
||||
fn metadata() -> OptionSet
|
||||
where
|
||||
|
@ -51,6 +55,7 @@ impl Display for OptionEntry {
|
|||
#[derive(Copy, Clone, Eq, PartialEq)]
|
||||
pub struct OptionSet {
|
||||
record: fn(&mut dyn Visit),
|
||||
doc: fn() -> Option<&'static str>,
|
||||
}
|
||||
|
||||
impl OptionSet {
|
||||
|
@ -58,7 +63,10 @@ impl OptionSet {
|
|||
where
|
||||
T: OptionsMetadata + 'static,
|
||||
{
|
||||
Self { record: T::record }
|
||||
Self {
|
||||
record: T::record,
|
||||
doc: T::documentation,
|
||||
}
|
||||
}
|
||||
|
||||
/// Visits the options in this set by calling `visit` for each option.
|
||||
|
@ -67,6 +75,11 @@ impl OptionSet {
|
|||
record(visit);
|
||||
}
|
||||
|
||||
pub fn documentation(&self) -> Option<&'static str> {
|
||||
let documentation = self.doc;
|
||||
documentation()
|
||||
}
|
||||
|
||||
/// Returns `true` if this set has an option that resolves to `name`.
|
||||
///
|
||||
/// The name can be separated by `.` to find a nested option.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue