vim.api.nvim_create_autocmd("LspAttach", { callback = function(event) local client = vim.lsp.get_client_by_id(event.data.client_id) if not client then return end if client:supports_method("textDocument/completion") then vim.lsp.completion.enable(true, client.id, event.buf, { autotrigger = false }) end vim.lsp.inlay_hint.enable(true, { bufnr = event.buf }) local opts = { buffer = event.buf, silent = true } vim.keymap.set( { "n", "x" }, "", "lua vim.lsp.buf.format({async = true})", vim.tbl_extend("force", opts, { desc = "Format buffer" }) ) vim.keymap.set( "n", "grr", "Telescope lsp_references", vim.tbl_extend("force", opts, { desc = "LSP references (Telescope)" }) ) vim.keymap.set( "n", "df", "lua vim.diagnostic.open_float()", vim.tbl_extend("force", opts, { desc = "Diagnostic float" }) ) vim.keymap.set( "n", "dl", "Telescope diagnostics", vim.tbl_extend("force", opts, { desc = "Diagnostics list (Telescope)" }) ) end, }) -- Server configs: cmd/filetypes/root_markers come from nvim-lspconfig. -- rust_analyzer is managed by rustaceanvim. vim.lsp.enable({ "gopls", "nil_ls", "ts_ls" }) -- Add border to the completion documentation popup (not covered by winborder/pumborder) vim.api.nvim_create_autocmd("CompleteChanged", { callback = function() local info = vim.fn.complete_info({ "selected" }) local win = info.preview_winid if win and vim.api.nvim_win_is_valid(win) then vim.api.nvim_win_set_config(win, { border = "rounded" }) end end, }) vim.diagnostic.config({ severity_sort = true, -- Use single-line virtual_text and df for the full message virtual_text = true; virtual_lines = false; float = { border = "rounded", source = true, }, })