feat!: add more options to diagnostics toggling

Co-authored-by: Jaeshii <56745535+Jaeshii@users.noreply.github.com>
This commit is contained in:
Micah Halter
2023-03-10 10:14:43 -05:00
co-authored by Jaeshii
parent 700e6eff3c
commit b7f0830da4
5 changed files with 40 additions and 43 deletions
+1 -2
View File
@@ -52,8 +52,7 @@ local options = astronvim.user_opts("options", {
lsp_handlers_enabled = true, -- enable or disable default vim.lsp.handlers (hover and signatureHelp)
cmp_enabled = true, -- enable completion at start
autopairs_enabled = true, -- enable autopairs at start
diagnostics_enabled = true, -- enable diagnostics at start
status_diagnostics_enabled = true, -- enable diagnostics in statusline
diagnostics_mode = 3, -- set the visibility of diagnostics in the UI (0=off, 1=only show in status line, 2=virtual text off, 3=all on)
icons_enabled = true, -- disable icons in the UI (disable if no nerd font is available)
ui_notifications_enabled = true, -- disable notifications when toggling UI elements
},
+28 -23
View File
@@ -23,34 +23,39 @@ local setup_handlers = user_opts("lsp.setup_handlers", {
function(server, opts) require("lspconfig")[server].setup(opts) end,
})
M.diagnostics = { off = {}, on = {} }
M.diagnostics = { [0] = {}, {}, {}, {} }
M.setup_diagnostics = function(signs)
M.diagnostics = {
off = {
underline = false,
virtual_text = false,
signs = false,
update_in_insert = false,
local default_diagnostics = astronvim.user_opts("diagnostics", {
virtual_text = true,
signs = { active = signs },
update_in_insert = true,
underline = true,
severity_sort = true,
float = {
focused = false,
style = "minimal",
border = "rounded",
source = "always",
header = "",
prefix = "",
},
on = astronvim.user_opts("diagnostics", {
virtual_text = true,
signs = { active = signs },
update_in_insert = true,
underline = true,
severity_sort = true,
float = {
focused = false,
style = "minimal",
border = "rounded",
source = "always",
header = "",
prefix = "",
},
}),
})
M.diagnostics = {
-- diagnostics off
[0] = utils.extend_tbl(
default_diagnostics,
{ underline = false, virtual_text = false, signs = false, update_in_insert = false }
),
-- status only
utils.extend_tbl(default_diagnostics, { virtual_text = false, signs = false }),
-- virtual text off, signs on
utils.extend_tbl(default_diagnostics, { virtual_text = false }),
-- all diagnostics on
default_diagnostics,
}
vim.diagnostic.config(M.diagnostics[vim.g.diagnostics_enabled and "on" or "off"])
vim.diagnostic.config(M.diagnostics[vim.g.diagnostics_mode])
end
M.formatting = user_opts("lsp.formatting", { format_on_save = { enabled = true }, disabled = {} })
+1 -1
View File
@@ -871,7 +871,7 @@ end
-- @usage local heirline_component = { provider = "Example Provider", condition = require("astronvim.utils.status").condition.has_diagnostics }
function M.condition.has_diagnostics(bufnr)
if type(bufnr) == "table" then bufnr = bufnr.bufnr end
return vim.g.status_diagnostics_enabled and #vim.diagnostic.get(bufnr or 0) > 0
return vim.g.diagnostics_mode > 0 and #vim.diagnostic.get(bufnr or 0) > 0
end
--- A condition function if there is a defined filetype
+9 -14
View File
@@ -41,22 +41,17 @@ end
--- Toggle diagnostics
function M.toggle_diagnostics()
local status = "on"
if vim.g.status_diagnostics_enabled then
if vim.g.diagnostics_enabled then
vim.g.diagnostics_enabled = false
status = "virtual text off"
else
vim.g.status_diagnostics_enabled = false
status = "fully off"
end
vim.g.diagnostics_mode = (vim.g.diagnostics_mode - 1) % 4
vim.diagnostic.config(require("astronvim.utils.lsp").diagnostics[vim.g.diagnostics_mode])
if vim.g.diagnostics_mode == 0 then
ui_notify "diagnostics off"
elseif vim.g.diagnostics_mode == 1 then
ui_notify "only status diagnostics"
elseif vim.g.diagnostics_mode == 2 then
ui_notify "virtual text off"
else
vim.g.diagnostics_enabled = true
vim.g.status_diagnostics_enabled = true
ui_notify "all diagnostics on"
end
vim.diagnostic.config(require("astronvim.utils.lsp").diagnostics[bool2str(vim.g.diagnostics_enabled)])
ui_notify(string.format("diagnostics %s", status))
end
--- Toggle background="dark"|"light"
+1 -3
View File
@@ -54,8 +54,7 @@ local config = {
autoformat_enabled = true, -- enable or disable auto formatting at start (lsp.formatting.format_on_save must be enabled)
cmp_enabled = true, -- enable completion at start
autopairs_enabled = true, -- enable autopairs at start
diagnostics_enabled = true, -- enable diagnostics at start
status_diagnostics_enabled = true, -- enable diagnostics in statusline
diagnostics_mode = 3, -- set the visibility of diagnostics in the UI (0=off, 1=only show in status line, 2=virtual text off, 3=all on)
icons_enabled = true, -- disable icons in the UI (disable if no nerd font is available, requires :PackerSync after changing)
ui_notifications_enabled = true, -- disable notifications when toggling UI elements
},
@@ -72,7 +71,6 @@ local config = {
-- Diagnostics configuration (for vim.diagnostics.config({...})) when diagnostics are on
diagnostics = {
virtual_text = true,
underline = true,
},