Skip to content

[Diagnostics] Reference markdown files for educational notes and diagnostic group documentation #79688

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 3 commits into from
Mar 5, 2025

Conversation

DougGregor
Copy link
Member

@DougGregor DougGregor commented Feb 28, 2025

Start including diagnostic category and category documentation in diagnostics. These are rendered by the updated diagnostic formatter as a reference like [#StrictMemorySafety]. That reference will be a link to the Markdown documentation in the toolchain:

t.swift:2:7: warning: expression uses unsafe constructs but is not marked with 'unsafe' [#StrictMemorySafety]
1 | func somethingUnsafe(x: Int) {
2 |   _ = UnsafeRawPointer(bitPattern: x)
  |       |- warning: expression uses unsafe constructs but is not marked with 'unsafe' [#StrictMemorySafety]
  |       |- note: reference to unsafe type 'UnsafeRawPointer'
  |       |- note: reference to initializer 'init(bitPattern:)' involves unsafe type 'UnsafeRawPointer'
  |       `- note: @unsafe conformance of 'UnsafeRawPointer' to protocol '_Pointer' involves unsafe code
3 | }
4 | 

@DougGregor
Copy link
Member Author

@swift-ci please smoke test

@DougGregor
Copy link
Member Author

I'm splitting the mechanical changes out into a separate PR at #79688 so we can fret over the UI experience in this PR. I think maybe I want to use # instead of ^ for the marker because ^ looks weird to me, and I'm not sure that rendering this information as part of the message text is actually the right call (vs. having the renderer do it).

Bridge the category name and educational note computed for the Swift
compiler's diagnostics to the newly-introduced category field for
the swift-syntax diagnostics. This lets the swift-syntax renderer
introduce the category name and (optionally) link to the
documentation.
@heckj
Copy link
Member

heckj commented Mar 4, 2025

FWIW - while the markdown for footnotes made sense to me when I first saw it, it's apparently not currently supported in swift-markdown (or any of the DocC chain above it), if that makes a difference.

Since the goal here looks to be a providing a link/refernce location over an arbitrary block of metadata, using a single # as a subsequent marker seems simpler, and is relatively easy to look for and parse (for an IDE tooling kind of use case)

@DougGregor
Copy link
Member Author

FWIW - while the markdown for footnotes made sense to me when I first saw it, it's apparently not currently supported in swift-markdown (or any of the DocC chain above it), if that makes a difference.

Since the goal here looks to be a providing a link/refernce location over an arbitrary block of metadata, using a single # as a subsequent marker seems simpler, and is relatively easy to look for and parse (for an IDE tooling kind of use case)

It's another reason to go with #, which I just... tend to like more for entirely aesthetic reasons.

@DougGregor DougGregor force-pushed the diagnostic-ref-footnotes branch from af317ff to 398e1ad Compare March 4, 2025 17:51
@DougGregor DougGregor requested a review from CodaFi as a code owner March 4, 2025 17:51
@DougGregor
Copy link
Member Author

swiftlang/swift-syntax#2981

@swift-ci please smoke test

@DougGregor
Copy link
Member Author

Merging this. There will be a follow-up to add the links at the end of the file.

@DougGregor DougGregor merged commit 0997a7e into swiftlang:main Mar 5, 2025
3 checks passed
@DougGregor DougGregor deleted the diagnostic-ref-footnotes branch March 5, 2025 20:41
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.

2 participants