Skip to content

Swift: Run Swift Script always runs in Swift 5 language mode #1427

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

Closed
MahdiBM opened this issue Mar 11, 2025 · 7 comments · Fixed by #1476
Closed

Swift: Run Swift Script always runs in Swift 5 language mode #1427

MahdiBM opened this issue Mar 11, 2025 · 7 comments · Fixed by #1476
Labels
enhancement New feature or request

Comments

@MahdiBM
Copy link
Contributor

MahdiBM commented Mar 11, 2025

Describe the bug
When running Swift: Run Swift Script on single files, the extension runs effectively this command:

swift path/to/your-file.swift

Since Swift's default language mode is 5, this will be run in Swift 5 language mode.

To fix, the extension should provide a second "step" when you choose Swift: Run Swift Script that also asks about what language mode a user would like to choose.

Then use that in the command that runs the Swift file. For example the command for Swift 6 language mode would be:

swift -swift-version 6 path/to/your-file.swift

Environment

  • OS: [e.g. Ubuntu 20.04] -
  • Swift version (output of swift --version): 6
  • Visual Studio Code version: -
  • vscode-swift version: 2.0.2
@plemarquand
Copy link
Contributor

I think a second step would make this feature more cumbersome to use if it had to be picked every time. How about a setting that can be specified globally or per-workspace?

@MahdiBM
Copy link
Contributor Author

MahdiBM commented Mar 12, 2025

@plemarquand i did think about that, but i think usually one could just push "return" twice quickly instead of once, to also choose the language mode with the second push? I think VSCode also moves your last-used option to top?

A global setting could be fine but then we still should have another command that lets you choose the language mode you'd want, just in case?

@award999 award999 added enhancement New feature or request and removed bug Something isn't working labels Mar 21, 2025
@award999 award999 moved this from Unscreened to Backlog in Swift Extension for Visual Studio Code Mar 21, 2025
@louisunlimited
Copy link
Contributor

louisunlimited commented Apr 2, 2025

Hi @award999 @MahdiBM @plemarquand , I was browsing over issues and found this. Looks like an interesting addition! Since this is still in Backlog I suppose a nice POC would help visualize this, so I made a tiny PR implementing just be basics of having another dropdown selecting Swift Versions. If this is something y'all would love a PR for I would love to iterate on this and contribute!

@adam-fowler
Copy link
Contributor

I would prefer a global setting. But the setting could have options swift 6, swift 5 and ask each time.

@plemarquand
Copy link
Contributor

Verified in 962681f

@MahdiBM
Copy link
Contributor Author

MahdiBM commented Apr 7, 2025

@plemarquand thank you, this looks good enough, but I would have included all swift-supported versions because why not:

note: valid arguments to '-swift-version' are '4', '4.2', '5', '6'

if Swift supports these, the official VSCode extension should too, IMO.

@plemarquand
Copy link
Contributor

@MahdiBM sure, why not, I opened #1486

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
5 participants