-- Use an on_attach function to only map the following keys -- after the language server attaches to the current buffer local on_attach = function(client, bufnr) -- Mappings. -- See `:help vim.lsp.*` for documentation on any of the below functions local bufopts = { noremap = true, silent = true, buffer = bufnr } vim.keymap.set("n", "gd", vim.lsp.buf.definition, bufopts) vim.keymap.set("n", "gr", vim.lsp.buf.references, bufopts) vim.keymap.set("n", "gi", vim.lsp.buf.implementation, bufopts) vim.keymap.set("n", "K", vim.lsp.buf.hover, bufopts) vim.keymap.set("n", "D", vim.lsp.buf.type_definition, bufopts) vim.keymap.set("n", "rn", vim.lsp.buf.rename, bufopts) vim.keymap.set("n", "ca", vim.lsp.buf.code_action, bufopts) vim.keymap.set( "n", "i", function() vim.lsp.buf.format { bufnr = bufnr, timeout_ms = 2000, async = true } end, bufopts ) -- specific client tweaks if client.name ~= "null-ls" then client.server_capabilities.documentFormattingProvider = false end if client.name == "ruff_lsp" then client.server_capabilities.hoverProvider = false end -- Attach navic and navbuddy if applicable if client.server_capabilities.documentSymbolProvider then require("nvim-navic").attach(client, bufnr) require("nvim-navbuddy").attach(client, bufnr) end end return on_attach