From cbdd4b2f83628aed4ccca583e2b29bd3b9075316 Mon Sep 17 00:00:00 2001 From: davidramnero Date: Tue, 25 Nov 2025 21:10:53 +0200 Subject: [PATCH 1/3] fix#23: the col is always 1 --- src/extension.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/extension.ts b/src/extension.ts index 5629a6e..e68301c 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -268,12 +268,19 @@ async function runCppcheckOnFileXML( continue; } + let col = Number(mainLoc.column) - 1; + console.log('column # ', mainLoc); + // Invalid line number usually means non-analysis output + if (isNaN(col) || col < 0 || col > document.lineAt(line).text.length) { + col = 1; + } + const severity = parseSeverity(e.$.severity); if (severityToNumber(severity) < minSevNum) { continue; } - const range = new vscode.Range(line, 0, line, document.lineAt(line).text.length); + 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; From dd71626af1af0b35ee86baf35a68455fb385e1c3 Mon Sep 17 00:00:00 2001 From: davidramnero Date: Tue, 25 Nov 2025 21:12:51 +0200 Subject: [PATCH 2/3] remove incorrect comment about col processing from analysis --- src/extension.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index e68301c..8464767 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -269,8 +269,6 @@ async function runCppcheckOnFileXML( } let col = Number(mainLoc.column) - 1; - console.log('column # ', mainLoc); - // Invalid line number usually means non-analysis output if (isNaN(col) || col < 0 || col > document.lineAt(line).text.length) { col = 1; } From 3bb6b27ad23a9fd7bcd463fa60da9f2223e70a68 Mon Sep 17 00:00:00 2001 From: davidramnero Date: Tue, 25 Nov 2025 21:23:51 +0200 Subject: [PATCH 3/3] updated fallback value and incorrect comments --- src/extension.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index 8464767..5e3834d 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -254,7 +254,6 @@ async function runCppcheckOnFileXML( continue; } - // Cppcheck line number is 1-indexed, while VS Code uses 0-indexing const mainLoc = locations[locations.length - 1].$; // If main location is not current file, then skip displaying warning @@ -262,15 +261,17 @@ async function runCppcheckOnFileXML( continue; } + // Cppcheck line number is 1-indexed, while VS Code uses 0-indexing const line = Number(mainLoc.line) - 1; // Invalid line number usually means non-analysis output if (isNaN(line) || line < 0 || line >= document.lineCount) { continue; } + // Cppcheck col number is 1-indexed, while VS Code uses 0-indexing let col = Number(mainLoc.column) - 1; if (isNaN(col) || col < 0 || col > document.lineAt(line).text.length) { - col = 1; + col = 0; } const severity = parseSeverity(e.$.severity);