Skip to content

Commit a146fc0

Browse files
authored
fix/ #48 cwd fix for relative file references in arguments (#50)
* fix/ #48 cwd fix for relative file references in arguments * restore out commented lines
1 parent 99118af commit a146fc0

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

src/extension.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import * as path from "path";
44
import * as xml2js from 'xml2js';
55

66
import { runCommand } from './util/scripts';
7-
import { resolvePath } from './util/path';
7+
import { resolvePath, findWorkspaceRoot } from './util/path';
88

99
enum SeverityNumber {
1010
Info = 0,
@@ -219,8 +219,10 @@ async function runCppcheckOnFileXML(
219219
...argsParsed,
220220
filePath,
221221
].filter(Boolean);
222+
223+
const cwd = findWorkspaceRoot();
222224
proc = cp.spawn(commandPath, args, {
223-
cwd: path.dirname(document.fileName),
225+
cwd,
224226
});
225227
}
226228

src/util/path.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,16 @@ import * as path from "path";
22
import * as os from "os";
33
import * as vscode from 'vscode';
44

5-
export function resolvePath(argPath: string): string {
5+
export function findWorkspaceRoot(): string {
66
const folders = vscode.workspace.workspaceFolders;
77
const workspaceRoot = folders && folders.length > 0
88
? folders[0].uri.fsPath
99
: process.cwd();
10+
return workspaceRoot;
11+
}
12+
13+
export function resolvePath(argPath: string): string {
14+
const workspaceRoot = findWorkspaceRoot();
1015

1116
// Expand ${workspaceFolder}
1217
if (argPath.includes("${workspaceFolder}")) {

0 commit comments

Comments
 (0)