neovim: Leverage the new LspAttach callback rather than the mason-lspconfig method for LSP-bindings
This commit is contained in:
parent
e67d669436
commit
3126226ad4
1 changed files with 27 additions and 22 deletions
|
@ -315,25 +315,34 @@ later(function()
|
||||||
})
|
})
|
||||||
|
|
||||||
-- only perform these mappings if an LSP is attached
|
-- only perform these mappings if an LSP is attached
|
||||||
local on_attach = function(client, buffnr)
|
vim.api.nvim_create_autocmd("LspAttach", {
|
||||||
local lsp_key = function(lhs, rhs, desc)
|
callback = function(args)
|
||||||
vim.keymap.set('n', lhs, rhs, { silent = true, buffer = buffnr, desc = desc })
|
local client = vim.lsp.get_client_by_id(args.data.client_id)
|
||||||
end
|
if not client then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
lsp_key('<leader>lr', vim.lsp.buf.rename, 'Rename symbol')
|
local buffnr = args.buf
|
||||||
lsp_key('<leader>la', vim.lsp.buf.code_action, 'Code action')
|
|
||||||
lsp_key('<leader>ld', vim.lsp.buf.type_definition, 'Type definition')
|
|
||||||
|
|
||||||
lsp_key('gd', vim.lsp.buf.definition, 'Goto Definition')
|
local lsp_key = function(lhs, rhs, desc)
|
||||||
lsp_key('gr', vim.lsp.buf.references, 'Goto References')
|
vim.keymap.set('n', lhs, rhs, { silent = true, buffer = buffnr, desc = desc })
|
||||||
lsp_key('gI', vim.lsp.buf.implementation, 'Goto Implementation')
|
end
|
||||||
lsp_key('gD', vim.lsp.buf.declaration, 'Goto Declaration')
|
|
||||||
|
|
||||||
-- setup :Lsp* commands
|
lsp_key('<leader>lr', vim.lsp.buf.rename, 'Rename symbol')
|
||||||
local basics = require('lsp_basics')
|
lsp_key('<leader>la', vim.lsp.buf.code_action, 'Code action')
|
||||||
basics.make_lsp_commands(client, buffnr)
|
lsp_key('<leader>ld', vim.lsp.buf.type_definition, 'Type definition')
|
||||||
basics.make_lsp_mappings(client, buffnr)
|
|
||||||
end
|
lsp_key('gd', vim.lsp.buf.definition, 'Goto Definition')
|
||||||
|
lsp_key('gr', vim.lsp.buf.references, 'Goto References')
|
||||||
|
lsp_key('gI', vim.lsp.buf.implementation, 'Goto Implementation')
|
||||||
|
lsp_key('gD', vim.lsp.buf.declaration, 'Goto Declaration')
|
||||||
|
|
||||||
|
-- setup :Lsp* commands
|
||||||
|
local basics = require('lsp_basics')
|
||||||
|
basics.make_lsp_commands(client, buffnr)
|
||||||
|
basics.make_lsp_mappings(client, buffnr)
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
|
||||||
require('mason').setup()
|
require('mason').setup()
|
||||||
require('mason-lspconfig').setup({
|
require('mason-lspconfig').setup({
|
||||||
|
@ -341,18 +350,14 @@ later(function()
|
||||||
-- read documentation for one-off configurations if an LSP needs/wants non-default configuration
|
-- read documentation for one-off configurations if an LSP needs/wants non-default configuration
|
||||||
handlers = {
|
handlers = {
|
||||||
function (server_name)
|
function (server_name)
|
||||||
require('lspconfig')[server_name].setup({
|
require('lspconfig')[server_name].setup({})
|
||||||
on_attach = on_attach
|
|
||||||
})
|
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
-- make sure LSPs are autostarted if already installed at neovim start
|
-- make sure LSPs are autostarted if already installed at neovim start
|
||||||
for _, server_name in pairs(require('mason-lspconfig').get_installed_servers()) do
|
for _, server_name in pairs(require('mason-lspconfig').get_installed_servers()) do
|
||||||
require('lspconfig')[server_name].setup({
|
require('lspconfig')[server_name].setup({})
|
||||||
on_attach = on_attach
|
|
||||||
})
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- TODO see if there is a way to automatically do this rather than having to manually specify them
|
-- TODO see if there is a way to automatically do this rather than having to manually specify them
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue