I'm currently unable to see any output from the "Run Swift Script" command. This is a folder with a few swift files. No package. My goal is to just open one of those swift files and then run the top level code there. Should this be possible? Can anyone forward some more documentation to see how I use this command?
Switching the Output window to Swift shows me:
2025-09-11 13:19:06.416 [info] Activating Swift for Visual Studio Code...
2025-09-11 13:19:08.719 [info] focus: undefined
As a temporary workaround you could run swift package init in your scripts folder to scaffold out a Package.swift, and then just ignore it. This should allow you to run the scripts via the command in VS Code.
I have a similar question to this user. I am learning swift on linux and have been having a good time experimenting with the language and using “run script” to test functionality and check for errors.
However, if I try to use a class / struct defined in another script, I get “cannot find ___ in scope.“ I guess that makes sense, as the type is defined in another script. But is there any way to make this automatically work? Otherwise, I can’t imagine the run script command is terribly useful outside of the most basic scenarios.
Currently there isn’t a way to import from scripts or modules in scripts. There is some good discussion in this thread, with a more recent comment from @dschaefer2 explaining why this limitation exists today and what would need to change to fix it.
If you’re experimenting and learning the language I’d recommend creating a simple executable with swift package init --type executable, which gives you a small command line app to start with that should let you use modules and code spread across files more freely.
Thanks for the suggestions Paul. I did indeed end up building a godot project with Swift Godot. It was a bit of work but it felt great getting it all working. Unfortunately, it doesn’t seem like the VScode extension is ready for production level work just yet, which is too bad since I definitely fell in love with the language.
I believe I encountered a bug that left me trying to debug for a couple hours. I had an extension modifying a fileprivate protocol with a public function attached. The function never showed up in autocomplete. Eventually, I tried typing it in manually, and it compiled and worked just fine.
extension iStatPrivate
{
public mutating func RecalculateValue()
{
Value = 4
GD.print("Test \(Value)")
}
}
That’s indeed not how it should work, we should be providing completion results. Would you be able to file a bug report about this at GitHub · Where software is built and attach the output of running sourcekit-lsp diagnose in your terminal (ideally after enabling extended logging if that’s OK for you). If you can attach your project as well, that would be amazing, if not, we should also have some information in the logs alone. I can look into what’s going wrong from there.
Thanks for looking into that bug Alex, glad to know it’s already being handled by a future swift version.
I was wondering if I could ask one more question. The design I was trying to accomplish was for a protocol to expose a publicly gettable, privately settable property (which is why I used the fileprivate inherited protocol), and then have an extension expose public functions to modify the property. I gathered from a variety of old stack exchange posts that this kind of setup used to work to some degree, which is why i was trying to implement it.
Looking though some old forum threads, I’m definitely not alone in wishing for this:
Do you know of any better workarounds for this pattern? Is there any chance of this being formally introduced to Swift?
I haven’t spent too much time designing the following, but I’d start with something like the following that gives you a protocol Settable, that’s only visible within the current module and Gettable that is available publicly. I’m not entirely sure what you are trying to achieve, but you might not even need the Settable protocol – that’s usually where I ended up: Some public protocol that exposes the getters and all the setters are just available on the type itself.
public protocol Gettable {
var value: Int { get }
}
protocol Settable: Gettable {
var value: Int { get set }
}
public struct Foo: Settable {
public internal(set) var value: Int
}