Swift Development Environment
SDE adds Swift code completion and hover help to Visual Studio Code on macOS and Linux.
Fork Notice: This is the new home of SDE initially been developed by @jinmingjian. It is now maintained by @vknabel. jinmingjian/sde is no longer maintained and does only support Swift 3. This fork supports Swift 3 and 4.
Installation
-
Install the extension itself.
-
Install the companion project sourcekite.
$ git clone https://github.com/vknabel/sourcekite $ cd sourcekite # For Linux # Ensure LD_LIBRARY_PATH contains /your/swift/usr/lib # And have sudo ln -s /usr/lib/sourcekitdInProc /your/swift/usr/lib/libsourcekitdInProc.so $ swift build -Xlinker -l:sourcekitdInProc -c release # For macOS (when using swiftenv or multiple Toolchains) $ swift build -Xswiftc -framework -Xswiftc sourcekitd -Xswiftc -F -Xswiftc /Library/Developer/Toolchains/swift-latest.xctoolchain/usr/lib -Xlinker -rpath -Xlinker /Library/Developer/Toolchains/swift-latest.xctoolchain/usr/lib -c release # For macOS (using Xcode's Toolchain) $ swift build -Xswiftc -framework -Xswiftc sourcekitd -Xswiftc -F -Xswiftc /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/ -Xlinker -rpath -Xlinker /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/ -c release
-
Add the absolute path to your compiled sourcekite binary
swift.path.sourcekite
to your vscode settings as/path/to/your/sourcekite-bin/.build/release/sourcekite
.
If you experience any problems during installation, file an issue or write me an email. All kind of feedback helps especially when trying to automate this.
Debugging
SDE has a built-in Swift debugger which has been deprecated. Instead use LLDB Debugger which powers more features and is more stable.
An example config can be seen below. program
should contain the path to your built executable, the preLaunchTask
is optional, but will run swift build
before each debug session to keep your binaries up to date.
Note: Currently I don't know of any reliable solution to debug your Swift tests. If you do, please file an issue or write me an email.
// .vscode.json/launch.json
{
"version": "0.2.0",
"configurations": [
{
"type": "lldb",
"request": "launch",
"name": "Run your Executable",
"program": "${workspaceFolder}/.build/debug/your-executable",
"args": [],
"cwd": "${workspaceFolder}",
"preLaunchTask": "swift-build"
}
}
// .vscode.json/tasks.json
{
"version": "2.0.0",
"tasks": [
{
"label": "swift-build",
"type": "shell",
"command": "swift build"
}
}
Contributors
- Valentin Knabel, @vknabel, twitter, maintainer
- Jin Mingjian, @JinMingjian, twitter, author
- Felix Fischer, @felix91gr, twitter
FAQ
How to contribute to this project?
Any feedback helps.
If you mean contributions to the sources, this is truely another topic. The experience of using an editor is much different than that of developing one. It might be a bit more painful than you think. But if you would like to, welcome!
There aren't too much documents about the development of this project. If you have any questions or interests, don't hesitate to file an issue or write me an email. I will help you and then drop more readings as time goes by. This is the way of "open source".
How do I get autocompletion for UIKit?
Just add "sde.sourcekit.compilerOptions": ["-target", "arm64-apple-ios11.0"]
to your workspace settings in Visual Studio Code and restart it.
Other questions?
If so, file an issue, please :)
License
Apache License v2.
3rd-party Sources Thanks
- dbgmits, very nice structure of sources, but of which in my heavy modification to support non-MI and much more