Skip to content

Commit 1da15eb

Browse files
committed
Use the clang-tidy version in use for check documentation links
1 parent e38cfef commit 1da15eb

6 files changed

Lines changed: 69 additions & 3 deletions

File tree

‎Extension/CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
* Reduce CPU usage when resolving headers in large Windows workspaces.
1616

1717
### Bug Fixes
18+
* Fix clang-tidy check documentation links pointing at the bundled LLVM release instead of the clang-tidy version in use. [#12804](https://github.com/microsoft/vscode-cpptools/issues/12804)
1819
* Fix 'Go to Declaration' and 'Go to Definition' returning the current location instead of an available counterpart. [#14509](https://github.com/microsoft/vscode-cpptools/issues/14509)
1920
* Update MIEngine to fix debugger failures with synthetic GDB stack frames. [#14741](https://github.com/microsoft/vscode-cpptools/issues/14741)
2021
* Thanks for the contribution. [@tzcnt](https://github.com/tzcnt) [PR MIEngine#1605](https://github.com/microsoft/MIEngine/pull/1605)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/* --------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All Rights Reserved.
3+
* See 'LICENSE' in the project root for license information.
4+
* ------------------------------------------------------------------------------------------ */
5+
6+
/**
7+
* The clang-tidy documentation is published for every LLVM release, so the URL of a check's
8+
* page depends on the release the clang-tidy binary in use comes from. Checks added in a
9+
* newer release have no page at all in an older one. When the version in use could not be
10+
* determined, fall back to the release bundled with the extension.
11+
*/
12+
export const fallbackClangTidyDocVersion: string = '23.1.0';
13+
14+
const versionPattern: RegExp = /^[0-9]+\.[0-9]+\.[0-9]+$/;
15+
16+
export function getClangTidyDocumentationUrl(docPage: string, clangTidyVersion?: string): string {
17+
const version: string = clangTidyVersion && versionPattern.test(clangTidyVersion) ? clangTidyVersion : fallbackClangTidyDocVersion;
18+
return `https://releases.llvm.org/${version}/tools/clang/tools/extra/docs/clang-tidy/${docPage}`;
19+
}

‎Extension/src/LanguageServer/codeAnalysis.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import * as vscode from 'vscode';
77
import { NotificationType, Range } from 'vscode-languageclient';
88
import * as nls from 'vscode-nls';
9+
import { getClangTidyDocumentationUrl } from './clangTidyDocumentation';
910
import { Location, WorkspaceEdit } from './commonTypes';
1011
import { CppSourceStr } from './extension';
1112
import { LanguageClient } from './languageClient';
@@ -379,8 +380,7 @@ export function publishCodeAnalysisDiagnostics(params: PublishCodeAnalysisDiagno
379380
const checksPage: string = dashIndex > 0 ? primaryCode.substring(dashIndex + 1) : primaryCode;
380381
docPage = `checks${checksGroup}/${checksPage}.html`;
381382
}
382-
// TODO: This should be checking the clang-tidy version used to better support usage of older versions.
383-
const primaryDocUri: vscode.Uri = vscode.Uri.parse(`https://releases.llvm.org/23.1.0/tools/clang/tools/extra/docs/clang-tidy/${docPage}`);
383+
const primaryDocUri: vscode.Uri = vscode.Uri.parse(getClangTidyDocumentationUrl(docPage, new CppSettings().clangTidyVersion));
384384
diagnostic.code = { value: identifier.code, target: primaryDocUri };
385385

386386
if (new CppSettings().clangTidyCodeActionShowDocumentation) {

‎Extension/src/LanguageServer/settings.ts‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import * as vscode from 'vscode';
1212
import * as nls from 'vscode-nls';
1313
import * as which from 'which';
1414
import * as util from '../common';
15-
import { getCachedClangFormatPath, getCachedClangTidyPath, getExtensionFilePath, getRawSetting, isArray, isArrayOfString, isBoolean, isNumber, isObject, isString, isValidMapping, setCachedClangFormatPath, setCachedClangTidyPath } from '../common';
15+
import { getCachedClangFormatPath, getCachedClangTidyPath, getCachedClangTidyVersion, getExtensionFilePath, getRawSetting, isArray, isArrayOfString, isBoolean, isNumber, isObject, isString, isValidMapping, setCachedClangFormatPath, setCachedClangTidyPath, setCachedClangTidyVersion } from '../common';
1616
import { isWindows } from '../constants';
1717
import * as telemetry from '../telemetry';
1818
import { cachedEditorConfigLookups, DefaultClient, hasTrustedCompilerPaths } from './client';
@@ -279,6 +279,10 @@ export class CppSettings extends Settings {
279279
return this.getClangPath(false);
280280
}
281281

282+
public get clangTidyVersion(): string | undefined {
283+
return getCachedClangTidyVersion();
284+
}
285+
282286
public get clangFormatPath(): string | undefined {
283287
return this.getClangPath(true);
284288
}
@@ -303,6 +307,7 @@ export class CppSettings extends Settings {
303307
} else {
304308
// Attempt to invoke both our own version of clang-* to see if we can successfully execute it, and to get its version.
305309
let bundledVersion: string;
310+
let clangVersion: string | undefined;
306311
try {
307312
const bundledPath: string = getExtensionFilePath(`./LLVM/bin/${clangName}`);
308313
const output: string = execFileSync(bundledPath, ['--version']).toString();
@@ -322,10 +327,18 @@ export class CppSettings extends Settings {
322327
if (semver.ltr(userVersion, bundledVersion)) {
323328
path = "";
324329
setCachedClangPath(path);
330+
clangVersion = bundledVersion;
331+
} else {
332+
clangVersion = userVersion;
325333
}
326334
} catch {
327335
path = "";
328336
setCachedClangPath(path);
337+
clangVersion = bundledVersion;
338+
}
339+
340+
if (!isFormat && clangVersion) {
341+
setCachedClangTidyVersion(clangVersion);
329342
}
330343
}
331344
}

‎Extension/src/common.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,15 @@ export function setCachedClangTidyPath(path: string): void {
6060
cachedClangTidyPath = path;
6161
}
6262

63+
let cachedClangTidyVersion: string | undefined;
64+
export function getCachedClangTidyVersion(): string | undefined {
65+
return cachedClangTidyVersion;
66+
}
67+
68+
export function setCachedClangTidyVersion(version: string): void {
69+
cachedClangTidyVersion = version;
70+
}
71+
6372
// Use this package.json to read values
6473
export const packageJson: any = vscode.extensions.getExtension("ms-vscode.cpptools")?.packageJSON;
6574

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/* --------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All Rights Reserved.
3+
* See 'LICENSE' in the project root for license information.
4+
* ------------------------------------------------------------------------------------------ */
5+
6+
import { describe, it } from 'mocha';
7+
import { strictEqual } from 'node:assert';
8+
import { fallbackClangTidyDocVersion, getClangTidyDocumentationUrl } from '../../src/LanguageServer/clangTidyDocumentation';
9+
10+
const bundledDocUrl: string = `https://releases.llvm.org/${fallbackClangTidyDocVersion}/tools/clang/tools/extra/docs/clang-tidy`;
11+
12+
describe('clang-tidy documentation URLs', () => {
13+
it('points at the clang-tidy version in use', () => {
14+
strictEqual(
15+
getClangTidyDocumentationUrl('checks/readability/use-std-min-max.html', '19.1.0'),
16+
'https://releases.llvm.org/19.1.0/tools/clang/tools/extra/docs/clang-tidy/checks/readability/use-std-min-max.html');
17+
});
18+
19+
it('falls back to the bundled version when the version in use is unknown', () => {
20+
strictEqual(getClangTidyDocumentationUrl('checks/misc/include-cleaner.html'), `${bundledDocUrl}/checks/misc/include-cleaner.html`);
21+
strictEqual(getClangTidyDocumentationUrl('checks/misc/include-cleaner.html', ''), `${bundledDocUrl}/checks/misc/include-cleaner.html`);
22+
strictEqual(getClangTidyDocumentationUrl('checks/misc/include-cleaner.html', '23.1'), `${bundledDocUrl}/checks/misc/include-cleaner.html`);
23+
});
24+
});

0 commit comments

Comments
 (0)