From 5626ce8358cd438dc4ce8cde143dbb7934ecbfa4 Mon Sep 17 00:00:00 2001 From: davidramnero Date: Tue, 9 Jun 2026 12:28:53 +0200 Subject: [PATCH 1/2] cleaner flow for starting client --- src/extension.ts | 43 ++++++++++++++----------------------------- 1 file changed, 14 insertions(+), 29 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index 047b2d0..4ca5e63 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -205,37 +205,22 @@ async function runCppcheckOnFileXML( }); let proc; + const args = [ + '--enable=all', + '--inline-suppr', + '--xml', + '--suppress=unusedFunction', + '--suppress=missingInclude', + '--suppress=missingIncludeSystem', + ...argsParsed, + ].filter(Boolean); if (processedArgs.includes("--project")) { - const args = [ - '--enable=all', - '--inline-suppr', - '--xml', - '--suppress=unusedFunction', - '--suppress=missingInclude', - '--suppress=missingIncludeSystem', - `--file-filter=${filePath}`, - ...argsParsed, - ].filter(Boolean); - proc = cp.spawn(commandPath, args, { - cwd: path.dirname(document.fileName), - }); - } else { - const args = [ - '--enable=all', - '--inline-suppr', - '--xml', - '--suppress=unusedFunction', - '--suppress=missingInclude', - '--suppress=missingIncludeSystem', - ...argsParsed, - filePath, - ].filter(Boolean); - - const cwd = findWorkspaceRoot(); - proc = cp.spawn(commandPath, args, { - cwd, - }); + args.push(`--file-filter=${filePath}`); } + const cwd = findWorkspaceRoot(); + proc = cp.spawn(commandPath, args, { + cwd, + }); // if spawn fails (e.g. ENOENT or permission denied) proc.on("error", (err) => { From 2cdebc032fe1d768c87cfda76fea52155429e69f Mon Sep 17 00:00:00 2001 From: davidramnero Date: Tue, 9 Jun 2026 14:15:38 +0200 Subject: [PATCH 2/2] handle array input --- src/extension.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index 4ca5e63..4b1a2c6 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -1,6 +1,5 @@ import * as vscode from 'vscode'; import * as cp from 'child_process'; -import * as path from "path"; import * as xml2js from 'xml2js'; import { documentationLinkMap } from './util/documentation'; @@ -100,6 +99,11 @@ export async function activate(context: vscode.ExtensionContext) { const commandPath = userPath ? resolvePath(userPath) : "cppcheck"; var args = config.get("cppcheck-official.arguments", ""); + // If user enter arguments as array we parse them into space separated string format + if (args.startsWith("[") && args.endsWith("]")) { + args = args.replaceAll("[", "").replaceAll("]", "").replaceAll(",", " "); + } + var processedArgs = ''; // If argument field contains command to run script we do so here if (args.includes('@(')) { @@ -195,10 +199,11 @@ async function runCppcheckOnFileXML( // Resolve paths for arguments where applicable const argsParsed = processedArgs.split(" ").map((arg) => { - const isPathArgument = pathVariableArgs.some(a => arg.startsWith(a)); + let cleanedArg = arg.replaceAll("\"",""); + const isPathArgument = pathVariableArgs.some(a => cleanedArg.startsWith(a)); // Some arguments such as addon may be either a path or the name of a built in addon - if (isPathArgument && looksLikePath(arg)) { - const splitArg = arg.split('='); + if (isPathArgument && looksLikePath(cleanedArg)) { + const splitArg = cleanedArg.split('='); return `${splitArg[0]}=${resolvePath(splitArg[1])}`; } return arg; @@ -216,6 +221,8 @@ async function runCppcheckOnFileXML( ].filter(Boolean); if (processedArgs.includes("--project")) { args.push(`--file-filter=${filePath}`); + } else { + args.push(filePath); } const cwd = findWorkspaceRoot(); proc = cp.spawn(commandPath, args, {