nvim-lualine / lualine.nvim

A blazing fast and easy to configure neovim statusline plugin written in pure lua.
MIT License
5.93k stars 462 forks source link

Bug: Diagnostics color issues #402

Closed tristan957 closed 2 years ago

tristan957 commented 2 years ago

Self Checks

How to reproduce the problem

require("lualine").setup({
    options = {
        icons_enabled = false,
        theme = "powerline",
        component_separators = { left = "|", right = "|" },
        section_separators = { left = "", right = "" },
    },
    sections = {
        lualine_b = {
            "branch",
            "diff",
        },
        lualine_c = {
            {
                "diagnostics",
                sources = { "nvim_lsp", "coc" },
                sections = { "error", "warn", "info", "hint" },
                diagnostics_color = {
                    error = false,
                    warn = false,
                    info = false,
                    hint = false,
                },
                symbols = { error = "E", warn = "W", info = "I", hint = "H" },
                always_visible = true,
                update_in_insert = false,
                color = nil,
            },
            "filename",
            require("lsp-status").status,
        },
    },
})

Expected behaviour

diagnostics_color should have an effect when set to nil, meaning unset the color. The background color of the diagnostics should follow the theme when switching modes.

Actual behaviour

diagnostics_color members don't get unset when set to nil. Background color doesn't update with theme when switching modes.

shadmansaleh commented 2 years ago

Did you try setting colored option to false ?

lualine_c = {
            {
                "diagnostics",
                                colored = false,
                sources = { "nvim_lsp", "coc" },
                    }
                    }
tristan957 commented 2 years ago

Yes, but then you don't get the nice foreground colors.

Side note, I think in the "general component config" section, it uses "color" instead of "colored".

shadmansaleh commented 2 years ago

Side note, I think in the "general component config" section, it uses "color" instead of "colored".

colored is specific to diagnostics & diff component but I can see it's not documented under diagnostics .

Yes, but then you don't get the nice foreground colors.

I though you wanted to get rid of colors ?? I don't think I understand the issue can you elaborate ?

tristan957 commented 2 years ago

This is really two issues in one.

  1. When colored=true, the diagnostics background doesn't change with the theme when modes change.

  2. The individual colors in diagnostic_colors have no effect when set to nil as shown in the documentation.

shadmansaleh commented 2 years ago

The individual colors in diagnostic_colors have no effect when set to nil as shown in the documentation.

It doesn't have an effect .In lua when you set an entry to nil it deletes that entry . The nil was written just two show what fields are available for that table.

the diagnostics background doesn't change with the theme when modes change.

This might be a bug . I'll take a look.

tristan957 commented 2 years ago

Thanks for the correction on 2.

shadmansaleh commented 2 years ago

Can you check if the issue is fixed?

tristan957 commented 2 years ago

Works like a charm.

tristan957 commented 2 years ago

@shadmansaleh seeing the following issue:

image

Here is my current setup:

require("lualine").setup({
    options = {
        icons_enabled = false,
        theme = "powerline",
        component_separators = { left = "|", right = "|" },
        section_separators = { left = "", right = "" },
    },
    sections = {
        lualine_b = {
            "branch",
            "diff",
        },
        lualine_c = {
            "filename",
            {
                "diagnostics",
                sources = { "nvim_diagnostic" },
                diagnostics_color = {
                    error = "DiagnosticError",
                    warn = "DiagnosticWarn",
                    info = "DiagnosticInfo",
                    hint = "DiagnosticHint",
                },
                sections = { "error", "warn", "info", "hint" },
                symbols = { error = "E", warn = "W", info = "I", hint = "H" },
                always_visible = false,
                update_in_insert = false,
            },
            require("lsp-status").status(),
        },
    },
})

This seems very much like the the original issue if I remember. I would have expected the background color of the diagnostics section to be the same as the rest of the theme.

imjasonmiller commented 2 years ago

@tristan957 I'm experiencing the same for what it's worth, practically the same configuration, but using gruvbox for now, also expected it to default to the background of e.g. diff to the left of it.

Lualine diagnostics component having a different background color to other components

Setting colored to false for diagnostics properly sets the background, but does remove the foreground color, unlike with diff? Lualine diagnostics component with the 'colored' property set to false


The plugin is amazing so far @shadmansaleh, thank you!

tristan957 commented 2 years ago

So I found the issue: image

You can see that there is not bg defined, just this "links to" thing

tristan957 commented 2 years ago

I think using linking here is incorrect. We need to apply the currently linked color as the foreground and apply the background as necessary. @shadmansaleh any thoughts? Would probably help to re-open this.

tristan957 commented 2 years ago

To evaluate a highlight group, use the following:

vim.fn.synIDattr(vim.fn.hlID("DiagnosticError"), "fg", "gui" | "cterm" ))

In my case, this comes out to Red, so lualine could set guifg=Red.

Once lualine has done this, it can use the necessary background color after applying the foreground without "links".

shadmansaleh commented 2 years ago

Sorry for late response . As you figured when Hl_goup is provided in color option lualine links to that group. Here lualine relies of user providing the correct group because hl_group can contain both foreground & background colors and lualine can't know if user want's fg/bg or both from that hl_group . To avoid this you xan set color as table containing fg,bg.... keys . You can use something like extract_highlight_colors to get color from hl_group .

For example:

local get_color = require'lualine.utils.utils'.extract_highlight_colors
require("lualine").setup({
  lualine_c = {
    {"diagnostics",
    diagnostics_color = {
          error = {fg = get_color("DiagnosticError", "fg")},
      warn = {fg = get_color("DiagnosticWarn", "fg")},
      info = {fg = get_color("DiagnosticInfo", "fg")},
      hint = {fg = get_color("DiagnosticHint", "fg")},
    },          
  },
}
tristan957 commented 2 years ago

@shadmansaleh thanks for the background on the issue. Is this information available in the README? If not, I wouldn't mind sending a PR, so others don't fall into the same trap.

shadmansaleh commented 2 years ago

You can put it in FAQ if you want to.

tristan957 commented 2 years ago

I'll look into that. Never submitted to a wiki on github before.

schardev commented 2 years ago

You can put it in FAQ if you want to.

I faced the exact same issue and was looking for docs related to the same but it wasn't mentioned in docs nor in the README. After some searching I stumbled upon here.

It'll be easy for those who face this issue to have the "fix" mentioned somewhere. I tried to edit docs but the Wiki has restricted edit permissions I guess.

h0adp0re commented 2 years ago

I'll cast another vote here. I had the same problem and eventually searched for "background" in the issues. It would be nice if it'd be mentioned somewhere in the docs, though.