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,7 +315,15 @@ later(function()
|
|||
})
|
||||
|
||||
-- only perform these mappings if an LSP is attached
|
||||
local on_attach = function(client, buffnr)
|
||||
vim.api.nvim_create_autocmd("LspAttach", {
|
||||
callback = function(args)
|
||||
local client = vim.lsp.get_client_by_id(args.data.client_id)
|
||||
if not client then
|
||||
return
|
||||
end
|
||||
|
||||
local buffnr = args.buf
|
||||
|
||||
local lsp_key = function(lhs, rhs, desc)
|
||||
vim.keymap.set('n', lhs, rhs, { silent = true, buffer = buffnr, desc = desc })
|
||||
end
|
||||
|
@ -333,7 +341,8 @@ later(function()
|
|||
local basics = require('lsp_basics')
|
||||
basics.make_lsp_commands(client, buffnr)
|
||||
basics.make_lsp_mappings(client, buffnr)
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
require('mason').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
|
||||
handlers = {
|
||||
function (server_name)
|
||||
require('lspconfig')[server_name].setup({
|
||||
on_attach = on_attach
|
||||
})
|
||||
require('lspconfig')[server_name].setup({})
|
||||
end
|
||||
}
|
||||
})
|
||||
|
||||
-- make sure LSPs are autostarted if already installed at neovim start
|
||||
for _, server_name in pairs(require('mason-lspconfig').get_installed_servers()) do
|
||||
require('lspconfig')[server_name].setup({
|
||||
on_attach = on_attach
|
||||
})
|
||||
require('lspconfig')[server_name].setup({})
|
||||
end
|
||||
|
||||
-- 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