vim.api.nvim_create_autocmd('LspAttach', { callback = function(args) local client = vim.lsp.get_client_by_id(args.data.client_id) if not client then return end vim.bo[args.buf].omnifunc = 'v:lua.MiniCompletion.completefunc_lsp' -- Prefer LSP folding if client supports it if client:supports_method('textDocument/foldingRange') then local win = vim.api.nvim_get_current_win() vim.wo[win][0].foldexpr = 'v:lua.vim.lsp.foldexpr()' end vim.keymap.set({ "n", "x", "v" }, "la", vim.lsp.buf.code_action, { buffer = args.buf, desc = "Code Action" }) vim.keymap.set({ "n", "x", "v" }, "ld", vim.diagnostic.open_float, { desc = "Show diagnostic under cursor" }) vim.keymap.set({ "n", "x", "v" }, "lc", function() local curpos = vim.fn.getcurpos() local diagnostics = vim.diagnostic.get(0, { lnum = curpos[2] - 1 }) if #diagnostics == 0 then vim.notify("No diagnostic under cursor") return end local diagnostic = diagnostics[1] local msg = string.format("%s [%s]: %s", diagnostic.source, diagnostic.code, diagnostic.message) vim.fn.setreg("+", msg) vim.notify("Diagnostic saved to clipboard:\n\n" .. msg) end, { buffer = args.buf, desc = "Copy diagnostic to clipboard" }) end, })