1vim.diagnostic.config({
2 severity_sort = true,
3 float = {
4 border = "rounded",
5 source = true,
6 header = "",
7 prefix = "",
8 },
9 signs = {
10 text = {
11 [vim.diagnostic.severity.ERROR] = "",
12 [vim.diagnostic.severity.WARN] = "",
13 [vim.diagnostic.severity.INFO] = "",
14 [vim.diagnostic.severity.HINT] = "",
15 },
16 },
17})
18
19vim.api.nvim_create_autocmd("LspAttach", {
20 group = vim.api.nvim_create_augroup("user_config_lsp_attach", { clear = true }),
21 callback = function(event)
22 local keymaps = {
23 ---------------------- Hover & Signature -----------------------
24 { "K", function() vim.lsp.buf.hover({ border = "rounded" }) end, desc = "Hover Documentation" },
25 { "gK", function() vim.lsp.buf.signature_help({ border = "rounded" }) end, desc = "Signature Help" },
26
27 ---------------------- Goto / Navigation -----------------------
28 { "gd", vim.lsp.buf.definition, desc = "Goto Definition" },
29 { "gD", vim.lsp.buf.declaration, desc = "Goto Declaration" },
30 { "gi", vim.lsp.buf.implementation, desc = "Goto Implementation" },
31 { "gy", vim.lsp.buf.type_definition, desc = "Goto Type Definition" },
32 { "gr", vim.lsp.buf.references, desc = "References" },
33 -- { "gr", function() Snacks.picker.lsp_references() end, desc = "References" },
34
35 ------------------------- Diagnostics --------------------------
36 { "gl", vim.diagnostic.open_float, desc = "Show Line Diagnostics" },
37 { "]d", function() vim.diagnostic.jump({ count = 1, float = true }) end, desc = "Next Diagnostic" },
38 { "[d", function() vim.diagnostic.jump({ count = -1, float = true }) end, desc = "Prev Diagnostic" },
39 { "<Leader>lj", function() vim.diagnostic.jump({ count = 1, float = true }) end, desc = "Next Diagnostic" },
40 { "<Leader>lk", function() vim.diagnostic.jump({ count = -1, float = true }) end, desc = "Prev Diagnostic" },
41 { "<Leader>lq", vim.diagnostic.setloclist, desc = "Diagnostics → Loclist" },
42 { "<Leader>ld", function() Snacks.picker.diagnostics_buffer() end, desc = "Buffer Diagnostics" },
43 { "<Leader>lD", function() Snacks.picker.diagnostics() end, desc = "Workspace Diagnostics" },
44
45 -------------------- Code Actions & Lenses ---------------------
46 { "<Leader>la", vim.lsp.buf.code_action, desc = "Code Action", mode = { "n", "x" } },
47 { "<Leader>lf", vim.lsp.buf.format, desc = "Format Document" },
48 { "<Leader>lr", vim.lsp.buf.rename, desc = "Rename Symbol" },
49 { "<Leader>lc", vim.lsp.codelens.run, desc = "Run CodeLens" },
50
51 --------------------- Symbols & Workspace ----------------------
52 { "<Leader>ls", function() Snacks.picker.lsp_symbols() end, desc = "Symbols" },
53 { "<Leader>lS", function() Snacks.picker.lsp_workspace_symbols() end, desc = "Workspace Symbols" },
54 { "<Leader>ll", "<Cmd>Trouble lsp toggle focus=false<CR>", desc = "LSP Definitions / References / ... (Trouble)" },
55
56 -------------------------- Misc LSP ----------------------------
57 { "<Leader>li", "<Cmd>LspInfo<CR>", desc = "LSP Info" },
58 { "<Leader>lR", "<Cmd>LspRestart<CR>", desc = "Restart LSP" },
59 }
60
61 for _, map in ipairs(keymaps) do
62 local lhs, rhs = map[1], map[2]
63 vim.keymap.set(map.mode or "n", lhs, rhs, {
64 buffer = event.buf,
65 desc = map.desc,
66 silent = true,
67 })
68 end
69 end,
70})