nix/homes/modules/programs/neovim/lua/lsp/capabilities.lua

66 lines
2.5 KiB
Lua

local M = {}
function M.on_attach(_, bufnr)
-- we create a function that lets us more easily define mappings specific
-- for LSP related items. It sets the mode, buffer and description for us each time.
local nmap = function(keys, func, desc)
if desc then
desc = "LSP: " .. desc
end
vim.keymap.set("n", keys, func, { buffer = bufnr, desc = desc })
end
nmap("<leader>rn", vim.lsp.buf.rename, "[R]e[n]ame")
nmap("<leader>ca", vim.lsp.buf.code_action, "[C]ode [A]ction")
nmap("gd", vim.lsp.buf.definition, "[G]oto [D]efinition")
-- NOTE: why are these functions that call the telescope builtin?
-- because otherwise they would load telescope eagerly when this is defined.
-- due to us using the on_require handler to make sure it is available.
if nixCats("general.telescope") then
nmap("gr", function()
require("telescope.builtin").lsp_references()
end, "[G]oto [R]eferences")
nmap("gI", function()
require("telescope.builtin").lsp_implementations()
end, "[G]oto [I]mplementation")
nmap("<leader>ds", function()
require("telescope.builtin").lsp_document_symbols()
end, "[D]ocument [S]ymbols")
nmap("<leader>ws", function()
require("telescope.builtin").lsp_dynamic_workspace_symbols()
end, "[W]orkspace [S]ymbols")
nmap("<leader>dd", "<cmd>Telescope diagnostics bufnr=0<CR>", "[D]ocument [D]iagnostics")
nmap("<leader>wd", "<cmd>Telescope diagnostics<CR>", "[W]orkspace [D]iagnostics")
end -- TODO: someone who knows the builtin versions of these to do instead help me out please.
nmap("<leader>D", vim.lsp.buf.type_definition, "Type [D]efinition")
nmap("<leader>e", vim.diagnostic.open_float, "Show [E]rror")
-- See `:help K` for why this keymap
nmap("K", vim.lsp.buf.hover, "Hover Documentation")
nmap("<C-k>", vim.lsp.buf.signature_help, "Signature Documentation")
-- Lesser used LSP functionality
nmap("gD", vim.lsp.buf.declaration, "[G]oto [D]eclaration")
nmap("<leader>wa", vim.lsp.buf.add_workspace_folder, "[W]orkspace [A]dd Folder")
nmap("<leader>wr", vim.lsp.buf.remove_workspace_folder, "[W]orkspace [R]emove Folder")
nmap("<leader>wl", function()
print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
end, "[W]orkspace [L]ist Folders")
-- Create a command `:Format` local to the LSP buffer
vim.api.nvim_buf_create_user_command(bufnr, "Format", function(_)
vim.lsp.buf.format()
end, { desc = "Format current buffer with LSP" })
end
function M.get(server_name)
local capabilities = require("blink.cmp").get_lsp_capabilities()
return capabilities
end
return M