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

Quote SwiftFormat path to handle spaces #37

Merged
merged 1 commit into from
May 23, 2024

Conversation

vinocher-bc
Copy link
Contributor

@vinocher-bc vinocher-bc commented May 21, 2024

  • Spaces in swiftformat.exe's path were not being handled, so formatting failed when the tool was installed in a path with spaces like C:\Program Files\nicklockwood\SwiftFormat\usr\bin\swiftformat.exe. Fixed by quoting path.

  • Breakpoints could not be set because launch.json's outFiles was incorrect.

Copy link
Collaborator

@tristanlabelle tristanlabelle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks!

@tristanlabelle
Copy link
Collaborator

@vknabel for reviewing/merging

@vknabel vknabel merged commit a3b9375 into vknabel:master May 23, 2024
@tristanlabelle
Copy link
Collaborator

Hi @vknabel , how would it work to publish new versions of this extension? I see there is no GitHub actions workflow and we could help set that up, but how would the final push to the VSCode marketplace work?

@vknabel
Copy link
Owner

vknabel commented Jun 5, 2024

Hi @tristanlabelle! Totally forgot to automate the releases. The last months were tough. For now I released it manually and I will add a basic Github action for releasing. Later we can tune it and have a chat.

@furby-tm
Copy link

furby-tm commented Jun 5, 2024

This change broke (for me on Fedora Linux), issue here #39.

I do not think all paths to swiftformat should be quoted across all operating systems, because as you can see, this revision broke the path to swiftformat on Linux and possibly macOS as well, one way to handle spaces in paths in a cross platform way, is by escaping them like so:

- my/very long path/to/swiftformat

# do this on macos and linux
+ my/very\ long\ path/to/swiftformat

# do this on windows
# (though I actually believe this only works on cmd prompt.)
+ my/very^ long^ path/to/swiftformat

Or possibly, keep the existing quote fix but only on Microsoft Windows, and keep the previous revision for only macOS and Linux, I believe you should be able to detect platforms in javascript with the following conditional statement checks:

if (process.platform === 'win32')
{
  // do something on windows.
  // (such as your current revision's changes.)
}
else
{
  // do something on macOS, linux, and even unicorns too.
  // (such as leaving the previous code, before your revision, in tact.)
}

above all this extension needs some unit testing, but I'm not familiar enough with vscode extensions to be able to provide you with any guidance there.

@tristanlabelle
Copy link
Collaborator

Rereading this change, the problem is that child_process.spawn is ill-behaved with spaces on Windows, so the workaround quoting logic should happen here:

const result = spawnSync(file, args ?? [], {
. This node API looks like a mess. See windowsVerbatimArguments, although I think we don't want to use that.

@vinocher-bc , can you follow-up since this is affecting other platforms?

@vinocher-bc
Copy link
Contributor Author

vinocher-bc commented Jun 6, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants