neovim: Leverage the new LspAttach callback rather than the mason-lspconfig method for LSP-bindings

This commit is contained in:
Tony Blyler 2025-07-17 10:48:47 -04:00
parent e67d669436
commit 3126226ad4
No known key found for this signature in database

View file

@ -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