Skip to content

Commit

Permalink
Quote SwiftFormat path to handle spaces (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
vinocher-bc authored May 23, 2024
1 parent 4e1e5d8 commit a3b9375
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"args": ["--extensionDevelopmentPath=${workspaceRoot}"],
"stopOnEntry": false,
"sourceMaps": true,
"outFiles": ["${workspaceRoot}/out/src"],
"outFiles": ["${workspaceRoot}/out/src/*.js"],
"preLaunchTask": "npm"
}
]
Expand Down
12 changes: 10 additions & 2 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(
swiftFormatPath[0],
quotePath(swiftFormatPath[0]),
[
...swiftFormatPath.slice(1),
...swiftFormatPath.slice(1).map(quotePath),
"stdin",
"--stdinpath",
fileName,
Expand All @@ -102,6 +102,14 @@ 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

0 comments on commit a3b9375

Please sign in to comment.