Skip to content

Commit a6e8568

Browse files
authored
Merge pull request #783 from scottfines/nvim_doc
Adding some documentation on setting up LSP for neovim 0.8+
2 parents 8cb76ba + 3e11a6e commit a6e8568

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

Editors/README.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,54 @@ As a test, open a Swift file, put the cursor on top of a symbol in normal mode a
143143
:call CocAction('jumpDefinition')
144144
```
145145

146+
### Neovim 0.8 and above
147+
since version 0.8, neovim has native LSP support, which can be used to connect to sourcekit-lsp directly. To do so, add the following to
148+
a .lua config file (such as `lua/swift.lua`):
149+
150+
```lua
151+
require'lspconfig'.sourcekit.setup{
152+
cmd = {'$TOOLCHAIN_PATH/usr/bin/sourcekit-lsp'}
153+
}
154+
```
155+
where `$TOOLCHAIN_PATH` is the path to your active toolchain (for example, `/Library/Developer/Toolchains/swift-latest.xctoolchain`). This should enable
156+
the lsp server directly, and you can test it by opening a swift file and running `:LspInfo`--you should get a window popping up saying "1 client attached to this buffer" and be able to do navigation and such.
157+
158+
The default LSP commands are not bound to many keys, so it is also useful to create some keybindings to help with various LSP activities. Here are some
159+
of the known lsp commands that work with `sourcekit-lsp`:
160+
161+
```lua
162+
vim.api.nvim_create_autocmd('LspAttach', {
163+
group = vim.api.nvim_create_augroup('UserLspConfig', {}),
164+
callback = function(ev)
165+
--enable omnifunc completion
166+
vim.bo[ev.buf].omnifunc = 'v:lua.vim.lsp.omnifunc'
167+
168+
-- buffer local mappings
169+
local opts = { buffer = ev.buf }
170+
-- go to definition
171+
vim.keymap.set('n','gd',vim.lsp.buf.definition,opts)
172+
--puts doc header info into a float page
173+
vim.keymap.set('n','K',vim.lsp.buf.hover,opts)
174+
175+
-- workspace management. Necessary for multi-module projects
176+
vim.keymap.set('n','<space>wa',vim.lsp.buf.add_workspace_folder, opts)
177+
vim.keymap.set('n','<space>wr',vim.lsp.buf.remove_workspace_folder, opts)
178+
vim.keymap.set('n','<space>wl',function()
179+
print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
180+
end,opts)
181+
182+
-- add LSP code actions
183+
vim.keymap.set({'n','v'},'<space>ca',vim.lsp.buf.code_action,opts)
184+
185+
-- find references of a type
186+
vim.keymap.set('n','gr',vim.lsp.buf.references,opts)
187+
end,
188+
})
189+
```
190+
191+
Further information on neovim's LSP integration(including detailed information on configuration) can be found [in neovim's documentation](https://neovim.io/doc/user/lsp.html).
192+
193+
146194
## Theia Cloud IDE
147195

148196
You can use SourceKit-LSP with Theia by using the `theiaide/theia-swift` image. To use the image you need to have [Docker](https://docs.docker.com/get-started/) installed first.

0 commit comments

Comments
 (0)