From 2ea1885278ff963011cfc7f6300e37ed31bf5b39 Mon Sep 17 00:00:00 2001 From: davidramnero Date: Mon, 18 May 2026 13:01:47 +0200 Subject: [PATCH 1/2] fix/ #48 cwd fix for relative file references in arguments --- src/extension.ts | 12 +++++++----- src/util/path.ts | 7 ++++++- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index 51ed09b..c8c3009 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -4,7 +4,7 @@ import * as path from "path"; import * as xml2js from 'xml2js'; import { runCommand } from './util/scripts'; -import { resolvePath } from './util/path'; +import { resolvePath, findWorkspaceRoot } from './util/path'; enum SeverityNumber { Info = 0, @@ -199,9 +199,9 @@ async function runCppcheckOnFileXML( '--enable=all', '--inline-suppr', '--xml', - '--suppress=unusedFunction', - '--suppress=missingInclude', - '--suppress=missingIncludeSystem', + // '--suppress=unusedFunction', + // '--suppress=missingInclude', + // '--suppress=missingIncludeSystem', `--file-filter=${filePath}`, ...argsParsed, ].filter(Boolean); @@ -219,8 +219,10 @@ async function runCppcheckOnFileXML( ...argsParsed, filePath, ].filter(Boolean); + + const cwd = findWorkspaceRoot(); proc = cp.spawn(commandPath, args, { - cwd: path.dirname(document.fileName), + cwd, }); } diff --git a/src/util/path.ts b/src/util/path.ts index 2ca36ff..fca6082 100644 --- a/src/util/path.ts +++ b/src/util/path.ts @@ -2,11 +2,16 @@ import * as path from "path"; import * as os from "os"; import * as vscode from 'vscode'; -export function resolvePath(argPath: string): string { +export function findWorkspaceRoot(): string { const folders = vscode.workspace.workspaceFolders; const workspaceRoot = folders && folders.length > 0 ? folders[0].uri.fsPath : process.cwd(); + return workspaceRoot; +} + +export function resolvePath(argPath: string): string { + const workspaceRoot = findWorkspaceRoot(); // Expand ${workspaceFolder} if (argPath.includes("${workspaceFolder}")) { From 10f178239590dd967026951df288a0f011003825 Mon Sep 17 00:00:00 2001 From: davidramnero Date: Mon, 18 May 2026 13:05:08 +0200 Subject: [PATCH 2/2] restore out commented lines --- src/extension.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index c8c3009..ed7e3bb 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -199,9 +199,9 @@ async function runCppcheckOnFileXML( '--enable=all', '--inline-suppr', '--xml', - // '--suppress=unusedFunction', - // '--suppress=missingInclude', - // '--suppress=missingIncludeSystem', + '--suppress=unusedFunction', + '--suppress=missingInclude', + '--suppress=missingIncludeSystem', `--file-filter=${filePath}`, ...argsParsed, ].filter(Boolean); @@ -219,7 +219,7 @@ async function runCppcheckOnFileXML( ...argsParsed, filePath, ].filter(Boolean); - + const cwd = findWorkspaceRoot(); proc = cp.spawn(commandPath, args, { cwd,