@@ -28,6 +28,9 @@ export class CodeActionProvider implements vscode.CodeActionProvider {
2828 const lineText = document . lineAt ( mainLocLineNumber ) . text ;
2929 const expectedLineText = this . metadataStore . get ( diagnostic ) ?. mainLocLine ;
3030
31+ // Additional locations are stored in the relatedInformation field
32+ const multipleLocationWarning = ( diagnostic . relatedInformation ?. length ?? 0 ) > 0 ;
33+
3134 // If document has been edited so that diagnostic no longer refers to the correct line we don't provide code actions
3235 if ( lineText !== expectedLineText ) {
3336 continue ;
@@ -47,26 +50,28 @@ export class CodeActionProvider implements vscode.CodeActionProvider {
4750 // Copy indentation from line affected by diagnostic
4851 const indent = lineText . match ( / ^ \s * / ) ?. [ 0 ] ?? "" ;
4952
50- // Insert suppression comment above affected line
51- const suppressLineEdit = new vscode . WorkspaceEdit ( ) ;
52- suppressLineEdit . insert (
53- document . uri ,
54- new vscode . Position (
55- diagnostic . range . start . line ,
56- 0 ,
57- ) ,
58- `${ indent } // cppcheck-suppress ${ diagnosticCode } \n`
59- ) ;
60- suppressAction . edit = suppressLineEdit ;
53+ if ( ! multipleLocationWarning ) {
54+ // Insert suppression comment above affected line
55+ const suppressLineEdit = new vscode . WorkspaceEdit ( ) ;
56+ suppressLineEdit . insert (
57+ document . uri ,
58+ new vscode . Position (
59+ diagnostic . range . start . line ,
60+ 0 ,
61+ ) ,
62+ `${ indent } // cppcheck-suppress ${ diagnosticCode } \n`
63+ ) ;
64+ suppressAction . edit = suppressLineEdit ;
6165
62- // For inline suppression we also hide the warning so user does not have to rerun analysis for it to disappear
63- suppressAction . command = {
64- command : "cppcheck-official.hideWarning" ,
65- title : "Hide warning" ,
66- arguments : [ document . uri , diagnosticCode , diagnostic . range ]
67- } ;
68- suppressAction . diagnostics = [ diagnostic ] ;
69- actions . push ( suppressAction ) ;
66+ // For inline suppression we also hide the warning so user does not have to rerun analysis for it to disappear
67+ suppressAction . command = {
68+ command : "cppcheck-official.hideWarning" ,
69+ title : "Hide warning" ,
70+ arguments : [ document . uri , diagnosticCode , diagnostic . range ]
71+ } ;
72+ suppressAction . diagnostics = [ diagnostic ] ;
73+ actions . push ( suppressAction ) ;
74+ }
7075
7176 // Set up an action for hiding a warning
7277 const hideAction = new vscode . CodeAction (
0 commit comments