-
Notifications
You must be signed in to change notification settings - Fork 440
Add an optional diagnostic category to diagnostics #2981
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 |
---|---|---|
|
@@ -48,7 +48,8 @@ extension DiagnosticDecorator where Self == ANSIDiagnosticDecorator { | |
/// ``` | ||
@_spi(Testing) public func decorateMessage( | ||
_ message: String, | ||
basedOnSeverity severity: DiagnosticSeverity | ||
basedOnSeverity severity: DiagnosticSeverity, | ||
category: DiagnosticCategory? = nil | ||
) -> String { | ||
let severityText: String | ||
let severityAnnotation: ANSIAnnotation | ||
|
@@ -77,7 +78,24 @@ extension DiagnosticDecorator where Self == ANSIDiagnosticDecorator { | |
resetAfterApplication: false | ||
) | ||
|
||
return prefix + colorizeIfNotEmpty(message, usingAnnotation: .diagnosticText) | ||
// Append the [#CategoryName] suffix when there is a category. | ||
let categorySuffix: String | ||
if let category { | ||
// Make the category name a link to the documentation, if there is | ||
// documentation. | ||
let categoryName: String | ||
if let documentationURL = category.documentationURL { | ||
categoryName = ANSIAnnotation.hyperlink(category.name, to: "\(documentationURL)") | ||
} else { | ||
categoryName = category.name | ||
} | ||
|
||
categorySuffix = " [#\(categoryName)]" | ||
} else { | ||
categorySuffix = "" | ||
} | ||
|
||
return prefix + colorizeIfNotEmpty(message, usingAnnotation: .diagnosticText) + categorySuffix | ||
} | ||
|
||
/// Decorates a source code buffer outline using ANSI cyan color codes. | ||
|
@@ -220,4 +238,12 @@ private struct ANSIAnnotation { | |
static var remarkText: Self { | ||
Self(color: .blue, trait: .bold) | ||
} | ||
|
||
/// Forms a hyperlink to the given URL with the given text. | ||
/// | ||
/// This follows the OSC 8 standard for hyperlinks that is supported by | ||
/// a number of different terminals. | ||
static func hyperlink(_ text: String, to url: String) -> String { | ||
"\u{001B}]8;;\(url)\u{001B}\\\(text)\u{001B}]8;;\u{001B}\\" | ||
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. Uh, interesting. I did not know that terminals support hyperlinks. ✨ 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. Wild, eh? 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. Do you know which terminal applications support this functionality? I don't think it's universal (the VT-100 certainly didn't have the feature.) 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. Looks like Apple's Terminal.app doesn't support it. Allegedly Konsole doesn't either, although I don't have a copy handy. 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. (Also, as an aside, you may want to escape both strings.) 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. There's a list of terminals supporting this at https://github.com/Alhadis/OSC8-Adoption/. Terminal.app doesn't, but it doesn't blow up on it, either; it just shows the text (not the link), which is fine. |
||
} | ||
} |
DougGregor marked this conversation as resolved.
Show resolved
Hide resolved
|
Uh oh!
There was an error while loading. Please reload this page.