Editor Integration
This document contains information about how to configure an editor to use SourceKit-LSP. If your editor is not listed below, but it supports the Language Server Protocol (LSP), see Other Editors.
In general, you will need to know where to find the sourcekit-lsp server exectuable. Some examples:
- With Xcode 11.4+
xcrun sourcekit-lsp- run the serverxcrun --find sourcekit-lsp- get the full path to the server
- Toolchain from Swift.org
- Linux
- You will find
sourcekit-lspin thebindirectory of the toolchain.
- You will find
- macOS
xcrun --toolchain swift sourcekit-lsp- run the serverxcrun --toolchain swift --find sourcekit-lsp- get the full path to the server
- Linux
- Built from source
.build/<platform>/<configuration>/sourcekit-lsp
Visual Studio Code
To use SourceKit-LSP with Visual Studio Code, you will need the SourceKit-LSP Visual Studio Code extension. Documentation for Building and Installing is in the extension's README. There is also information about Configuration. The most common settings are listed below.
After installing the extension, settings for SourceKit-LSP can be found in Preferences > Settings under
Extensions > SourceKit-LSP or by searching for the setting prefix
sourcekit-lsp..
sourcekit-lsp.serverPath: The path to sourcekit-lsp executablesourcekit-lsp.toolchainPath: (optional) The path of the swift toolchain (setsSOURCEKIT_TOOLCHAIN_PATH). By default, sourcekit-lsp uses the toolchain it is installed in.sourcekit-lsp.tracing.server: Traces the communication between VS Code and the SourceKit-LSP language server
Sublime Text
Before using SourceKit-LSP with Sublime Text, you will need to install the LSP package from Package Control. To configure SourceKit-LSP, open the LSP package's settings. The following snippet should be enough to get started with Swift.
You will need the path to the sourcekit-lsp executable for the "command" section.
{
"clients":
{
"SourceKit-LSP":
{
"enabled": true,
"command": [
"<sourcekit-lsp command>"
],
"env": {
// To override the toolchain, uncomment the following:
// "SOURCEKIT_TOOLCHAIN_PATH": "<path to toolchain>",
},
"languages": [
{
"scopes": ["source.swift"],
"syntaxes": [
"Packages/Swift/Syntaxes/Swift.tmLanguage",
"Packages/Decent Swift Syntax/Swift.sublime-syntax",
],
"languageId": "swift"
},
{
"scopes": ["source.c"],
"syntaxes": ["Packages/C++/C.sublime-syntax"],
"languageId": "c"
},
{
"scopes": ["source.c++"],
"syntaxes": ["Packages/C++/C++.sublime-syntax"],
"languageId": "cpp"
},
{
"scopes": ["source.objc"],
"syntaxes": ["Packages/Objective-C/Objective-C.sublime-syntax"],
"languageId": "objective-c"
},
{
"scopes": ["source.objc++"],
"syntaxes": ["Packages/Objective-C/Objective-C++.sublime-syntax"],
"languageId": "objective-cpp"
},
]
}
}
}
Emacs
There is an Emacs client for SourceKit-LSP in the main Emacs LSP repository.
Vim 8 or Neovim
All methods below assume sourcekit-lsp is in your PATH. If it's not then replace sourcekit-lsp with the absolute path to the sourcekit-lsp executable.
vim-lsp
Install vim-lsp. In your .vimrc, configure vim-lsp to use sourcekit-lsp for Swift source files like so:
if executable('sourcekit-lsp')
au User lsp_setup call lsp#register_server({
\ 'name': 'sourcekit-lsp',
\ 'cmd': {server_info->['sourcekit-lsp']},
\ 'whitelist': ['swift'],
\ })
endif
That's it! As a test, open a swift file, put cursor on top of a symbol in normal mode and
run :LspDefinition. More commands are documented here.
There are many Vim solutions for code completion. For instance, you may want to use LSP for omnifunc:
autocmd FileType swift setlocal omnifunc=lsp#complete
With this added in .vimrc, you can use <c-x><c-o> in insert mode to trigger sourcekit-lsp completion.
coc.nvim
With coc.nvim installed, the easiest is to use the coc-sourcekit plugin:
:CocInstall coc-sourcekit
Alternatively open your coc config (:CocConfig in vim) and add:
"languageserver": {
"sourcekit-lsp": {
"filetypes": ["swift"],
"command": "sourcekit-lsp",
}
}
As a test, open a Swift file, put the cursor on top of a symbol in normal mode and run:
:call CocAction('jumpDefinition')
Theia Cloud IDE
You can use SourceKit-LSP with Theia by using the theiaide/theia-swift image. To use the image you need to have Docker installed first.
The following command pulls the image and runs Theia IDE on http://localhost:3000 with the current directory as a workspace.
docker run -it -p 3000:3000 -v "$(pwd):/home/project:cached" theiaide/theia-swift:next
You can pass additional arguments to Theia after the image name, for example to enable debugging:
docker run -it -p 3000:3000 --expose 9229 -p 9229:9229 -v "$(pwd):/home/project:cached" theiaide/theia-swift:next --inspect=0.0.0.0:9229
Image Variants
theiaide/theia-swift:latest
This image is based on the latest stable released version.
theiaide/theia-swift:next
This image is based on the nightly published version.
theia-swift-docker source theia-apps
Other Editors
SourceKit-LSP should work with any editor that supports the Language Server Protocol
(LSP). Each editor has its own mechanism for configuring an LSP server, so consult your editor's
documentation for the specifics. In general, you can configure your editor to use SourceKit-LSP for
Swift, C, C++, Objective-C and Objective-C++ files; the editor will need to be configured to find
the sourcekit-lsp executable (see the top-level README for build instructions), which
expects to communicate with the editor over stdin and stdout.