Swift code not running vscode windows 10

So I'm just getting started with swift and I've had a couple problems.

I've downloaded everything according to the swift.org website, plus the visual studio stuff, I also tried getting the swift for windows software to compile it which didn't work.

Anyway here are the problems:

  1. When I try to run swift code in vscode and debug it I get this error

"cannot start debugging because no launch configuration has been provided"

So I add the configuration and it tells me variable ${workspacefolder} can't be resolved, so I edit it to the right directory

But it comes back and says it can't find the executable at ${C:\Users\dummy\Downloads\SwiftProject}/main.swift.exe

I don't know why its adding a .exe to the end of it.

I've installed the swift extension in vscode and I've got the CodeLLDB debugger extension, I saw someone say its meant to debug in binary or something and to try changing

"program": "${C:\Users\dummy\Downloads\SwiftProject}/main.swift",

to just "program": "${C:\Users\dummy\Downloads\SwiftProject}/main."

or to get rid of the program rule all together but that doesn't work either.

I hear mac is easier to use but I don't have a mac so unless I use a virtual machine for macOS or something then I don't know.

I saw someone say CodeLLDB isn't compatible with swift and you have to get an alternative version that is but I don't know where to find it.

Anyone know how to fix this?

Problem 2.

When using the swift for windows software to compile and run swift it says I have to compile before I can run the code so I try and compile it but I get this error:

"C:\Swift\bin\swiftc.exe" -swift-version 4 "C:\Users\dummy\Downloads\SwiftProject\main.swift" -o "C:\Swift\RuntimeEnv\main.exe"

C:\Swift\mingw64\bin\ld: cannot find C:\Users\dummy\AppData\Local\Programs\Swift\Platforms\5.10.0\Windows.platform\Developer\SDKs\Windows.sdk: Permission denied

Successfully compiled"

Not sure what any of that means or how to fix it. I've tried removing and reinstalling swift in the different ways that swift.org says you can but none of them work.

Hi @ensiv

Can you try swift-setup/platforms/windows/README.md at main · pwsacademy/swift-setup · GitHub and swift-setup/editors/vscode-windows/README.md at main · pwsacademy/swift-setup · GitHub ?

I maintain these instructions for first-time users. They should help you get started and avoid any known issues (there still are a few, so follow the instructions carefully).

hi @svanimpe I followed the instuctions and installed the swift extension for vscode but I don't get the message box telling me to configure a Swift-specific version of LLDB

Is there a specific version of it I have to install instead of the latest one?

That may be because you already have it installed and configured?

I tried uninstalling it all and reinstalling and even using an older version of the swift extension but I never get a prompt asking me to configure it

Is there still something in your VS Code settings.json?

Or are you using the new debug adapter, which doesn't use CodeLLDB?

when I deleted VS code the first time I completely wiped everything including the %appdata%\code folder so I don't think it would still have anything in the settings.json

No it's unchecked for me

I think it might work if I use the terminal to do the swift run command but it asks for the package.swift file which I haven't made.

In the video I've added below I followed the tutorial you sent and just used the code hello.swift line in command prompt and it's made the file for me without any package.swift file.

Ah yes, you really should use a package here, not a single file.

If you're unfamiliar with packages, you should try Getting Started | Programming with Swift first. That course is made to be cross-platform, and has been tested on Windows.

I'll check it out, what about the debugging problem where it tells me there's no launch configuration? If there's no fix then just doing swift run should work but would be nice for the debugging to work.

Thanks for all the help by the way

The Swift extension will generate a launch configuration for you :slight_smile:
But that only applies to packages

Good news I just figured out how to get the debugging to work, basically all I had to do was change

"program": "${C:\\Users\\dummy\\hello_swift}/hello",
            "args": [],
            "cwd": "${C:\\Users\\dummy\\hello_swift}"

in the configuration file to

"program": "C:\\Users\\dummy\\hello_swift/hello",
            "args": [],
            "cwd": "C:\\Users\\dummy\\hello_swift"

and now it works, the only problem is if I edit the code and try and run it again it doesn't apply the change.

I'm guessing because it's running hello.exe and not the file I'm editing hello.swift

would I have to recompile it every time I edit it and then run and debug again?

Edit: I just checked out the guide you sent and made all the packages and things and it works

Just have to run swift run and it'll compile it all for me and it works.

Run and debug does work but like I said before It doesn't run the updated changes so I guess from now on I'll use swift run instead