From d2ec5893708af1e4b05e6ad4198bc3ff4fd2ee10 Mon Sep 17 00:00:00 2001 From: Santo Cariotti Date: Sat, 25 Jun 2022 22:32:19 +0200 Subject: nvim: reorder lsp --- .config/nvim/lua/lsp_conf.lua | 49 ++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 26 deletions(-) (limited to '.config/nvim/lua') diff --git a/.config/nvim/lua/lsp_conf.lua b/.config/nvim/lua/lsp_conf.lua index 35f88eb..6555f2e 100644 --- a/.config/nvim/lua/lsp_conf.lua +++ b/.config/nvim/lua/lsp_conf.lua @@ -28,48 +28,45 @@ null_ls.setup({ null_ls.builtins.formatting.clang_format, -- JS/TS null_ls.builtins.formatting.prettier, - } + }, + on_attach = function(client) + if client.resolved_capabilities.document_formatting then + vim.keymap.set('n', '', 'lua vim.lsp.buf.formatting_sync(nil, 2000)', opts) + vim.cmd "autocmd BufWritePre lua vim.lsp.buf.formatting_seq_sync(nil, 2000)" + end + end }) -- Setup lspconfig. +require "lsp_signature".setup() + --- Use a loop to conveniently call 'setup' on multiple servers and -- map buffer local keybindings when the language server attaches + +local common_on_attach = function(client, bufnr) + -- Mappings. + vim.api.nvim_buf_set_keymap(bufnr, "n", "gD", "lua vim.lsp.buf.declaration()", opts) + vim.api.nvim_buf_set_keymap(bufnr, "n", "gd", "lua vim.lsp.buf.definition()", opts) + vim.api.nvim_buf_set_keymap(bufnr, "n", "K", "lua vim.lsp.buf.hover()", opts) + vim.api.nvim_buf_set_keymap(bufnr, "n", "gr", "lua vim.lsp.buf.references()", opts) + vim.api.nvim_buf_set_keymap(bufnr, "n", "e", "lua vim.lsp.diagnostic.show_line_diagnostics()", opts) + + lsp_status.on_attach(client) +end + + local servers = { 'pyright', 'rust_analyzer', 'tsserver', 'clangd' } for _, lsp in ipairs(servers) do nvim_lsp[lsp].setup { capabilities = coq.lsp_ensure_capabilities(), - on_attach = function(client, bufnr) - client.resolved_capabilities.document_formatting = false - - require "lsp_signature".on_attach() - - -- Mappings. - local opts = { noremap=true, silent=true } - - -- See `:help vim.lsp.*` for documentation on any of the below functions - vim.keymap.set('n', 'gD', 'lua vim.lsp.buf.declaration()', opts) - vim.keymap.set('n', 'gd', 'lua vim.lsp.buf.definition()', opts) - vim.keymap.set('n', 'K', 'lua vim.lsp.buf.hover()', opts) - vim.keymap.set('n', 'gr', 'lua vim.lsp.buf.references()', opts) - vim.keymap.set('n', 'e', 'lua vim.lsp.diagnostic.show_line_diagnostics()', opts) - end, + on_attach = common_on_attach, flags = { debounce_text_changes = 150, } } end --- nvim_lsp["null-ls"].setup({ --- on_attach = function(client) --- if client.resolved_capabilities.document_formatting then --- vim.keymap.set('n', '', 'lua vim.lsp.buf.formatting_sync()', opts) --- vim.cmd "autocmd BufWritePre lua vim.lsp.buf.formatting_seq_sync()" --- end --- end --- }) --- --- trouble.setup({ use_diagnostic_signs = true, auto_close = true, -- cgit v1.2.3-18-g5258