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 local function nnoremap(bind, cmd, desc) local args = { buffer = bufnr, desc = "LSP: " .. desc, } 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") nnoremap("f", function() vim.lsp.buf.format { async = true } end, "format buffer") 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" 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