diff --git a/README.md b/README.md index ab2667d..9e65e18 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ - **Configurable severity threshold**: Filter out messages below a chosen severity level (`info`, `warning`, or `error`). - **Set C/C++ standard**: Easily specify `--std=` (e.g. `c++17`, `c99`, etc.). - **Diagnostic cleanup**: When you close a file, its diagnostics are automatically cleared. - +- **Project file support**: You can feed your project file to cppcheck through the `--project` flag in the `cppcheck-official.arguments` field in the extension settings. ## Requirements **Cppcheck** must be installed on your system. diff --git a/src/extension.ts b/src/extension.ts index f449756..a6fce95 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -192,16 +192,28 @@ async function runCppcheckOnFileXML( return arg; }); - const args = [ - '--enable=all', - '--xml', - '--xml-version=2', - standardArg, - ...extraArgsParsed, - filePath.replace(/\\/g, '/') - ].filter(Boolean); - - const proc = cp.spawn(commandPath, args); + let proc; + if (extraArgs.includes("--project")) { + const args = [ + '--enable=all', + '--xml', + '--xml-version=2', + `--file-filter=${filePath.replace(/\\/g, '/')}`, + standardArg, + ...extraArgsParsed + ].filter(Boolean); + proc = cp.spawn(commandPath, args); + } else { + const args = [ + '--enable=all', + '--xml', + '--xml-version=2', + standardArg, + ...extraArgsParsed, + filePath.replace(/\\/g, '/') + ].filter(Boolean); + proc = cp.spawn(commandPath, args); + } // if spawn fails (e.g. ENOENT or permission denied) proc.on("error", (err) => {