Merge pull request #3870 from gdbaldw/trunk

Add documentation for NeoVIM LSP Configuration
This commit is contained in:
Paul Chiusano 2023-03-20 09:05:43 -05:00 committed by GitHub
commit cf54ef4095
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -67,10 +67,65 @@ Configuration for [coc-nvim](https://github.com/neoclide/coc.nvim), enter the fo
}
```
For [lspconfig](https://github.com/neovim/nvim-lspconfig), you can use the following setup function:
For [lspconfig](https://github.com/neovim/nvim-lspconfig) with optional autocomplete [nvim-cmp](https://github.com/hrsh7th/nvim-cmp) for LSP
[cmp-nvim-lsp](https://github.com/hrsh7th/cmp-nvim-lsp), you can use the following setup function(s):
```lua
require('lspconfig').unison.setup({})
-- This function is for configuring a buffer when an LSP is attached
local on_attach = function(client, bufnr)
-- Always show the signcolumn, otherwise it would shift the text each time
-- diagnostics appear/become resolved
vim.o.signcolumn = 'yes'
-- Update the cursor hover location every 1/4 of a second
vim.o.updatetime = 250
-- Disable appending of the error text at the offending line
vim.diagnostic.config({virtual_text=false})
-- Enable a floating window containing the error text when hovering over an error
vim.api.nvim_create_autocmd("CursorHold", {
buffer = bufnr,
callback = function()
local opts = {
focusable = false,
close_events = { "BufLeave", "CursorMoved", "InsertEnter", "FocusLost" },
border = 'rounded',
source = 'always',
prefix = ' ',
scope = 'cursor',
}
vim.diagnostic.open_float(nil, opts)
end
})
-- This setting is to display hover information about the symbol under the cursor
vim.keymap.set('n', 'K', vim.lsp.buf.hover)
end
-- Setup the Unison LSP
require('lspconfig')['unison'].setup{
on_attach = on_attach,
}
```
```lua
-- This is NVim Autocompletion support
local cmp = require 'cmp'
-- This function sets up autocompletion
cmp.setup {
-- This mapping affects the autocompletion choices menu
mapping = cmp.mapping.preset.insert(),
-- This table names the sources for autocompletion
sources = {
{ name = 'nvim_lsp' },
},
}
```
Note that you'll need to start UCM _before_ you try connecting to it in your editor or your editor might give up.