mirror of
https://github.com/harivansh-afk/nvim.git
synced 2026-04-15 08:03:44 +00:00
33 lines
1.5 KiB
Lua
33 lines
1.5 KiB
Lua
-- Shared LSP utilities
|
|
local M = {}
|
|
|
|
-- Set up buffer-local keymaps when LSP attaches
|
|
function M.on_attach(client, bufnr)
|
|
local opts = { buffer = bufnr, silent = true }
|
|
|
|
-- Navigation
|
|
vim.keymap.set("n", "gd", vim.lsp.buf.definition, vim.tbl_extend("force", opts, { desc = "Go to definition" }))
|
|
vim.keymap.set("n", "gD", vim.lsp.buf.declaration, vim.tbl_extend("force", opts, { desc = "Go to declaration" }))
|
|
vim.keymap.set("n", "<C-]>", vim.lsp.buf.definition, vim.tbl_extend("force", opts, { desc = "Go to definition" }))
|
|
vim.keymap.set("n", "gi", vim.lsp.buf.implementation, vim.tbl_extend("force", opts, { desc = "Go to implementation" }))
|
|
vim.keymap.set("n", "gr", vim.lsp.buf.references, vim.tbl_extend("force", opts, { desc = "Go to references" }))
|
|
|
|
-- Documentation
|
|
vim.keymap.set("n", "K", vim.lsp.buf.hover, vim.tbl_extend("force", opts, { desc = "Hover documentation" }))
|
|
|
|
-- Refactoring
|
|
vim.keymap.set("n", "<leader>rn", vim.lsp.buf.rename, vim.tbl_extend("force", opts, { desc = "Rename symbol" }))
|
|
vim.keymap.set({ "n", "v" }, "<leader>ca", vim.lsp.buf.code_action, vim.tbl_extend("force", opts, { desc = "Code action" }))
|
|
|
|
-- Formatting
|
|
vim.keymap.set("n", "<leader>f", function()
|
|
vim.lsp.buf.format({ async = true })
|
|
end, vim.tbl_extend("force", opts, { desc = "Format buffer" }))
|
|
end
|
|
|
|
-- Return default capabilities for LSP servers
|
|
function M.capabilities()
|
|
return vim.lsp.protocol.make_client_capabilities()
|
|
end
|
|
|
|
return M
|