Skip to content

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

Merged
merged 4 commits into from
Mar 5, 2025

Conversation

DougGregor
Copy link
Member

@DougGregor DougGregor commented Mar 4, 2025

A diagnostic category provides a category name that is used to identify a set of related diagnostics. It can also include a documentation path to provide more information about those diagnostics, to help guide the user in resolving them.

Always render a category as [#CategoryName] at the end of the diagnostic message. When we are producing colored output and there is a documentation path, make the category name a hyperlink to the documentation using the OSC 8 scheme.

A diagnostic category provides a category name that is used to identify
a set of related diagnostics. It can also include a documentation path
to provide more information about those diagnostics, to help guide the
user in resolving them.

Always render a category as [#CategoryName] at the end of the
diagnostic message. When we are producing colored output and there is a
documentation path, make the category name a hyperlink to the
documentation using the OSC 8 scheme.
@DougGregor
Copy link
Member Author

@swift-ci please test

@DougGregor
Copy link
Member Author

@swift-ci please test macOS

Copy link
Member

@ahoppen ahoppen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice


/// Forms a hyperlink to the given URL with the given text.
static func hyperlink(_ text: String, to url: String) -> String {
"\u{001B}]8;;\(url)\u{001B}\\\(text)\u{001B}]8;;\u{001B}\\"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uh, interesting. I did not know that terminals support hyperlinks. ✨

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wild, eh?

Copy link
Contributor

Choose a reason for hiding this comment

The 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.)

Copy link
Contributor

Choose a reason for hiding this comment

The 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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Also, as an aside, you may want to escape both strings.)

Copy link
Member Author

Choose a reason for hiding this comment

The 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.

Since we're creating a hyperlink to it, we want a URL here.
@DougGregor DougGregor force-pushed the diagnostic-category branch from 01c7c33 to e3b4abf Compare March 4, 2025 17:46
@DougGregor
Copy link
Member Author

@swift-ci please test

@DougGregor
Copy link
Member Author

@swift-ci please test Linux

@DougGregor
Copy link
Member Author

@swift-ci please test Windows

@DougGregor DougGregor force-pushed the diagnostic-category branch from 0897ff5 to d877261 Compare March 4, 2025 21:25
@DougGregor
Copy link
Member Author

@swift-ci please test

@DougGregor
Copy link
Member Author

@swift-ci please test Windows

@DougGregor
Copy link
Member Author

@swift-ci please test platform Windows

@DougGregor
Copy link
Member Author

@swift-ci please test macOS

@DougGregor
Copy link
Member Author

@swift-ci please test Windows

@rintaro
Copy link
Member

rintaro commented Mar 5, 2025

@swift-ci Please test Windows

@DougGregor DougGregor merged commit 7b01db2 into swiftlang:main Mar 5, 2025
3 checks passed
@DougGregor DougGregor deleted the diagnostic-category branch March 5, 2025 14:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants