Skip to content
New home of Swift Development Environment for VS Code
Branch: master
Clone or download
vknabel Merge pull request #44 from 343max/patch-1
`sourcekite-lsp` -> `sourcekit-lsp`
Latest commit 78f9c9f Apr 15, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.vscode Added Swift Targets settings Aug 30, 2018
docs r1.0 Jan 11, 2017
icons r1.0 Jan 11, 2017
src Sourcekit-lsp and documentation improvements #39 Apr 11, 2019
test
.editorconfig Added initial support for reading compiler arguments from debug yaml #27 Aug 30, 2018
.gitignore correct wrong thing in gitignore Jan 12, 2017
.travis.yml
.vscodeignore r1.0 Jan 11, 2017
CHANGELOG.md
CONTRIBUTING.md Add support for alternative language servers #21 Oct 29, 2018
LICENSE
README.md
package.json Sourcekit-lsp and documentation improvements #39 Apr 11, 2019
tsconfig.json Prettier Aug 29, 2018
yarn.lock

README.md

Swift Development Environment

Build Status Visual Studio Code Version Swift Version SwiftPM compatible Platforms License Apache

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.

preview

Installation

You have the choice between three different language server implementations.

sde.languageServerMode Comments Swift Versions Install
sourcekit-lsp Apple's official one. Activley developed. 4 and 5 #Using sourcekite
sourcekite default SDE's one. Actively maintained. 4, 5 and older version 3.1 #Using sourcekit-lsp
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.

Using sourcekite

  1. sourcekite does only work with SDE. Make sure you have it installed.

  2. 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/sourcekitdInProc
    $ swift build -Xlinker -l:sourcekitdInProc -c release
    
    # For macOS (when using swiftenv or multiple Toolchains)
    $ make install LIB_DIR=/Library/Developer/Toolchains/swift-latest.xctoolchain/usr/lib
    
    # For macOS (using Xcode's Toolchain)
    $ make install LIB_DIR=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib
  3. 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.

Using sourcekit-lsp

  1. Install SDE.
  2. Install sourcekit-lsp.
  3. Add the absolute path to your compiled sourcekite binary sourcekit-lsp.serverPath, optionally to your toolchain sourcekit-lsp.toolchainPath and tell SDE to use sourcekit-lsp "sde.languageServerMode": "sourcekit-lsp".

Using Langserver Swift

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.

Debugging

SDE has a built-in Swift debugger which has been deprecated. Instead use LLDB Debugger which powers more features and is more stable.

Below is an example configuration supporting running executable targets, unit tests on macOS and Linux. Relevant files will be compiled using the pre-launch-tasks.

// .vscode/launch.json
{
    "version": "0.2.0",
    "configurations": [
        // Running executables
        {
            "type": "lldb",
            "request": "launch",
            "name": "Run your Executable",
            "program": "${workspaceFolder}/.build/debug/your-executable",
            "args": [],
            "cwd": "${workspaceFolder}",
            "preLaunchTask": "swift-build"
        },
        // Running unit tests
        {
            "type": "lldb",
            "request": "launch",
            "name": "Debug tests on macOS",
            "program": "<path to xctest executable>", //For example /Applications/Xcode.app/Contents/Developer/usr/bin/xctest
            "args": [
                "${workspaceFolder}.build/debug/<xctest bundle name>.xctest"
            ],
            "preLaunchTask": "swift-build-tests"
        },
        {
            "type": "lldb",
            "request": "launch",
            "name": "Debug tests on Linux",
            "program": "./.build/x86_64-unknown-linux/debug/YourPackageTests.xctest",
            "preLaunchTask": "swift-build-tests"
        }
    ]
}
// .vscode/tasks.json
{
    "version": "2.0.0",
    "tasks": [
        // compile your SPM project
        {
            "label": "swift-build",
            "type": "shell",
            "command": "swift build"
        },
        // compile your SPM tests
        {
            "label": "swift-build-tests",
            "type": "process",
            "command": "swift",
            "group": "build",
            "args": [
                "build",
                "--build-tests"
            ]
        }
}

Contributors

FAQ

How to contribute to this project?

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.

How do I get autocompletion for UIKit?

You can add new autocomplation 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"
      ]
    }
  ]
}

Other questions?

If so, file an issue, please :)

License

Apache License v2.

3rd-party Sources Thanks

  1. dbgmits, very nice structure of sources, but of which in my heavy modification to support non-MI and much more
You can’t perform that action at this time.