rcarriga / nvim-notify

A fancy, configurable, notification manager for NeoVim
MIT License
3k stars 80 forks source link

Highlight group 'Normal' has no background highlight warning #134

Closed tomaskallup closed 1 year ago

tomaskallup commented 1 year ago

Hello, first thanks for this great plugin!

After updating, I keep seeing Highlight group 'Normal' has no background highlight notification the first time a notification is displayed. I have no idea why this shows up, because my Normal highlight has background color: image I modified my config to include the background_colour, but the warning still seems like a bug to me. By quick glance it seems only the bg property is checked, but not the guibg.

I'm using material.nvim colorscheme (if that somehow relates):

  use({ -- Colorscheme
    "marko-cerovac/material.nvim",
    branch = "main",
    config = function()
      vim.g.material_style = "deep ocean"
      require("material").setup({
        contrast = {
          sidebars = true, -- Enable contrast for sidebar-like windows ( for example Nvim-Tree )
          floating_windows = true, -- Enable contrast for floating windows
          line_numbers = true, -- Enable contrast background for line numbers
          sign_column = true, -- Enable contrast background the sign column
          cursor_line = false, -- Enable darker background for the cursor line
          non_current_windows = false, -- Enable darker background for non-current windows
          popup_menu = true, -- Enable lighter background for the popup menu
        },

        contrast_filetypes = {
          "terminal", -- Darker terminal background
          "term", -- Darker terminal background
          "packer", -- Darker packer background
          "qf", -- Darker qf list background
        },

        disable = {
          term_colors = true,
          borders = false,
          colored_cursor = true,
        },

        custom_highlights = {
          DiffAdd = { bg = "#002500" },
          DiffDelete = { bg = "#250000" },
          DiffChange = { bg = "None" },
          DiffText = { bg = "None", fg = "#999900" },
          NvimTreeNormal = { fg = "#A6ACCD" },
          NeomakeVirtualtextErrorDefault = { fg = "#AF111A" },
          FloatTitle = { fg = "#a6accd", bg = "#090b10" },
        },
      })
      vim.cmd([[colorscheme material]])
    end,
  })
rcarriga commented 1 year ago

The synIDattr() function doesn't distinguish between gui/cterm values, it just returns what's currently in use (determined by termguicolors option). The logic for the warning is simply

local bg = vim.fn.synIDattr(vim.fn.synIDtrans(vim.fn.hlID(colour_or_group)), "bg#")
if bg == "" or bg == "none" then
  -- Warn
end

so you can see locally why that's being triggered. I've tried with the material config you provided and don't see the warning so there might be something else setting the highlight?

tomaskallup commented 1 year ago

Running :echo synIDattr(synIDtrans(hlID('Normal')), 'bg#') results in #0f111a. Same result with lua :lua print(vim.inspect(vim.fn.synIDattr(vim.fn.synIDtrans(vim.fn.hlID("Normal")), "bg#"))) results in "#0f111a".

rcarriga commented 1 year ago

OK since I can't reproduce you'll either need to provide a minimal init.lua that reproduces or you can try debugging yourself by adding a print for the value as the warning is emitted in config module https://github.com/rcarriga/nvim-notify/blob/master/lua/notify/config/init.lua#L71

tomaskallup commented 1 year ago

Seems like in that part of code, the background is "". I tried running :verbose hi Normal and it's same before and after the first notification.

However, I just noticed this problem only happens when the notification is triggered from nvim-tree, if I do :lua vim.notify('Test') from a regular buffer, the background is set and no warning shows up. If I run the same command inside nvim-tree (or just do any action that creates a notification eg. rename a file) the background reports as empty and warning is shown.

bushblade commented 1 year ago

I too am seeing the same issue. For me it seems to be when I have my TokyoNight theme settings to show a transparent background...

require("tokyonight").setup({
  style = "night",
  transparent = true,
  styles = {
    sidebars = "transparent",
    floats = "transparent",
  },
})

When I comment out the transparent settings I don't see the warning popup...

require("tokyonight").setup({
  style = "night",
  -- transparent = true,
  -- styles = {
  --   sidebars = "transparent",
  --   floats = "transparent",
  -- },
})
zakissimo commented 1 year ago

I too have the tokyonight theme and see the same problem with transparency.

rcarriga commented 1 year ago

@bushblade @zakissimo This is the expected behaviour, please follow the notification and set the background_colour setting. This issue is for when a transparent background is not being used.

@tomaskallup I believe I've found the issue, it's due to nvim-tree using a custom winhl setting and how the underlying implementation of it changed in latest neovim. Please try the latest commit

bushblade commented 1 year ago

Hi @rcarriga thanks for the reply. How do you set the background_colour? Do you mean for nvim-notify? I don't see it documented where that is a setting. Wouldn't setting a background colour defeat the purpose of a transparent background though? i.e. using tokyonight transparent doesn't set any background colours so it just uses your terminal background. I'm actually using this plugin via Noice not sure if that makes any difference though.

rcarriga commented 1 year ago

For nvim-notify to provide an opacity effect, it must know the background colour to fade to/from. If you don't have a background colour for the "Normal" highlight group, it will not know what colour to use so you must tell it. This should be whatever your terminal background colour is (even if it is somewhat transparent itself).

The notification tells you how to set it

  notify.setup({
    background_colour = "#121212", --Change to terminal background colour
  })
bushblade commented 1 year ago

@rcarriga Thanks, sorry yes I did notice that just after. This seems to work for me in my Noice setup...

    use({
      "folke/noice.nvim",
      event = "VimEnter",
      config = function()
        require("noice").setup()
        require("notify").setup({
          background_colour = "#1a1b26",
        })
      end,
      requires = {
        "MunifTanjim/nui.nvim",
        "rcarriga/nvim-notify",
      },
    })
tomaskallup commented 1 year ago

@rcarriga Thanks, with the latest commit it seems to work fine.