Blog

Musings on Software Development, Design, and Personal Development.

VSCode + Swift = 💯?

Lately I’ve been doing more and more work with Server-Side Swift (with Vapor in particular), and have been trying alternate development environments like VSCode instead of Xcode. However when switching away from Xcode you lose the benefits of code completion and the build and run cycle. Luckily the clever folks at Swift.org have adopted the Language Server Protocol for Swift, allowing rich IDE support for Swift outside of Xcode.

I followed the Editor Integration guide to get setup, but ran into a speed bump and hope this helps you. If you get this type of error:

9ffbc071706b1772382cb57517a7309fdba175e2.png

I found you could solve this by setting your ‘Server Path’ to the Xcode toolchain path in VSCode Settings.

Screen Shot 2020-08-01 at 4.53.59 PM.png

To find this path run this in Terminal.app:

xcrun --find sourcekit-lsp

Which should return something like:

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/sourcekit-lsp

Once you’ve got this running you can enjoy the sweet code-completion and lookups you are used to.

I did find some rough edges, every now and then the sourcekit-lsp server would slow down, requiring me to kill the process (after which it restarts itself). So this is still a work in progress… but better than nothing.