Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle spaces in path only on Windows #40

Merged
merged 1 commit into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 2 additions & 10 deletions src/SwiftFormatEditProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ function format(request: {
}

const newContents = execShellSync(
quotePath(swiftFormatPath[0]),
swiftFormatPath[0],
[
...swiftFormatPath.slice(1).map(quotePath),
...swiftFormatPath.slice(1),
"stdin",
"--stdinpath",
fileName,
Expand All @@ -102,14 +102,6 @@ function format(request: {
}
}

function quotePath(path: string): string {
if (path.startsWith('"') && path.endsWith('"')) {
return path;
} else {
return `"${path}"`;
}
}

export class SwiftFormatEditProvider
implements
vscode.DocumentRangeFormattingEditProvider,
Expand Down
10 changes: 9 additions & 1 deletion src/execShell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export function execShellSync(
options: ExecFileSyncOptionsWithStringEncoding,
): string {
if (os.platform() === "win32") {
const result = spawnSync(file, args ?? [], {
const result = spawnSync(quotePath(file), args ?? [], {
...options,
encoding: "utf8",
shell: true,
Expand All @@ -24,3 +24,11 @@ export function execShellSync(
return execFileSync(file, args, options);
}
}

function quotePath(path: string): string {
if (path.startsWith('"') && path.endsWith('"')) {
return path;
} else {
return `"${path}"`;
}
}