Skip to content

feat(#1826): add diagnostics.diagnostic_opts: vim.diagnostic.Opts will override diagnostics.severity and diagnostics.icons #3190

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 3 commits into from
Aug 25, 2025

Conversation

igorlfs
Copy link
Contributor

@igorlfs igorlfs commented Aug 17, 2025

Closes #1826

Based on nvim-lualine/lualine.nvim#1091, which never got merged

Copy link
Member

@alex-courtis alex-courtis left a comment

Choose a reason for hiding this comment

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

Thanks for looking into this one @igorlfs - this will be most useful.

The timing isn't working, however. At nvim-tree startup, diagnostics may not have been configured or even started.

Alternative Implementation

Retrieve the signs dynamically in DiagnosticsDecorator. This will ensure that we pick up the configured signs, and allow the user to change them at runtime.

hint = get_diagnostics_icons(vim.diagnostic.severity.HINT) or "",
info = get_diagnostics_icons(vim.diagnostic.severity.INFO) or "",
warning = get_diagnostics_icons(vim.diagnostic.severity.WARN) or "",
error = get_diagnostics_icons(vim.diagnostic.severity.ERROR) or "",
Copy link
Member

Choose a reason for hiding this comment

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

When the user copies and uses this default config this fails, as get_diagnostics_icons is local to this file.

No matter, we will work around this another way.

@alex-courtis alex-courtis changed the title fix: get diagnostics icons from config (#1826) feat(#1826): use diagnostics icons from vim.diagnostic Aug 18, 2025
@igorlfs
Copy link
Contributor Author

igorlfs commented Aug 18, 2025

Retrieve the signs dynamically in DiagnosticsDecorator. This will ensure that we pick up the configured signs, and allow the user to change them at runtime.

Just pushed a commit following this implementation. LMK if that's not what you meant.

@igorlfs igorlfs force-pushed the fix/1826 branch 2 times, most recently from db41255 to 5821ea7 Compare August 18, 2025 00:28
Copy link
Member

@alex-courtis alex-courtis left a comment

Choose a reason for hiding this comment

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

This is looking good.

However, this will break existing users, as vim diagnostic config will override their diagnostics.icons settings. We will need to add an option to allow the users to enable this if they choose.

*nvim-tree.diagnostics.diagnostic_opts*
|vim.diagnostic.Opts| overrides |nvim-tree.diagnostics.severity| and
|nvim-tree.diagnostics.icons|
  Type: `boolean`, Default: `false`

Please add the severity functionality. Yes, that is scope creep, however we should make the user experience complete.

if type(signs) == "function" then
signs = signs(0, 0)
end
return (type(signs) == "table" and signs.text and signs.text[severity]) or nil
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 safe and is returning correctly with the following test cases:

vim.diagnostic.config({
  signs = function(namespace, bufnr)
    return {
      text = {
        "e", "w", "i", "h",
      }
    }
  end,
})
vim.diagnostic.config({
  signs = {
    text = {
      "e", "w", "i", "h",
    }
  }
})

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, should I add a test for that or something?

Copy link
Member

Choose a reason for hiding this comment

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

No need, we don't actually have any testing.

That's more for my reference so that I can test again.

@@ -3,6 +3,17 @@ local diagnostics = require("nvim-tree.diagnostics")
local Decorator = require("nvim-tree.renderer.decorator")
local DirectoryNode = require("nvim-tree.node.directory")

---@param severity vim.diagnostic.Severity
---@return string?
local function get_diagnostics_icons(severity)
Copy link
Member

Choose a reason for hiding this comment

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

Please make this function a private member.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I inlined it.

@alex-courtis
Copy link
Member

Fantastic, thank you so much for going the extra mile.

I'll get to a review this weekend.

Copy link
Member

@alex-courtis alex-courtis left a comment

Choose a reason for hiding this comment

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

Works beautifully, many thanks for your contribution!

Fixing the trivial CI issues in the name of speed.

@alex-courtis alex-courtis changed the title feat(#1826): use diagnostics icons from vim.diagnostic feat(#1826): add diagnostics.diagnostic_opts: vim.diagnostic.Opts will override diagnostics.severity and diagnostics.icons Aug 25, 2025
@alex-courtis alex-courtis merged commit fefa335 into nvim-tree:master Aug 25, 2025
4 checks passed
@igorlfs igorlfs deleted the fix/1826 branch August 25, 2025 03:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add option to use diagnostic signs
2 participants