From 57ac2b7a08888b0e2a6a6f73bf7751f33fdb461c Mon Sep 17 00:00:00 2001 From: davidramnero Date: Tue, 19 May 2026 11:41:14 +0200 Subject: [PATCH] feature/cppcheck documentation links --- src/extension.ts | 7 ++++++- src/util/documentation.ts | 16 ++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 src/util/documentation.ts diff --git a/src/extension.ts b/src/extension.ts index ed7e3bb..0c6524a 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -3,6 +3,7 @@ import * as cp from 'child_process'; import * as path from "path"; import * as xml2js from 'xml2js'; +import { documentationLinkMap } from './util/documentation'; import { runCommand } from './util/scripts'; import { resolvePath, findWorkspaceRoot } from './util/path'; @@ -294,7 +295,11 @@ async function runCppcheckOnFileXML( const range = new vscode.Range(line, col, line, document.lineAt(line).text.length); const diagnostic = new vscode.Diagnostic(range, e.$.msg, severity); diagnostic.source = "cppcheck"; - diagnostic.code = e.$.id; + // If we have a link to documentation, include it + diagnostic.code = documentationLinkMap[e.$.id] ? { + value: e.$.id, + target: vscode.Uri.parse(documentationLinkMap[e.$.id]) + } : e.$.id; // Related Information const relatedInfos: vscode.DiagnosticRelatedInformation[] = []; diff --git a/src/util/documentation.ts b/src/util/documentation.ts new file mode 100644 index 0000000..5518a5b --- /dev/null +++ b/src/util/documentation.ts @@ -0,0 +1,16 @@ +const documentationLinkMap : Record = { + 'constParameterPointer': 'https://github.com/cppcheck-opensource/cppcheck/blob/main/man/checkers/constParameterPointer.md', + 'cstyleCast': 'https://github.com/cppcheck-opensource/cppcheck/blob/main/man/checkers/cstyleCast.md', + 'dangerousTypeCast': 'https://github.com/cppcheck-opensource/cppcheck/blob/main/man/checkers/dangerousTypeCast.md', + 'duplicateExpressionTernary': 'https://github.com/cppcheck-opensource/cppcheck/blob/main/man/checkers/duplicateExpressionTernary.md', + 'duplicateValueTernary': 'https://github.com/cppcheck-opensource/cppcheck/blob/main/man/checkers/duplicateValueTernary.md', + 'fcloseInLoopCondition': 'https://github.com/cppcheck-opensource/cppcheck/blob/main/man/checkers/fcloseInLoopCondition.md', + 'functionConst': 'https://github.com/cppcheck-opensource/cppcheck/blob/main/man/checkers/functionConst.md', + 'functionStatic': 'https://github.com/cppcheck-opensource/cppcheck/blob/main/man/checkers/functionStatic.md', + 'premium-misra-config': 'https://github.com/cppcheck-opensource/cppcheck/blob/main/man/checkers/premium-misra-config.md', + 'preprocessorErrorDirective': 'https://github.com/cppcheck-opensource/cppcheck/blob/main/man/checkers/preprocessorErrorDirective.md', + 'truncLongCast': 'https://github.com/cppcheck-opensource/cppcheck/blob/main/man/checkers/truncLongCast.md', + 'unknownMacro': 'https://github.com/cppcheck-opensource/cppcheck/blob/main/man/checkers/unknownMacro.md', +}; + +export { documentationLinkMap }; \ No newline at end of file