Skip to content

Commit

Permalink
feat: make live diagnostics level configurable (#776)
Browse files Browse the repository at this point in the history
* feat: make severity_limit configurable(#774), add more notes for users.

* fixup! feat: make severity_limit configurable(#774), add more notes for users.

---------

Co-authored-by: Jint-lzxy <[email protected]>
  • Loading branch information
ayamir and Jint-lzxy authored May 30, 2023
1 parent 8437261 commit 1926dc0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
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

0 comments on commit 1926dc0

Please sign in to comment.