From 3aff7b33e4b1550a1008583ec7762692a9ade584 Mon Sep 17 00:00:00 2001 From: davidramnero Date: Sat, 13 Dec 2025 16:23:07 +0100 Subject: [PATCH 1/4] fix #33 show critical warnings with location other than checked file --- src/extension.ts | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index 65b6144..dc3f640 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -10,6 +10,23 @@ enum SeverityNumber { Error = 2 } +const criticalWarningTypes = [ + 'cppcheckError', + 'cppcheckLimit', + 'includeNestedTooDeeply', + 'internalAstError', + 'instantiationError', + 'internalError', + 'missingFile', + 'premium-internalError', + 'premium-invalidArgument', + 'premium-invalidLicense', + 'preprocessorErrorDirective', + 'syntaxError', + 'unhandledChar', + 'unknownMacro' +]; + function parseSeverity(str: string): vscode.DiagnosticSeverity { const lower = str.toLowerCase(); if (lower.includes("error")) { @@ -257,9 +274,9 @@ async function runCppcheckOnFileXML( } const mainLoc = locations[locations.length - 1].$; - - // If main location is not current file, then skip displaying warning - if (!filePath.endsWith(mainLoc.file)) { + console.log('error id ', e.$.id, 'error', e); + // If main location is not current file, then skip displaying warning unless it is critical + if (!filePath.endsWith(mainLoc.file) && !criticalWarningTypes.includes(e.$.id)) { continue; } From 4a42638a13e9732280a86f813249069f1368ff04 Mon Sep 17 00:00:00 2001 From: davidramnero Date: Sat, 13 Dec 2025 16:37:50 +0100 Subject: [PATCH 2/4] pass by checks on line numbers etc if error is critical --- src/extension.ts | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index dc3f640..17f6074 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -266,25 +266,29 @@ async function runCppcheckOnFileXML( const errors = result.results?.errors?.[0]?.error || []; const diagnostics: vscode.Diagnostic[] = []; - for (const e of errors) { + const isCriticalError = criticalWarningTypes.includes(e.$.id); const locations = e.location || []; if (!locations.length) { continue; } const mainLoc = locations[locations.length - 1].$; - console.log('error id ', e.$.id, 'error', e); + // If main location is not current file, then skip displaying warning unless it is critical - if (!filePath.endsWith(mainLoc.file) && !criticalWarningTypes.includes(e.$.id)) { + if (!isCriticalError && !filePath.endsWith(mainLoc.file)) { continue; } // Cppcheck line number is 1-indexed, while VS Code uses 0-indexing - const line = Number(mainLoc.line) - 1; + let line = Number(mainLoc.line) - 1; // Invalid line number usually means non-analysis output if (isNaN(line) || line < 0 || line >= document.lineCount) { - continue; + if (isCriticalError) { + line = 0; + } else { + continue; + } } // Cppcheck col number is 1-indexed, while VS Code uses 0-indexing @@ -294,7 +298,7 @@ async function runCppcheckOnFileXML( } const severity = parseSeverity(e.$.severity); - if (severityToNumber(severity) < minSevNum) { + if (!isCriticalError && severityToNumber(severity) < minSevNum) { continue; } @@ -302,7 +306,6 @@ async function runCppcheckOnFileXML( const diagnostic = new vscode.Diagnostic(range, e.$.msg, severity); diagnostic.source = "cppcheck"; diagnostic.code = e.$.id; - // Related Information const relatedInfos: vscode.DiagnosticRelatedInformation[] = []; for (let i = 1; i <= locations.length; i++) { From f35f4c6a996273ac3669770431b0fb45a0387855 Mon Sep 17 00:00:00 2001 From: davidramnero Date: Sat, 13 Dec 2025 16:38:41 +0100 Subject: [PATCH 3/4] restore removed white space --- src/extension.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/extension.ts b/src/extension.ts index 17f6074..d8f40c8 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -266,6 +266,7 @@ async function runCppcheckOnFileXML( const errors = result.results?.errors?.[0]?.error || []; const diagnostics: vscode.Diagnostic[] = []; + for (const e of errors) { const isCriticalError = criticalWarningTypes.includes(e.$.id); const locations = e.location || []; From fbef60896f80d015e65a107de62ef78934ffb349 Mon Sep 17 00:00:00 2001 From: davidramnero Date: Sat, 13 Dec 2025 16:39:53 +0100 Subject: [PATCH 4/4] restore another white space --- src/extension.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/extension.ts b/src/extension.ts index d8f40c8..1c6a0e3 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -307,6 +307,7 @@ async function runCppcheckOnFileXML( const diagnostic = new vscode.Diagnostic(range, e.$.msg, severity); diagnostic.source = "cppcheck"; diagnostic.code = e.$.id; + // Related Information const relatedInfos: vscode.DiagnosticRelatedInformation[] = []; for (let i = 1; i <= locations.length; i++) {