mirror of
https://github.com/harivansh-afk/nvim.git
synced 2026-04-15 10:05:17 +00:00
net config
This commit is contained in:
parent
93b7b93d64
commit
dd59a54b92
36 changed files with 960 additions and 631 deletions
41
lua/config/lsp.lua
Normal file
41
lua/config/lsp.lua
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
-- 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()
|
||||
local capabilities = vim.lsp.protocol.make_client_capabilities()
|
||||
|
||||
-- If nvim-cmp is available, extend capabilities
|
||||
local ok, cmp_nvim_lsp = pcall(require, "cmp_nvim_lsp")
|
||||
if ok then
|
||||
capabilities = vim.tbl_deep_extend("force", capabilities, cmp_nvim_lsp.default_capabilities())
|
||||
end
|
||||
|
||||
return capabilities
|
||||
end
|
||||
|
||||
return M
|
||||
Loading…
Add table
Add a link
Reference in a new issue