-
Notifications
You must be signed in to change notification settings - Fork 439
[Diagnostic formatting] Add a category footnote printer #3007
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -351,4 +351,40 @@ public struct DiagnosticsFormatter { | |
suffixTexts: [:] | ||
) | ||
} | ||
|
||
/// Produce a string containing "footnotes" for each of the diagnostic | ||
/// category provided that has associated documentation. Each category | ||
/// is printed in Markdown link format, e.g., | ||
/// | ||
/// ``` | ||
/// [#categoryName]: <categoryDocumentationURL> | ||
/// ``` | ||
/// | ||
/// This function also deduplicates entries and alphabetizes the results. | ||
/// | ||
/// - Parameters: | ||
/// - categories: the categories to print | ||
/// - leadingText: text that is prefixed to the list of categories when | ||
/// there is at least one category to print. | ||
public func categoryFootnotes( | ||
_ categories: [DiagnosticCategory], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we make this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great idea! #3008 |
||
leadingText: String = "\n" | ||
) -> String { | ||
let categoriesInOrder = categories.compactMap { category in | ||
if let documentationURL = category.documentationURL { | ||
return (category.name, documentationURL) | ||
} else { | ||
return nil | ||
} | ||
}.sorted { $0.0.lowercased() < $1.0.lowercased() } | ||
|
||
if categoriesInOrder.isEmpty { | ||
return "" | ||
} | ||
|
||
return leadingText | ||
+ categoriesInOrder.map { name, url in | ||
"[#\(name)]: <\(url)>" | ||
}.joined(separator: "\n") | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, worth doing that 👍