local M = {} ---@type vim.lsp.client.on_attach_cb M.on_attach = function(client, bufnr) local telescope = require("telescope.builtin") local methods = vim.lsp.protocol.Methods ---@param bind string ---@param cmd function | string ---@param desc string ---@param extraArgs? table local function nnoremap(bind, cmd, desc, extraArgs) local args = { buffer = bufnr, desc = "LSP: " .. desc, } args = vim.tbl_deep_extend("keep", args, extraArgs or {}) vim.keymap.set("n", bind, cmd, args) end nnoremap("K", vim.lsp.buf.hover, "hover") nnoremap("", vim.lsp.buf.signature_help, "signature help") nnoremap("gd", telescope.lsp_definitions, "goto definition(s) (telescope)") nnoremap("gu", telescope.lsp_references, "goto usage(s) (telescope)") nnoremap("ca", vim.lsp.buf.code_action, "code action") -- TODO: Maybe remove these or use the defaults? nnoremap("cl", vim.lsp.codelens.run, "run codelens") nnoremap("r", vim.lsp.buf.rename, "rename symbol") pcall(nnoremap, "f", function() vim.lsp.buf.format { async = true } end, "format buffer", { unique = true }) vim.api.nvim_buf_create_user_command( bufnr, "LspToggleInlayHints", function() vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled()) end, {} ) local filetype = vim.api.nvim_get_option_value("filetype", { buf = bufnr }) if client:supports_method(methods.textDocument_inlayHint) -- Never start cabal with inlay hint request -- Related: https://github.com/mrcjkb/haskell-tools.nvim/discussions/485 and filetype ~= "cabal" -- I find it annoying especially with qmk and filetype ~= "c" then vim.lsp.inlay_hint.enable(true, { bufnr = bufnr }) end end local capabilities = vim.lsp.protocol.make_client_capabilities() capabilities = require("cmp_nvim_lsp").default_capabilities(capabilities) ---@type lsp.ClientCapabilities M.capabilities = capabilities ---@type string|(string|[string,string])[] M.border = { { " ", "FloatBorder" }, { " ", "FloatBorder" }, { " ", "FloatBorder" }, { " ", "FloatBorder" }, { " ", "FloatBorder" }, { " ", "FloatBorder" }, { " ", "FloatBorder" }, { " ", "FloatBorder" }, } return M