From 2ef52e46b1ae62cc7934ea6cc9c8780f07c0be14 Mon Sep 17 00:00:00 2001 From: davidramnero Date: Thu, 27 Aug 2026 15:56:08 +0200 Subject: [PATCH] fix / dont show inline suppression code action for multiple location warning --- src/util/codeActions.ts | 43 +++++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/src/util/codeActions.ts b/src/util/codeActions.ts index 41c1017..96c45ca 100644 --- a/src/util/codeActions.ts +++ b/src/util/codeActions.ts @@ -28,6 +28,9 @@ export class CodeActionProvider implements vscode.CodeActionProvider { const lineText = document.lineAt(mainLocLineNumber).text; const expectedLineText = this.metadataStore.get(diagnostic)?.mainLocLine; + // Additional locations are stored in the relatedInformation field + const multipleLocationWarning = (diagnostic.relatedInformation?.length ?? 0 ) > 0; + // If document has been edited so that diagnostic no longer refers to the correct line we don't provide code actions if (lineText !== expectedLineText) { continue; @@ -47,26 +50,28 @@ export class CodeActionProvider implements vscode.CodeActionProvider { // Copy indentation from line affected by diagnostic const indent = lineText.match(/^\s*/)?.[0] ?? ""; - // Insert suppression comment above affected line - const suppressLineEdit = new vscode.WorkspaceEdit(); - suppressLineEdit.insert( - document.uri, - new vscode.Position( - diagnostic.range.start.line, - 0, - ), - `${indent}// cppcheck-suppress ${diagnosticCode}\n` - ); - suppressAction.edit = suppressLineEdit; + if (!multipleLocationWarning) { + // Insert suppression comment above affected line + const suppressLineEdit = new vscode.WorkspaceEdit(); + suppressLineEdit.insert( + document.uri, + new vscode.Position( + diagnostic.range.start.line, + 0, + ), + `${indent}// cppcheck-suppress ${diagnosticCode}\n` + ); + suppressAction.edit = suppressLineEdit; - // For inline suppression we also hide the warning so user does not have to rerun analysis for it to disappear - suppressAction.command = { - command: "cppcheck-official.hideWarning", - title: "Hide warning", - arguments: [document.uri, diagnosticCode, diagnostic.range] - }; - suppressAction.diagnostics = [diagnostic]; - actions.push(suppressAction); + // For inline suppression we also hide the warning so user does not have to rerun analysis for it to disappear + suppressAction.command = { + command: "cppcheck-official.hideWarning", + title: "Hide warning", + arguments: [document.uri, diagnosticCode, diagnostic.range] + }; + suppressAction.diagnostics = [diagnostic]; + actions.push(suppressAction); + } // Set up an action for hiding a warning const hideAction = new vscode.CodeAction(