--- @param client vim.lsp.Client --- @param bufnr number local on_attach = function(client, bufnr) --- @param desc string? --- @return vim.keymap.set.Opts? local function opts(desc) if desc then ---@diagnostic disable-next-line: return-type-mismatch return { silent = true, buffer = bufnr, desc = desc } else ---@diagnostic disable-next-line: return-type-mismatch return { silent = true, buffer = bufnr } end end vim.keymap.set("n", "K", function() vim.lsp.buf.hover() end, opts("Show hover information")) vim.keymap.set("n", "gd", "Telescope lsp_definitions", opts("Find definitions")) vim.keymap.set("n", "gD", vim.lsp.buf.declaration, opts("Find declaration")) vim.keymap.set("n", "gi", "Telescope lsp_implementations", opts("Find implementations")) vim.keymap.set("n", "gt", "Telescope lsp_type_definitions", opts("Find type definitions")) vim.keymap.set("n", "gR", "Telescope lsp_references", opts("Find references")) vim.keymap.set("n", "vws", function() vim.lsp.buf.workspace_symbol() end, opts("Search workspace symbols")) vim.keymap.set("n", "vd", function() vim.diagnostic.open_float() end, opts("Open diagnostics")) -- vim.keymap.set("n", "vca", function() -- vim.lsp.buf.code_action() -- end, opts("Get code actions")) vim.keymap.set("n", "vca", function() require("tiny-code-action").code_action({}) end, opts("Get code actions")) vim.keymap.set("n", "vr", function() return ":IncRename " .. vim.fn.expand("") ---@diagnostic disable-next-line: param-type-not-match end, { expr = true, silent = true, buffer = bufnr, desc = "Rename symbol" }) vim.keymap.set("n", "vn", function() vim.lsp.buf.rename() end, opts("Rename symbol")) vim.keymap.set("n", "vh", function() if vim.fn.has("nvim-0.10.0") == 0 then vim.notify("Inlay hints are only available in Neovim 0.10.0 and above", vim.log.levels.ERROR) return end if client.server_capabilities == nil then return end if client.server_capabilities.inlayHintProvider then local current_state = vim.lsp.inlay_hint.is_enabled({ bufnr = bufnr }) vim.lsp.inlay_hint.enable(not current_state, { bufnr = bufnr }) end end, opts("Toggle inlay hints")) vim.keymap.set("n", "[d", function() vim.diagnostic.jump({ count = 1, float = true }) end, opts("Go to next diagnostic")) vim.keymap.set("n", "]d", function() vim.diagnostic.jump({ count = -1, float = true }) end, opts("Go to previous diagnostic")) vim.keymap.set("i", "", function() vim.lsp.buf.signature_help() end, opts("Show signature help")) end return on_attach