Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: make live diagnostics level configurable #776

Merged
merged 2 commits into from
May 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion lua/core/settings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,16 @@ settings["format_on_save"] = true
settings["format_notify"] = true

-- Set it to false if diagnostics virtual text is annoying.
-- If disabled, you may browse lsp diagnostics using trouble.nvim (press `gt` to toggle it).
---@type boolean
settings["diagnostics_virtual_text"] = true
settings["diagnostics_virtual_text"] = false

-- Set it to one of the values below if you want to change the visible severity level of lsp diagnostics.
-- Priority: `Error` > `Warning` > `Information` > `Hint`.
-- > e.g. if you set this option to `Warning`, only lsp warnings and errors will be shown.
-- NOTE: This entry only works when `diagnostics_virtual_text` is true.
---@type "Error"|"Warning"|"Information"|"Hint"
settings["diagnostics_level"] = "Hint"

-- Set the format disabled directories here, files under these dirs won't be formatted on save.
---@type string[]
Expand Down
7 changes: 6 additions & 1 deletion lua/modules/configs/completion/lsp.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
return function()
local diagnostics_virtual_text = require("core.settings").diagnostics_virtual_text
local diagnostics_level = require("core.settings").diagnostics_level

local nvim_lsp = require("lspconfig")
local mason = require("mason")
local mason_registry = require("mason-registry")
Expand Down Expand Up @@ -93,7 +96,9 @@ return function()
vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, {
signs = true,
underline = true,
virtual_text = require("core.settings").diagnostics_virtual_text,
virtual_text = diagnostics_virtual_text and {
severity_limit = diagnostics_level,
} or false,
-- set update_in_insert to false bacause it was enabled by lspsaga
update_in_insert = false,
})
Expand Down