Files
nvim-config/lua/languages/_shared.lua
T
Aaron Gorodetzky c4c7f16d2c Replace nvim-cmp with blink.cmp
Replace nvim-cmp and 5 cmp-* plugins with saghen/blink.cmp (v1 stable).
blink.cmp bundles LSP, buffer, path, cmdline completion in one plugin
with async fuzzy matching and typo resistance.

- Preserves keybindings: C-k/C-j nav, C-Space show, C-e abort, CR confirm
- No snippets (preset = 'none')
- Signature help enabled
- Cmdline completion enabled
- LazyDev integrated as blink source provider
- _shared.lua capabilities updated to use blink.get_lsp_capabilities()
- Removes cmp-nvim-lsp dependency from lsp.lua
2026-09-14 10:18:31 -04:00

91 lines
3.1 KiB
Lua
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
-- 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
local opts = {buffer = 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, opts)
vim.keymap.set('n', 'g]', vim.diagnostic.goto_next, opts)
vim.keymap.set('n', 'ga', vim.lsp.buf.code_action, opts)
vim.keymap.set('n', 'gh', vim.lsp.buf.hover, opts)
vim.keymap.set('i', '<C-Space>', vim.lsp.buf.hover, opts)
vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, opts)
vim.keymap.set('n', 'gs', vim.lsp.buf.signature_help, opts)
vim.keymap.set('n', 'gD', vim.lsp.buf.type_definition, opts)
vim.keymap.set('n', 'gR', vim.lsp.buf.references, opts)
vim.keymap.set('n', 'gr', vim.lsp.buf.rename, opts)
vim.keymap.set('n', 'g0', vim.lsp.buf.document_symbol, opts)
vim.keymap.set('n', 'gW', vim.lsp.buf.workspace_symbol, opts)
vim.keymap.set('n', 'gd', vim.lsp.buf.definition, opts)
-- Toggle inlay hints
vim.keymap.set('n', 'g-', function()
vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled())
end, opts)
-- 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, opts)
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