Skip to content

Commit

Permalink
Merge pull request #25 from hf02/file-not-found-fix
Browse files Browse the repository at this point in the history
Fix "File not found" on Windows
  • Loading branch information
vknabel authored Jul 30, 2023
2 parents 36faf41 + 2d7e4af commit e12c489
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/SwiftFormatEditProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,22 @@ function format(request: {
? `${request.formatting.tabSize}`
: "tabs"
];

// Make the path explicitly absolute when on Windows. If we don't do this,
// SwiftFormat will interpret C:\ as relative and put it at the end of
// the PWD.
let fileName = request.document.fileName;
if (process.platform === "win32") {
fileName = "/" + fileName;
}

const newContents = childProcess.execFileSync(
swiftFormatPath[0],
[
...swiftFormatPath.slice(1),
"stdin",
"--stdinpath",
request.document.fileName,
fileName,
...userDefinedParams.options,
...(request.parameters || []),
...formattingParameters
Expand Down

0 comments on commit e12c489

Please sign in to comment.