78 lines
2.5 KiB
Lua
78 lines
2.5 KiB
Lua
|
|
-- Native LSP — no nvim-lspconfig plugin required.
|
||
|
|
-- Server configs live in ~/.config/nvim/lsp/
|
||
|
|
-- Servers must be on your PATH (install via npm/pip/dnf etc.)
|
||
|
|
|
||
|
|
-- Global capabilities applied to every server
|
||
|
|
vim.lsp.config("*", {
|
||
|
|
capabilities = {
|
||
|
|
textDocument = {
|
||
|
|
completion = {
|
||
|
|
completionItem = {
|
||
|
|
snippetSupport = true,
|
||
|
|
resolveSupport = {
|
||
|
|
properties = { "documentation", "detail", "additionalTextEdits" },
|
||
|
|
},
|
||
|
|
},
|
||
|
|
},
|
||
|
|
},
|
||
|
|
},
|
||
|
|
})
|
||
|
|
|
||
|
|
-- Enable servers (configs are in lsp/ directory)
|
||
|
|
vim.lsp.enable({
|
||
|
|
"ts_ls",
|
||
|
|
"bashls",
|
||
|
|
"cssls",
|
||
|
|
"eslint",
|
||
|
|
"html",
|
||
|
|
"jsonls",
|
||
|
|
"ruff",
|
||
|
|
"pyright",
|
||
|
|
"yamlls",
|
||
|
|
"marksman",
|
||
|
|
"clangd",
|
||
|
|
})
|
||
|
|
|
||
|
|
-- Per-buffer setup on attach
|
||
|
|
vim.api.nvim_create_autocmd("LspAttach", {
|
||
|
|
group = vim.api.nvim_create_augroup("user.lsp", { clear = true }),
|
||
|
|
callback = function(ev)
|
||
|
|
local client = vim.lsp.get_client_by_id(ev.data.client_id)
|
||
|
|
local buf = ev.buf
|
||
|
|
|
||
|
|
-- Native completion (0.12)
|
||
|
|
if client and client:supports_method("textDocument/completion") then
|
||
|
|
vim.lsp.completion.enable(true, client.id, buf, { autotrigger = true })
|
||
|
|
end
|
||
|
|
|
||
|
|
-- Format on save
|
||
|
|
if client and client:supports_method("textDocument/formatting") then
|
||
|
|
vim.api.nvim_create_autocmd("BufWritePre", {
|
||
|
|
group = vim.api.nvim_create_augroup("user.lsp.format." .. buf, { clear = true }),
|
||
|
|
buffer = buf,
|
||
|
|
callback = function()
|
||
|
|
vim.lsp.buf.format({ bufnr = buf, id = client.id })
|
||
|
|
end,
|
||
|
|
})
|
||
|
|
end
|
||
|
|
|
||
|
|
-- Keymaps (replaces lspsaga bindings)
|
||
|
|
-- 0.12 provides gra, grn, grr, gri, gO, K globally by default.
|
||
|
|
-- These add your existing <leader> bindings on top:
|
||
|
|
local map = function(keys, fn, desc)
|
||
|
|
vim.keymap.set("n", keys, fn, { buffer = buf, desc = desc })
|
||
|
|
end
|
||
|
|
|
||
|
|
map("gd", vim.lsp.buf.definition, "Go to definition")
|
||
|
|
map("<leader>gf", vim.lsp.buf.definition, "Go to definition (alt)")
|
||
|
|
map("<leader>g", vim.lsp.buf.definition, "Peek definition (native fallback)")
|
||
|
|
map("<leader>K", vim.lsp.buf.hover, "Hover doc")
|
||
|
|
map("<leader>y", vim.lsp.buf.references, "References")
|
||
|
|
map("<leader>rn", vim.lsp.buf.rename, "Rename")
|
||
|
|
map("<leader>b", vim.lsp.buf.code_action, "Code action")
|
||
|
|
map("<leader>r", vim.diagnostic.open_float,"Show line diagnostics")
|
||
|
|
map("[d", vim.diagnostic.goto_prev, "Previous diagnostic")
|
||
|
|
map("]d", vim.diagnostic.goto_next, "Next diagnostic")
|
||
|
|
end,
|
||
|
|
})
|