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.1, 4 and 5.
You have the choice between three different language server implementations.
sde.languageServerMode |
Comments | Swift Versions | Install |
---|---|---|---|
sourcekit-lsp default |
Apple's official one. Activley developed. | 4 and 5 | #Using sourcekit-lsp |
sourcekite |
SDE's one. Actively maintained. | 5 and older versions 3.1 and 4 | #Using sourcekite |
langserver |
RLovelett's LSP. Not maintained. | 4.1, macOS only | #Using Langserver Swift |
sourcekit-lsp is easier to install and will be updated more frequently. On the other hand sourcekite treats standalone files, Xcode projects and SwiftPM modules differently and is more configurable. If you can't decide, you can install both and swap out the used LSP by setting sde.languageServerMode
to sourcekite
, sourcekit-lsp
or langserver
.
Note: on macOS SDE defaults to using your Xcode's Swift and sourcekit-lsp. In that case, SDE should work out of the box!
- Install SDE.
- Recent versions of Xcode ship with
sourcekit-lsp
, you can check its path runningxcrun -f sourcekit-lsp
. If not found, please install sourcekit-lsp. - Set
"sourcekit-lsp.serverPath": "absolute path to the sourcekit-lsp executable"
and"sde.languageServerMode": "sourcekit-lsp"
.
-
sourcekite does only work with SDE. Make sure you have it installed.
-
Install the companion project sourcekite.
$ git clone https://github.com/vknabel/sourcekite $ cd sourcekite # For Linux # Ensure you have libcurl4-openssl-dev installed (not pre-installed) # $ apt-get update && apt-get install libcurl4-openssl-dev # Ensure LD_LIBRARY_PATH contains /your/swift/usr/lib # And have $ sudo ln -s /your/swift/usr/lib/libsourcekitdInProc.so /usr/lib/libsourcekitdInProc.so $ make install PREFIX=/usr/local # For macOS $ make install PREFIX=/usr/local
-
Add the absolute path to your compiled sourcekite binary
swift.path.sourcekite
to your vscode settings as/usr/local/sourcekite
.
If you experience any problems during installation, file an issue. All kind of feedback helps especially when trying to automate this.
Besides sourcekit-lsp and sourcekite SDE allows you to use RLovelett/langserver-swift.
If you prefer using an alternative language server, set set sde.languageServerMode
to langserver
and let swift.languageServerPath
point to your installed language server.
Though in most cases sourcekit-lsp and sourcekite should produce better results and performance.
- Valentin Knabel, @vknabel, twitter, maintainer
- Jin Mingjian, @JinMingjian, twitter, author, not involved anymore
- Felix Fischer, @felix91gr, twitter
- Mijo Gračanin, @mijo-gracanin
There are a lot of ways you could contribute to either this project or the Swift on VS Code itself. For more information head over to CONTRIBUTING.md.
Debugging your Swift targets requires a different extension LLDB Debugger. You can follow this tutorial: vknabel.com/pages/Debugging-Swift-in-VS-Code.
You can add the following configs. This will improve your autocompletion. Though currently the TensorFlow
module will not be indexed yet.
// .vscode/settings.json example for TensorFlow
{
"sde.swiftBuildingParams": ["build", "-Xlinker", "-ltensorflow"],
"sde.languageServerMode": "sourcekite",
"sourcekit-lsp.toolchainPath": "/Library/Developer/Toolchains/swift-tensorflow-RELEASE-0.3.1.xctoolchain",
"swift.path.swift_driver_bin": "/Library/Developer/Toolchains/swift-tensorflow-RELEASE-0.3.1.xctoolchain/usr/bin/swift"
}
In case you find a way to get autocompletion for the
TensorFlow
module to work, please submit a PR or open an issue.
With sourcekite, you can add new autocompletion targets through your configuration.
// .vscode/settings.json example for iOS and WatchOS
{
"swift.targets": [
{
"name": "YourApp",
"path": "YourApp/YourApp",
"sources": ["**/*.swift"],
"compilerArguments": [
"-sdk",
"/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk",
"-target",
"arm64-apple-ios11.0"
]
},
{
"name": "YourWatchApp",
"path": "YourApp/YourWatchExtension",
"sources": ["**/*.swift"],
"compilerArguments": [
"-sdk",
"/Applications/Xcode.app/Contents/Developer/Platforms/WatchOS.platform/Developer/SDKs/WatchOS.sdk",
"-target",
"armv7k-apple-watchos4.0"
]
}
]
}
Since Xcode 11.4, you may use its built-in support for sourcekit-lsp
// .vscode/settings.json example for iOS
{
"sde.languageServerMode": "sourcekit-lsp",
"sourcekit-lsp.serverPath": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/sourcekit-lsp",
"sourcekit-lsp.toolchainPath": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain",
"sde.swiftBuildingParams": [
"build",
"-Xswiftc",
"-sdk",
"-Xswiftc",
"/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk",
"-Xswiftc",
"-target",
"-Xswiftc",
"arm64-apple-ios11.0"
]
}
// .vscode/settings.json example for WatchOS
{
"sde.languageServerMode": "sourcekit-lsp",
"sourcekit-lsp.serverPath": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/sourcekit-lsp",
"sourcekit-lsp.toolchainPath": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain",
"sde.swiftBuildingParams": [
"build",
"-Xswiftc",
"-sdk",
"-Xswiftc",
"/Applications/Xcode.app/Contents/Developer/Platforms/WatchOS.platform/Developer/SDKs/WatchOS.sdk",
"-Xswiftc",
"-target",
"-Xswiftc",
"armv7k-apple-watchos4.0"
]
}
Go to vscode OUTPUT
window, then select SPM
. The OUTPUT
window will tell you what's wrong.
If so, file an issue, please :)
Apache License v2.
- dbgmits, very nice structure of sources, but of which in my heavy modification to support non-MI and much more