aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--README.md2
-rw-r--r--doc/lspconfig.txt104
2 files changed, 50 insertions, 56 deletions
diff --git a/README.md b/README.md
index cd7074da..c374d996 100644
--- a/README.md
+++ b/README.md
@@ -6,7 +6,7 @@
* If you found a bug in the Nvim LSP client, [report it at the Nvim core repo](https://github.com/neovim/neovim/issues/new?assignees=&labels=bug%2Clsp&template=lsp_bug_report.yml).
* These configs are **best-effort and unsupported.** See [contributions](#contributions).
-See also `:help lsp-config`.
+See also `:help lspconfig`.
## Install
diff --git a/doc/lspconfig.txt b/doc/lspconfig.txt
index cff149d6..7e566626 100644
--- a/doc/lspconfig.txt
+++ b/doc/lspconfig.txt
@@ -1,4 +1,4 @@
-*lspconfig.txt* For Nvim version 0.7+
+*lspconfig.txt* For Nvim version 0.8+
nvim-lspconfig provides user-contributed configs for the Nvim |lsp| client.
@@ -477,70 +477,64 @@ EXAMPLE KEYBINDINGS *lspconfig-keybindings*
`lspconfig`, and the core client, do not map any keybindings by default. The
following is an example Lua block which demonstrates how to leverage
-`on-attach` to selectively apply keybindings after a language servers has
-attached to a given buffer.
+`LspAttach` (Nvim 0.8+) autocommand to apply keybindings after a language
+servers has attached to a given buffer.
>
->
- -- Mappings.
+ -- Setup language servers.
+ local lspconfig = require('lspconfig')
+ lspconfig.pyright.setup {}
+ lspconfig.tsserver.setup {}
+ lspconfig.rust_analyzer.setup {
+ -- Server-specific settings. See `:help lspconfig-setup`
+ settings = {
+ ['rust-analyzer'] = {},
+ },
+ }
+
+
+ -- Global mappings.
-- See `:help vim.diagnostic.*` for documentation on any of the below functions
- local opts = { noremap=true, silent=true }
- vim.keymap.set('n', '<space>e', vim.diagnostic.open_float, opts)
- vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, opts)
- vim.keymap.set('n', ']d', vim.diagnostic.goto_next, opts)
- vim.keymap.set('n', '<space>q', vim.diagnostic.setloclist, opts)
+ vim.keymap.set('n', '<space>e', vim.diagnostic.open_float)
+ vim.keymap.set('n', '[d', vim.diagnostic.goto_prev)
+ vim.keymap.set('n', ']d', vim.diagnostic.goto_next)
+ vim.keymap.set('n', '<space>q', vim.diagnostic.setloclist)
- -- Use an on_attach function to only map the following keys
+ -- Use LspAttach autocommand to only map the following keys
-- after the language server attaches to the current buffer
- local on_attach = function(client, bufnr)
- -- Enable completion triggered by <c-x><c-o>
- vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc')
-
- -- Mappings.
- -- See `:help vim.lsp.*` for documentation on any of the below functions
- local bufopts = { noremap=true, silent=true, buffer=bufnr }
- vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, bufopts)
- vim.keymap.set('n', 'gd', vim.lsp.buf.definition, bufopts)
- vim.keymap.set('n', 'K', vim.lsp.buf.hover, bufopts)
- vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, bufopts)
- vim.keymap.set('n', '<C-k>', vim.lsp.buf.signature_help, bufopts)
- vim.keymap.set('n', '<space>wa', vim.lsp.buf.add_workspace_folder, bufopts)
- vim.keymap.set('n', '<space>wr', vim.lsp.buf.remove_workspace_folder, bufopts)
- vim.keymap.set('n', '<space>wl', function()
- print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
- end, bufopts)
- vim.keymap.set('n', '<space>D', vim.lsp.buf.type_definition, bufopts)
- vim.keymap.set('n', '<space>rn', vim.lsp.buf.rename, bufopts)
- vim.keymap.set('n', '<space>ca', vim.lsp.buf.code_action, bufopts)
- vim.keymap.set('n', 'gr', vim.lsp.buf.references, bufopts)
- vim.keymap.set('n', '<space>f', function() vim.lsp.buf.format { async = true } end, bufopts)
- end
+ vim.api.nvim_create_autocmd('LspAttach', {
+ group = vim.api.nvim_create_augroup('UserLspConfig', {}),
+ callback = function(ev)
+ -- Enable completion triggered by <c-x><c-o>
+ vim.bo[ev.buf].omnifunc = 'v:lua.vim.lsp.omnifunc'
- local lsp_flags = {
- -- This is the default in Nvim 0.7+
- debounce_text_changes = 150,
- }
- require('lspconfig')['pyright'].setup{
- on_attach = on_attach,
- flags = lsp_flags,
- }
- require('lspconfig')['tsserver'].setup{
- on_attach = on_attach,
- flags = lsp_flags,
- }
- require('lspconfig')['rust_analyzer'].setup{
- on_attach = on_attach,
- flags = lsp_flags,
- -- Server-specific settings...
- settings = {
- ["rust-analyzer"] = {}
- }
- }
+ -- Buffer local mappings.
+ -- See `:help vim.lsp.*` for documentation on any of the below functions
+ local opts = { buffer = ev.buf }
+ vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, opts)
+ vim.keymap.set('n', 'gd', vim.lsp.buf.definition, opts)
+ vim.keymap.set('n', 'K', vim.lsp.buf.hover, opts)
+ vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, opts)
+ vim.keymap.set('n', '<C-k>', vim.lsp.buf.signature_help, opts)
+ vim.keymap.set('n', '<space>wa', vim.lsp.buf.add_workspace_folder, opts)
+ vim.keymap.set('n', '<space>wr', vim.lsp.buf.remove_workspace_folder, opts)
+ vim.keymap.set('n', '<space>wl', function()
+ print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
+ end, opts)
+ vim.keymap.set('n', '<space>D', vim.lsp.buf.type_definition, opts)
+ vim.keymap.set('n', '<space>rn', vim.lsp.buf.rename, opts)
+ vim.keymap.set({ 'n', 'v' }, '<space>ca', vim.lsp.buf.code_action, opts)
+ vim.keymap.set('n', 'gr', vim.lsp.buf.references, opts)
+ vim.keymap.set('n', '<space>f', function()
+ vim.lsp.buf.format { async = true }
+ end, opts)
+ end,
+ })
==============================================================================
COMPLETION SUPPORT *lspconfig-completion*
Manually triggered completion can be provided by Nvim's built-in omnifunc.
-See |lsp-config|.
+See |lspconfig|.
For autocompletion, Nvim does not provide built-in functionality. Consult the
nvim-lspconfig wiki, which provides configuration examples for using