Skip to content
This repository was archived by the owner on Jan 2, 2026. It is now read-only.

Commit 6ec66c6

Browse files
hamtikovknabel
authored andcommitted
Provide document rootpath as a working directory path execShellSync
1 parent ca9957a commit 6ec66c6

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/SwiftFormatEditProvider.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,19 @@ const wholeDocumentRange = new vscode.Range(
1212
Number.MAX_SAFE_INTEGER,
1313
);
1414

15+
function rootPathForDocument(document: vscode.TextDocument): string {
16+
const workspaceFolder = vscode.workspace.getWorkspaceFolder(document.uri);
17+
return (workspaceFolder && workspaceFolder.uri.fsPath) || vscode.workspace.rootPath || "./";
18+
}
19+
1520
function userDefinedFormatOptionsForDocument(document: vscode.TextDocument): {
1621
options: string[];
1722
hasConfig: boolean;
1823
} {
1924
const formatOptions = Current.config.formatOptions();
2025
if (formatOptions.indexOf("--config") != -1)
2126
return { options: formatOptions, hasConfig: true };
22-
const workspaceFolder = vscode.workspace.getWorkspaceFolder(document.uri);
23-
const rootPath =
24-
(workspaceFolder && workspaceFolder.uri.fsPath) ||
25-
vscode.workspace.rootPath ||
26-
"./";
27+
const rootPath = rootPathForDocument(document);
2728
const searchPaths = Current.config
2829
.formatConfigSearchPaths()
2930
.map((current) => resolve(rootPath, current));
@@ -85,6 +86,7 @@ function format(request: {
8586
],
8687
{
8788
encoding: "utf8",
89+
cwd: rootPathForDocument(request.document),
8890
input,
8991
},
9092
);

0 commit comments

Comments
 (0)