@@ -8,6 +8,7 @@ import { runCommand } from './util/scripts';
88import { looksLikePath , resolvePath , findWorkspaceRoot } from './util/path' ;
99import { diagnosticsUnion } from './util/diagnostics' ;
1010import { CodeActionProvider } from './util/codeActions' ;
11+ import { writeSuppressionToProjectFile } from './util/files' ;
1112
1213// To keep track of document changes we save hashed versions of their content to this record
1314let documentHashMemory : Record < string , string > = { } ;
@@ -18,6 +19,7 @@ let previewAnalysisTimer: NodeJS.Timeout | undefined;
1819let previewedDocument : vscode . TextDocument | undefined ;
1920let cppcheckProgressIndicator : vscode . StatusBarItem ;
2021let checksRunning = false ;
22+ let cppcheckProjectFileUri : vscode . Uri | undefined ;
2123
2224enum SeverityNumber {
2325 Info = 0 ,
@@ -96,6 +98,7 @@ function getDocumentSha1(document: vscode.TextDocument): string {
9698// This method is called when your extension is activated.
9799// Your extension is activated the very first time the command is executed.
98100export async function activate ( context : vscode . ExtensionContext ) {
101+ // Set up code actions provider
99102 context . subscriptions . push (
100103 vscode . languages . registerCodeActionsProvider (
101104 { pattern : "**/*" } ,
@@ -125,8 +128,12 @@ export async function activate(context: vscode.ExtensionContext) {
125128 context . subscriptions . push (
126129 vscode . commands . registerCommand (
127130 "cppcheck-official.suppressWarningAll" ,
128- ( diagnostic : vscode . Diagnostic ) => {
129- console . log ( "Suppress" , diagnostic ) ;
131+ async ( warningType : String ) => {
132+ if ( cppcheckProjectFileUri ) {
133+ await writeSuppressionToProjectFile ( cppcheckProjectFileUri , warningType ) ;
134+ } else {
135+ vscode . window . showInformationMessage ( `Adding suppression is currently only supported for .cppcheck project files` ) ;
136+ }
130137 }
131138 )
132139 ) ;
@@ -321,6 +328,8 @@ async function runCppcheckOnFileXML(
321328 } ) ;
322329
323330 let usingProjectFile = false ;
331+ cppcheckProjectFileUri = undefined ;
332+
324333 const args = [
325334 '--enable=all' ,
326335 '--inline-suppr' ,
@@ -330,9 +339,16 @@ async function runCppcheckOnFileXML(
330339 '--suppress=missingIncludeSystem' ,
331340 ...argsParsed ,
332341 ] . filter ( Boolean ) ;
342+
333343 if ( processedArgs . includes ( "--project" ) ) {
334344 usingProjectFile = true ;
335345 args . push ( `--file-filter=${ filePath } ` ) ;
346+ // If project file is of type .cppcheck we keep track of it
347+ var projectFilePath = processedArgs . split ( '--project=' ) [ 1 ] . split ( ' ' ) [ 0 ] ;
348+ var projectFileType = projectFilePath . split ( '.' ) [ 1 ] ;
349+ if ( projectFileType . toLowerCase ( ) === 'cppcheck' ) {
350+ cppcheckProjectFileUri = vscode . Uri . file ( projectFilePath ) ;
351+ }
336352 } else {
337353 args . push ( filePath ) ;
338354 }
0 commit comments