How to setup setup_handlers correctly? #606
Replies: 2 comments 2 replies
|
you just need to use require("mason-lspconfig").setup_handlers {
-- The first entry (without a key) will be the default handler
-- and will be called for each installed server that doesn't have
-- a dedicated handler.
function (server_name) -- default handler (optional)
require("lspconfig")[server_name].setup {}
end,
-- Next, you can provide a dedicated handler for specific servers.
-- For example, a handler override for the `rust_analyzer`:
["rust_analyzer"] = function ()
require("rust-tools").setup {}
end
}in the lspconfig's setup, you can put your configuration of lsp into it
Maybe my above example is not clear, you can refer to my neovim-config, I have realized the automatic management of lsp, dap, null-ts through mason |
|
In your provided snippet there's no "default" settings, so If you're using Neovim 0.8 or higher I'd recommend making use of the new -- You can place this as a standalone file inside e.g. `plugin/lsp/keymaps.lua`.
-- Because it's inside the `plugin/` directory, Neovim will execute this file automatically for you at startup (:h startup).
---@param bufnr integer
local function setup_buffer_keymaps(bufnr)
-- See `:help vim.lsp.*` for documentation on any of the below functions
local opts = { noremap = true, silent = true, buffer = bufnr }
vim.keymap.set('n', 'gd', vim.lsp.buf.definition, opts)
vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, 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', '<Leader>wa', vim.lsp.buf.add_workspace_folder, opts)
vim.keymap.set('n', '<Leader>wr', vim.lsp.buf.remove_workspace_folder, opts)
vim.keymap.set('n', '<Leader>wl', function()
print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
end, opts)
vim.keymap.set('n', '<Leader>D', vim.lsp.buf.type_definition, opts)
vim.keymap.set('n', '<Leader>rn', vim.lsp.buf.rename, opts)
vim.keymap.set('n', '<Leader>ca', vim.lsp.buf.code_action, opts)
vim.keymap.set('n', 'gr', vim.lsp.buf.references, opts)
end
vim.api.nvim_create_autocmd("LspAttach", {
callback = function(args)
local bufnr = args.buf
setup_buffer_keymaps(bufnr)
end,
})If you're running an older version I'd recommend looking into |
Uh oh!
There was an error while loading. Please reload this page.
I try to use
setup_handlersas a replacement ofon_server_readybut I don't know how to have a default behavior for each LSP (like keymap), so how to have a defaulton_attach,capabilities, etc and merge them without loosing the default behavior.Currently,
[sumneko_lua]and[intelephense]override my defaulton_attach, so the defaulton_attachdoesn't work.I've read the docs about this and I even find a question here but I don't know how to merge the default behavior with a custom config for one LSP.
All reactions