Skip to content

[Serialized diagnostics] Encode category documentation URL in existing record #10326

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

Conversation

DougGregor
Copy link
Member

Serialized diagnostics support an optional category name, which can be used to group diagnostics together. This grouping is most helpful when a number of diagnostics are placed in a category that is documented together. For example, Clang's warnings are placed into groups that are each documented. However, any relationship between the category name and such documentation is left to the client to establish.

This change introduces a convention and APIs to allow diagnostic categories to be associated with a URL at which one can find documentation for the diagnostics in that category. Rather than outright extend the serialized diagnostics format with a new record kind, we utilize some redundancy to extend the existing RECORD_CATEGORY in a backward-compatible way. Specifically, for diagnostic categories that have documentation URLs associated with them, the blob associated with a RECORD_CATEGORY entry will be

<category name>@<category URL>

The RECORD_CATEGORY already includes a "category name length" field, which specifies the length of the category name. A correct reader would already be ignoring anything beyond that that position in the blob, so we get this extensibility for free: all of the extra information goes into the blob, but the category name length field still describes the length of the category name (i.e., the position of the @). A correct reader (that hasn't been updated for this change) will treat diagnostics files that provide these documentation URLs in the same way as ones that don't, ignoring the URL.

Amusingly, the two readers I looked at (the one in Clang and a Swift one we use for other tools) ignore the category name length field. They still fail fairly gracefully: the category name ends up being the whole blob, which is still human-readable and fairly reasonable.

This change teaches Clang's serialized diagnostic reader to properly respect the category name length field and, when the blob matches the description above, separately track the category documentation URL. It adds a new libclang diagnostics API clang_getDiagnosticCategoryURL() that provides this URL separately from the category.

c-index-test prints the category name -> URL mapping separate from the diagnostic so we can test this functionality.

This commit does not teach Clang to encode documentation URLs in the diagnostics it generates. That will come separately.

@DougGregor DougGregor requested a review from a team as a code owner March 22, 2025 21:20
@DougGregor
Copy link
Member Author

@swift-ci please test

…g record

Serialized diagnostics support an optional category name, which can be
used to group diagnostics together. This grouping is most helpful when
a number of diagnostics are placed in a category that is documented
together. For example, Clang's warnings are placed into groups that are
each documented. However, any relationship between the category name and
such documentation is left to the client to establish.

This change introduces a convention and APIs to allow diagnostic
categories to be associated with a URL at which one can find
documentation for the diagnostics in that category. Rather than
outright extend the serialized diagnostics format with a new record
kind, we utilize some redundancy to extend the existing RECORD_CATEGORY
in a backward-compatible way. Specifically, for diagnostic categories
that have documentation URLs associated with them, the blob associated
with a RECORD_CATEGORY entry will be

    <category name>@<category URL>

The RECORD_CATEGORY already includes a "category name length" field,
which specifies the length of the category name. A correct reader
would already be ignoring anything beyond that that position in the
blob, so we get this extensibility for free: all of the extra
information goes into the blob, but the category name length field
still describes the length of the category name (i.e., the position of
the @). A correct reader (that hasn't been updated for this change)
will treat diagnostics files that provide these documentation URLs in
the same way as ones that don't, ignoring the URL.

Amusingly, the two readers I looked at (the one in Clang and a Swift
one we use for other tools) ignore the category name length field.
They still fail fairly gracefully: the category name ends up being the
whole blob, which is still human-readable and fairly reasonable.

This change teaches Clang's serialized diagnostic reader to properly
respect the category name length field and, when the blob matches the
description above, separately track the category documentation URL. It
adds a new libclang diagnostics API `clang_getDiagnosticCategoryURL()`
that provides this URL separately from the category.

c-index-test prints the category name -> URL mapping separate from the
diagnostic so we can test this functionality.

This commit does not teach Clang to encode documentation URLs in the
diagnostics it generates. That will come separately.
@DougGregor DougGregor force-pushed the serialized-diag-category-url-20240723 branch from b26d3c9 to 8304ed7 Compare March 23, 2025 02:56
@DougGregor
Copy link
Member Author

@swift-ci please test

@DougGregor
Copy link
Member Author

@swift-ci please test Windows

@DougGregor DougGregor merged commit 6d5e70b into swiftlang:stable/20240723 Mar 24, 2025
3 checks passed
@DougGregor DougGregor deleted the serialized-diag-category-url-20240723 branch March 24, 2025 03:58
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.

1 participant