Introducing SourceKit-LSP


As recently announced by @akyrtzi, we have been working on a new language service for Swift and C-family languages based on the Language Server Protocol (LSP). I am excited to say that the source code for SourceKit-LSP is now available on GitHub! While the new language service is still in early development, we are making it available today to continue its development in the open. Check it out at https://github.com/apple/sourcekit-lsp!

SourceKit-LSP provides code-completion, jump-to-definition and the other semantic editor features from the LSP for Swift and C-family language projects. It enables first class support for Swift and cross-language projects in editors such as Visual Studio Code and Sublime Text. SourceKit-LSP is built on top of sourcekitd and clangd for high-fidelity language support, and provides a powerful source code index as well as cross-language support. It natively understands Swift Packages and is designed to be cross platform, currently supporting macOS and Linux.

Instructions for trying out the new service are at https://github.com/apple/sourcekit-lsp#getting-started. Right now the best way to try it out is to build it from source. Part of the project plan is to explore good ways to package the service for users to try out. Another thing to be aware of: in this early stage of development, we recommend trying out SourceKit-LSP with the swift-DEVELOPMENT-SNAPSHOT-2018-11-01-a toolchain snapshot from https://swift.org/download/#snapshots under “Older Toolchains”. There is an issue with the current 2018-11-13 toolchain that we hope to have resolved soon. We intend to support Swift-5 and future release toolchains going forward.

There is still lots of work to do, but SourceKit-LSP already supports many important editing features. The following table, taken from https://github.com/apple/sourcekit-lsp#status gives an overview of the current status. If you are using Linux, be aware that index-based features such as jump-to-definition depend on some changes (swift-clang#219) that are not in a toolchain snapshot as of swift-DEVELOPMENT-SNAPSHOT-2018-11-01-a, but should be available soon.

Feature Status Notes
Swift :white_check_mark:
C/C++/ObjC :x: clangd is not available in the recommended toolchain. You can try out C/C++/ObjC support by building clangd from source and putting it in PATH.
Code completion :white_check_mark:
Quick Help (Hover) :white_check_mark:
Diagnostics :white_check_mark:
Fix-its :x:
Jump to Definition :white_check_mark:
Find References :white_check_mark:
Background Indexing :x: Build project to update the index using Indexing While Building
Open Quickly :x:
Refactoring :x:
Formating :x:
Folding :x:
Syntax Highlighting :x: Not currently part of LSP.

We welcome contributions to this new project! We have the same policies for contributing as the rest of the Swift project. One great way to get involved is to file bugs for any problems you run into at https://bugs.swift.org/ in the “SourceKit-LSP” component and engage with us in the forums at https://forums.swift.org/c/development/sourcekit-lsp. If you would like to submit a patch, SourceKit-LSP itself is written in Swift, and the core indexing support, IndexStoreDB, is written primarily in C++. We are adding PR testing support very soon.