Add descriptive desc attributes to 46 keybindings across keys.lua, _shared.lua (LSP), barbar, nvim-tree, telescope, hop, and toggleterm. Update which-key groups: find, buffers, goto/lsp. Hide buffer number keys (1-9, 0) from the popup since they're self-explanatory. Remove REFACTOR_PLAN.md and its gitignore entry.
90 lines
3.6 KiB
Lua
90 lines
3.6 KiB
Lua
-- Shared LSP configuration applied to all language servers via LspAttach.
|
||
-- Individual language modules should NOT define on_attach — this handles it globally.
|
||
|
||
-- Diagnostic signs (global, only needs to be set once)
|
||
vim.diagnostic.config({
|
||
signs = {
|
||
text = {
|
||
[vim.diagnostic.severity.ERROR] = "🛑",
|
||
[vim.diagnostic.severity.WARN] = "⚠️",
|
||
[vim.diagnostic.severity.HINT] = "💡",
|
||
[vim.diagnostic.severity.INFO] = "ℹ️",
|
||
},
|
||
},
|
||
})
|
||
|
||
-- LspAttach autocmd: runs whenever any LSP server attaches to a buffer
|
||
vim.api.nvim_create_autocmd('LspAttach', {
|
||
callback = function(ev)
|
||
local client = vim.lsp.get_client_by_id(ev.data.client_id)
|
||
local buf = ev.buf
|
||
|
||
-- Enable inlay hints if supported
|
||
if client and client.server_capabilities.inlayHintProvider then
|
||
vim.lsp.inlay_hint.enable(true)
|
||
end
|
||
|
||
-- LSP Keymaps
|
||
vim.keymap.set('n', 'g[', vim.diagnostic.goto_prev, {buffer = buf, desc = 'Prev diagnostic',})
|
||
vim.keymap.set('n', 'g]', vim.diagnostic.goto_next, {buffer = buf, desc = 'Next diagnostic',})
|
||
vim.keymap.set('n', 'ga', vim.lsp.buf.code_action, {buffer = buf, desc = 'Code action',})
|
||
vim.keymap.set('n', 'gh', vim.lsp.buf.hover, {buffer = buf, desc = 'Hover info',})
|
||
vim.keymap.set('i', '<C-Space>', vim.lsp.buf.hover, {buffer = buf, desc = 'Hover info',})
|
||
vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, {buffer = buf, desc = 'Go to implementation',})
|
||
vim.keymap.set('n', 'gs', vim.lsp.buf.signature_help, {buffer = buf, desc = 'Signature help',})
|
||
vim.keymap.set('n', 'gD', vim.lsp.buf.type_definition, {buffer = buf, desc = 'Type definition',})
|
||
vim.keymap.set('n', 'gR', vim.lsp.buf.references, {buffer = buf, desc = 'Find references',})
|
||
vim.keymap.set('n', 'gr', vim.lsp.buf.rename, {buffer = buf, desc = 'Rename symbol',})
|
||
vim.keymap.set('n', 'g0', vim.lsp.buf.document_symbol, {buffer = buf, desc = 'Document symbols',})
|
||
vim.keymap.set('n', 'gW', vim.lsp.buf.workspace_symbol, {buffer = buf, desc = 'Workspace symbols',})
|
||
vim.keymap.set('n', 'gd', vim.lsp.buf.definition, {buffer = buf, desc = 'Go to definition',})
|
||
|
||
-- Toggle inlay hints
|
||
vim.keymap.set('n', 'g-', function()
|
||
vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled())
|
||
end, {buffer = buf, desc = 'Toggle inlay hints',})
|
||
|
||
-- Format on save
|
||
if client and client.supports_method('textDocument/formatting') then
|
||
local fmt_group = vim.api.nvim_create_augroup('LspFormatOnSave_' .. buf, {clear = true,})
|
||
vim.api.nvim_create_autocmd('BufWritePre', {
|
||
group = fmt_group,
|
||
buffer = buf,
|
||
callback = function()
|
||
local ft_format_opts = {
|
||
lua = {tabSize = 2, insertSpaces = true,},
|
||
}
|
||
vim.lsp.buf.format({
|
||
async = false,
|
||
formatting_options = ft_format_opts[vim.bo.filetype],
|
||
})
|
||
end,
|
||
})
|
||
end
|
||
|
||
-- Manual format
|
||
vim.keymap.set('n', 'gf', function()
|
||
vim.lsp.buf.format {async = true,}
|
||
end, {buffer = buf, desc = 'Format buffer',})
|
||
end,
|
||
})
|
||
|
||
local M = {}
|
||
|
||
--- Build base capabilities for LSP servers (with blink.cmp support).
|
||
--- @param snippet_support boolean? Whether to advertise snippet support (default false)
|
||
--- @return table capabilities
|
||
function M.make_capabilities(snippet_support)
|
||
local capabilities = vim.lsp.protocol.make_client_capabilities()
|
||
local ok, blink = pcall(require, 'blink.cmp')
|
||
if ok then
|
||
capabilities = blink.get_lsp_capabilities(capabilities)
|
||
end
|
||
if not snippet_support then
|
||
capabilities.textDocument.completion.completionItem.snippetSupport = false
|
||
end
|
||
return capabilities
|
||
end
|
||
|
||
return M
|