aboutsummaryrefslogtreecommitdiffstats
path: root/doc/lspconfig.txt
diff options
context:
space:
mode:
authorii14 <59243201+ii14@users.noreply.github.com>2023-07-25 07:37:59 +0200
committerGitHub <noreply@github.com>2023-07-25 13:37:59 +0800
commit01b25ff1a66745d29ff75952e9f605e45611746e (patch)
treeff61955dc8acb29e0e9bb5d0c2dfd76ddd634c5d /doc/lspconfig.txt
parentfix(pyright): re-enable single-file mode (#2730) (diff)
downloadnvim-lspconfig-01b25ff1a66745d29ff75952e9f605e45611746e.tar
nvim-lspconfig-01b25ff1a66745d29ff75952e9f605e45611746e.tar.gz
nvim-lspconfig-01b25ff1a66745d29ff75952e9f605e45611746e.tar.bz2
nvim-lspconfig-01b25ff1a66745d29ff75952e9f605e45611746e.tar.lz
nvim-lspconfig-01b25ff1a66745d29ff75952e9f605e45611746e.tar.xz
nvim-lspconfig-01b25ff1a66745d29ff75952e9f605e45611746e.tar.zst
nvim-lspconfig-01b25ff1a66745d29ff75952e9f605e45611746e.zip
docs: make vimdocs consistent with readme (#2732)
Co-authored-by: ii14 <ii14@users.noreply.github.com>
Diffstat (limited to 'doc/lspconfig.txt')
-rw-r--r--doc/lspconfig.txt104
1 files changed, 49 insertions, 55 deletions
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