Skip to content

Commit 355f12b

Browse files
authored
feature/cppcheck documentation links (#52)
1 parent a146fc0 commit 355f12b

2 files changed

Lines changed: 22 additions & 1 deletion

File tree

src/extension.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as cp from 'child_process';
33
import * as path from "path";
44
import * as xml2js from 'xml2js';
55

6+
import { documentationLinkMap } from './util/documentation';
67
import { runCommand } from './util/scripts';
78
import { resolvePath, findWorkspaceRoot } from './util/path';
89

@@ -294,7 +295,11 @@ async function runCppcheckOnFileXML(
294295
const range = new vscode.Range(line, col, line, document.lineAt(line).text.length);
295296
const diagnostic = new vscode.Diagnostic(range, e.$.msg, severity);
296297
diagnostic.source = "cppcheck";
297-
diagnostic.code = e.$.id;
298+
// If we have a link to documentation, include it
299+
diagnostic.code = documentationLinkMap[e.$.id] ? {
300+
value: e.$.id,
301+
target: vscode.Uri.parse(documentationLinkMap[e.$.id])
302+
} : e.$.id;
298303

299304
// Related Information
300305
const relatedInfos: vscode.DiagnosticRelatedInformation[] = [];

src/util/documentation.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const documentationLinkMap : Record<string, string> = {
2+
'constParameterPointer': 'https://github.com/cppcheck-opensource/cppcheck/blob/main/man/checkers/constParameterPointer.md',
3+
'cstyleCast': 'https://github.com/cppcheck-opensource/cppcheck/blob/main/man/checkers/cstyleCast.md',
4+
'dangerousTypeCast': 'https://github.com/cppcheck-opensource/cppcheck/blob/main/man/checkers/dangerousTypeCast.md',
5+
'duplicateExpressionTernary': 'https://github.com/cppcheck-opensource/cppcheck/blob/main/man/checkers/duplicateExpressionTernary.md',
6+
'duplicateValueTernary': 'https://github.com/cppcheck-opensource/cppcheck/blob/main/man/checkers/duplicateValueTernary.md',
7+
'fcloseInLoopCondition': 'https://github.com/cppcheck-opensource/cppcheck/blob/main/man/checkers/fcloseInLoopCondition.md',
8+
'functionConst': 'https://github.com/cppcheck-opensource/cppcheck/blob/main/man/checkers/functionConst.md',
9+
'functionStatic': 'https://github.com/cppcheck-opensource/cppcheck/blob/main/man/checkers/functionStatic.md',
10+
'premium-misra-config': 'https://github.com/cppcheck-opensource/cppcheck/blob/main/man/checkers/premium-misra-config.md',
11+
'preprocessorErrorDirective': 'https://github.com/cppcheck-opensource/cppcheck/blob/main/man/checkers/preprocessorErrorDirective.md',
12+
'truncLongCast': 'https://github.com/cppcheck-opensource/cppcheck/blob/main/man/checkers/truncLongCast.md',
13+
'unknownMacro': 'https://github.com/cppcheck-opensource/cppcheck/blob/main/man/checkers/unknownMacro.md',
14+
};
15+
16+
export { documentationLinkMap };

0 commit comments

Comments
 (0)