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

[Feature Request]: Separate highlight groups for each diagnostic icon #952

Open
Momoyo opened this issue Aug 3, 2024 · 0 comments
Open
Labels
enhancement New feature or request

Comments

@Momoyo
Copy link

Momoyo commented Aug 3, 2024

What?

I'm looking for a way to distinguish each icon with its own highlight group. For example in the diagnostics_indicator option, where the user can formulate a function that returns a string for the diagnostics icons. Maybe it can return a table of tables each containing 1. a string text ( what it currently returns ) plus a string text member for a corresponding highlight group.

Basically treating each of the 4 possible severity icons as their own little components which could be derived from their existing highlight groups or custom HL groups that get passed back, error_diagnostic_selected or warn_diagnostic_selected etc. Instead of one single string that uses the highest severity.

I did a little digging and it seems like the diagnostics.lua where this callback function is called, has access to the parsed highlight group and it gets set based on highest severity. I'm wondering if it won't be too much work / won't affect performance to implement it, I could try doing PR but I'm an absolute newbie at nvim plugins.

diagnostics_indicator = function(count, level, diagnostics_dict, context)
  local s = ""
  for e, n in pairs(diagnostics_dict) do
    local sym = e == "error" and " "
        or (e == "warning" and " " or " ")
    s = s .. sym .. n
  end
  return s
end

I'm assuming for my idea to work, each icon will have to be treated as a separate component in diagnostics.lua before it's used in UI.lua?

  . . .
  local highlights = context.current_highlights
  local element = context.tab
  local diagnostics = element.diagnostics
  if not diagnostics or not diagnostics.count or diagnostics.count < 1 then return end

  local indicator = ""
  if user_indicator and type(user_indicator) == "function" then
    local ctx = { buffer = element, tab = element }
    indicator = user_indicator(diagnostics.count, diagnostics.level, diagnostics.errors, ctx)
  elseif indicator == nil then
    indicator = fmt(" (%s)", diagnostics.count)
  end

  local highlight = highlights[diagnostics.level] or ""
  local diag_highlight = highlights[diagnostics.level .. "_diagnostic"] or highlights.diagnostic or ""
  return {
    text = indicator,
    highlight = diag_highlight,
    attr = {
      extends = {
        { id = ui.components.id.name, highlight = highlight },
        { id = ui.components.id.groups, highlight = highlight },
      },
    },
  }

Why?

These are just personal observations but I think it would look a lot more aesthetically pleasing.
I also think a different color for each icon would help parse them out at a glance and help with the "mental triage" of which files need the most attention or what progress is being made.
Having a single error upgrade the severity of all the other icons intuitively feels wrong to look at.

@Momoyo Momoyo added the enhancement New feature or request label Aug 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant