.files/.config/nvim/lua/lsp.lua

59 lines
2.1 KiB
Lua

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("<C-k>", 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("<leader>ca", vim.lsp.buf.code_action, "code action")
-- TODO: Maybe remove these or use the defaults?
nnoremap("<leader>cl", vim.lsp.codelens.run, "run codelens")
nnoremap("<leader>r", vim.lsp.buf.rename, "rename symbol")
pcall(nnoremap, "<leader>f", function() vim.lsp.buf.format { async = true } end, "format buffer", { unique = true })
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