Repository navigation
Use the clang-tidy version in use for check documentation links #14830
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
Open
Abdelhadi Salmaoui (abdelhadi703)
wants to merge
3
commits into
microsoft:main
Choose a base branch
from
abdelhadi703:fix/clang-tidy-doc-version
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| /* -------------------------------------------------------------------------------------------- | ||
| * Copyright (c) Microsoft Corporation. All Rights Reserved. | ||
| * See 'LICENSE' in the project root for license information. | ||
| * ------------------------------------------------------------------------------------------ */ | ||
|
|
||
| /** | ||
| * The clang-tidy documentation is published per major LLVM release, so a check's page lives | ||
| * under the .1.0 release of the major the binary in use comes from: 23.1.0 and 22.1.0 have | ||
| * pages, 23.1.1 and 22.1.3 do not. Checks added in a newer major have no page in an older one, | ||
| * so the URL follows the binary in use rather than the release bundled with the extension. | ||
| * When the version in use could not be determined, fall back to the bundled release. | ||
| */ | ||
| const versionPattern: RegExp = /^([0-9]+)\.[0-9]+\.[0-9]+$/; | ||
|
|
||
| /** The release a clang-tidy version's documentation was published under. */ | ||
| function documentationRelease(clangTidyVersion: string): string | undefined { | ||
| const match: RegExpMatchArray | null = clangTidyVersion.match(versionPattern); | ||
| return match ? `${match[1]}.1.0` : undefined; | ||
| } | ||
|
|
||
| /** | ||
| * The clang-tidy release bundled with the extension. Its documentation is published under the | ||
| * .1.0 release of its major, so the fallback follows this rather than spelling out a URL version. | ||
| */ | ||
| export const bundledClangTidyVersion: string = '23.1.1'; | ||
|
|
||
| export const fallbackClangTidyDocVersion: string = documentationRelease(bundledClangTidyVersion) ?? '23.1.0'; | ||
|
|
||
| export function getClangTidyDocumentationUrl(docPage: string, clangTidyVersion?: string): string { | ||
| const release: string | undefined = clangTidyVersion ? documentationRelease(clangTidyVersion) : undefined; | ||
| return `https://releases.llvm.org/${release ?? fallbackClangTidyDocVersion}/tools/clang/tools/extra/docs/clang-tidy/${docPage}`; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| /* -------------------------------------------------------------------------------------------- | ||
| * Copyright (c) Microsoft Corporation. All Rights Reserved. | ||
| * See 'LICENSE' in the project root for license information. | ||
| * ------------------------------------------------------------------------------------------ */ | ||
|
|
||
| import { describe, it } from 'mocha'; | ||
| import { strictEqual } from 'node:assert'; | ||
| import { bundledClangTidyVersion, fallbackClangTidyDocVersion, getClangTidyDocumentationUrl } from '../../src/LanguageServer/clangTidyDocumentation'; | ||
|
|
||
| const bundledDocUrl: string = `https://releases.llvm.org/${fallbackClangTidyDocVersion}/tools/clang/tools/extra/docs/clang-tidy`; | ||
|
|
||
| describe('clang-tidy documentation URLs', () => { | ||
| it('points at the clang-tidy version in use', () => { | ||
| strictEqual( | ||
| getClangTidyDocumentationUrl('checks/readability/use-std-min-max.html', '19.1.0'), | ||
| 'https://releases.llvm.org/19.1.0/tools/clang/tools/extra/docs/clang-tidy/checks/readability/use-std-min-max.html'); | ||
| }); | ||
|
|
||
| it('uses the .1.0 release of that major, since patch releases have no page', () => { | ||
| strictEqual( | ||
| getClangTidyDocumentationUrl('checks/readability/use-std-min-max.html', '23.1.1'), | ||
| 'https://releases.llvm.org/23.1.0/tools/clang/tools/extra/docs/clang-tidy/checks/readability/use-std-min-max.html'); | ||
| strictEqual( | ||
| getClangTidyDocumentationUrl('checks/misc/include-cleaner.html', '22.1.3'), | ||
| 'https://releases.llvm.org/22.1.0/tools/clang/tools/extra/docs/clang-tidy/checks/misc/include-cleaner.html'); | ||
| }); | ||
|
|
||
| it('falls back to the bundled version when the version in use is unknown', () => { | ||
| strictEqual(getClangTidyDocumentationUrl('checks/misc/include-cleaner.html'), `${bundledDocUrl}/checks/misc/include-cleaner.html`); | ||
| strictEqual(getClangTidyDocumentationUrl('checks/misc/include-cleaner.html', ''), `${bundledDocUrl}/checks/misc/include-cleaner.html`); | ||
| strictEqual(getClangTidyDocumentationUrl('checks/misc/include-cleaner.html', '23.1'), `${bundledDocUrl}/checks/misc/include-cleaner.html`); | ||
| }); | ||
|
|
||
| it('keeps the fallback on the release the bundled binary belongs to', () => { | ||
| // The fallback is only correct while it matches what the bundled clang-tidy would produce, | ||
| // which is the point of deriving it from the bundled version instead of a literal URL. | ||
| strictEqual( | ||
| getClangTidyDocumentationUrl('checks/misc/include-cleaner.html', bundledClangTidyVersion), | ||
| getClangTidyDocumentationUrl('checks/misc/include-cleaner.html')); | ||
| }); | ||
| }); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
You are right, and this one was mine. The action was stored on the code, so the first folder to report a code decided the release for every folder and the URL never moved when the path or version changed. It now lives on the diagnostic, which already knows the resource, and the provider keeps one action per target URL so a shared code does not produce duplicates.