local M = {} M.lsp_signs = { Error = "E", Warn = "W", Hint = "H", Info = "I" } function M.on_attach(on_attach) vim.api.nvim_create_autocmd("LspAttach", { callback = function(args) local buffer = args.buf local client = vim.lsp.get_client_by_id(args.data.client_id) on_attach(client, buffer) end, }) end --[[ TODO: cmdlineheight = 0 makes notifications not visible for some reasons notifications in M.toggle_diagnostics() works just fine ]] function M.warn(msg, notify_opts) vim.notify(msg, vim.log.levels.WARN, notify_opts) end function M.error(msg, notify_opts) vim.notify(msg, vim.log.levels.ERROR, notify_opts) end function M.info(msg, notify_opts) vim.notify(msg, vim.log.levels.INFO, notify_opts) end ---@param silent boolean? ---@param values? {[1]:any, [2]:any} function M.toggle(option, silent, values) if values then if vim.opt_local[option]:get() == values[1] then vim.opt_local[option] = values[2] else vim.opt_local[option] = values[1] end M.info("Set " .. option .. " to " .. vim.opt_local[option]:get(), { title = "Option" }) else vim.opt_local[option] = not vim.opt_local[option]:get() if not silent then if vim.opt_local[option]:get() then M.info("Enabled " .. option, { title = "Option" }) else M.warn("Disabled " .. option, { title = "Option" }) end end end end M.diagnostics_active = true function M.toggle_diagnostics() M.diagnostics_active = not M.diagnostics_active if M.diagnostics_active then vim.diagnostic.show() M.info("Enabled Diagnostics", { title = "Lsp" }) vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, {}) else vim.diagnostic.hide() M.warn("Disabled Diagnostics", { title = "Lsp" }) vim.lsp.handlers["textDocument/publishDiagnostics"] = function() end end end function M.set_colorcolumn() local colorcolumn = vim.o.colorcolumn if colorcolumn == "80" then vim.o.colorcolumn = "0" M.info("Color Column disabled") else vim.o.colorcolumn = "80" M.info("Color Column set to 80") end end return M