Skip to content

feat: Support diagnostics severity #1755

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

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 5 additions & 0 deletions doc/nvim-tree-lua.txt
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ Subsequent calls to setup will replace the previous configuration.
enable = false,
show_on_dirs = false,
debounce_delay = 50,
severity = null,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please run update-help.sh as per https://github.com/nvim-tree/nvim-tree.lua/blob/master/CONTRIBUTING.md

This will set the default value.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

icons = {
hint = "",
info = "",
Expand Down Expand Up @@ -548,6 +549,10 @@ Show LSP and COC diagnostics in the signcolumn
Icons for diagnostic severity.
Type: `table`, Default: `{ hint = "", info = "", warning = "", error = "" }`

*nvim-tree.diagnostics.severity*
Controls the severity of the diagnostics.
Type: |vim.diagnostic.severity|, Default: vim.diagnostic.severity.HINT

`NOTE`: it will use the default diagnostic color groups to highlight the signs.
If you wish to customize, you can override these groups:
- `NvimTreeLspDiagnosticsError`
Expand Down
7 changes: 4 additions & 3 deletions lua/nvim-tree.lua
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,9 @@ function M.on_enter(netrw_disabled)
end

local should_hijack = _config.hijack_directories.enable
and _config.hijack_directories.auto_open
and is_dir
and not should_be_preserved
and _config.hijack_directories.auto_open
and is_dir
and not should_be_preserved

-- Session that left a NvimTree Buffer opened, reopen with it
local existing_tree_wins = find_existing_windows()
Expand Down Expand Up @@ -569,6 +569,7 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS
enable = false,
show_on_dirs = false,
debounce_delay = 50,
severity = vim.diagnostic.severity.HINT,
icons = {
hint = "",
info = "",
Expand Down
3 changes: 2 additions & 1 deletion lua/nvim-tree/diagnostics.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ end
local function from_nvim_lsp()
local buffer_severity = {}

for _, diagnostic in ipairs(vim.diagnostic.get()) do
for _, diagnostic in ipairs(vim.diagnostic.get(nil, { severity = M.severity })) do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is showing only the diagnostics with that exact severity.

:help diagnostic-severity indicates that you will need to set a min level.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's correct I'll the default value to { min = vim.diagnostic.severity.HINT }. But I think it's good to keep it like that here so it becomes compatible with other functions that uses severity as an options as per the docs. Example below. What do you think? ^^

1. A single [vim.diagnostic.severity](https://neovim.io/doc/user/diagnostic.html#vim.diagnostic.severity) value:
vim.diagnostic.get(0, { severity = vim.diagnostic.severity.WARN })


2. A table with a "min" or "max" key (or both):
vim.diagnostic.get(0, { severity = { min = vim.diagnostic.severity.WARN } })

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could simply make it explicit in the config and pass it directly to get()

diagnostics = {
  severity = {
    min = vim.diagnostic.severity.HINT,
    max = vim.diagnostic.severity.ERROR,
  },
}

This configuration will be validated at setup time.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect ^^ I'll do it like that. Thanks!

local buf = diagnostic.bufnr
if vim.api.nvim_buf_is_valid(buf) then
local bufname = vim.api.nvim_buf_get_name(buf)
Expand Down Expand Up @@ -140,6 +140,7 @@ local links = {
function M.setup(opts)
M.enable = opts.diagnostics.enable
M.debounce_delay = opts.diagnostics.debounce_delay
M.severity = opts.diagnostics.severity

if M.enable then
log.line("diagnostics", "setup")
Expand Down