From 1ab06df59d2ab8cc3b9c569f4430c00c4409ce66 Mon Sep 17 00:00:00 2001 From: davidramnero Date: Thu, 27 Aug 2026 22:30:21 +0200 Subject: [PATCH 1/2] fix / place inline suppression where it will actually work for multi-location warnings --- src/util/codeActions.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/util/codeActions.ts b/src/util/codeActions.ts index 41c1017..283c5c7 100644 --- a/src/util/codeActions.ts +++ b/src/util/codeActions.ts @@ -47,12 +47,22 @@ export class CodeActionProvider implements vscode.CodeActionProvider { // Copy indentation from line affected by diagnostic const indent = lineText.match(/^\s*/)?.[0] ?? ""; + var affectedLine = diagnostic.range.start.line; + + // Due to a quirk in cppcheck, even though last location for a multiple location warning is considered 'main location', + // inline suppression should be added to the 1st location (reversed order in diagnostic relatedInformation) + const multipleLocationWarning = (diagnostic.relatedInformation?.length ?? 0 ) > 0; + if (multipleLocationWarning && diagnostic?.relatedInformation?.[0]) { + const lastLocation = diagnostic?.relatedInformation?.[diagnostic?.relatedInformation?.length - 1].location; + affectedLine = lastLocation.range.start.line; + } + // Insert suppression comment above affected line const suppressLineEdit = new vscode.WorkspaceEdit(); suppressLineEdit.insert( document.uri, new vscode.Position( - diagnostic.range.start.line, + affectedLine, 0, ), `${indent}// cppcheck-suppress ${diagnosticCode}\n` From 1139128a35b31e60df97d2b51a912214c31726e9 Mon Sep 17 00:00:00 2001 From: davidramnero Date: Fri, 28 Aug 2026 08:30:22 +0200 Subject: [PATCH 2/2] make sure inline suppression is added to correct file --- src/util/codeActions.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/util/codeActions.ts b/src/util/codeActions.ts index 283c5c7..f65877d 100644 --- a/src/util/codeActions.ts +++ b/src/util/codeActions.ts @@ -48,19 +48,21 @@ export class CodeActionProvider implements vscode.CodeActionProvider { const indent = lineText.match(/^\s*/)?.[0] ?? ""; var affectedLine = diagnostic.range.start.line; + var documentUri = document.uri; // Due to a quirk in cppcheck, even though last location for a multiple location warning is considered 'main location', // inline suppression should be added to the 1st location (reversed order in diagnostic relatedInformation) const multipleLocationWarning = (diagnostic.relatedInformation?.length ?? 0 ) > 0; if (multipleLocationWarning && diagnostic?.relatedInformation?.[0]) { const lastLocation = diagnostic?.relatedInformation?.[diagnostic?.relatedInformation?.length - 1].location; + documentUri = lastLocation.uri; affectedLine = lastLocation.range.start.line; } // Insert suppression comment above affected line const suppressLineEdit = new vscode.WorkspaceEdit(); suppressLineEdit.insert( - document.uri, + documentUri, new vscode.Position( affectedLine, 0,