mvllow / modes.nvim

Prismatic line decorations for the adventurous vim user

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Removed fallbacks with transparent background throws error

PriceHiller opened this issue · comments

(See bottom for a quick fix to skip all the troubleshooting, not sure if it's the best fix, but it does work)

Troubleshooting

The commit, 4e69c2a and later commits, have lead to some issues for my configuration. When pointing packer directly at that commit and later commits I get the following error:

Error executing vim.schedule lua callback: ...im/site/pack/packer/start/modes.nvim/lua/modes/utils.lua:7: Expected lua string
stack traceback:
        [C]: in function 'nvim_get_color_by_name'
        ...im/site/pack/packer/start/modes.nvim/lua/modes/utils.lua:7: in function 'get_color'
        ...im/site/pack/packer/start/modes.nvim/lua/modes/utils.lua:29: in function 'blend'
        ...are/nvim/site/pack/packer/start/modes.nvim/lua/modes.lua:89: in function 'define'
        ...are/nvim/site/pack/packer/start/modes.nvim/lua/modes.lua:163: in function ''
        vim/_editor.lua: in function ''
        vim/_editor.lua: in function <vim/_editor.lua:0>

This occurs both on the latest stable neovim 0.7 & on the latest version of neovim 0.8 I have traced it down to the removal of a fallback for the normal group, adding back the fallback:

default_colors = {
    cursor_line = utils.get_bg('CursorLine'),
    cursor_line_nr = utils.get_bg('CursorLineNr'),
    mode_msg = utils.get_fg('ModeMsg'),
    normal = utils.get_bg('Normal', 'Normal'), -- <<<< here
    visual = utils.get_bg('Visual'),
}

clears this error for me.

This error popped up for me due to tokyonight.nvim's transparency options. When I comment out vim.g.tokyonight_transparent* the error referenced above goes away.

I suspect this is because the group gets set to none by the transparency options.

Taking a look at the blended colors groups, I noticed the bg color passed to blend is the default_colors.normal:

blended_colors = {
    copy = utils.blend(
        colors.copy,
        default_colors.normal,
        config.line_opacity.copy
    ),
    delete = utils.blend(
        colors.delete,
        default_colors.normal,
    -- snip

and the default_colors.normal is defined as

default_colors = {
    -- snip
    normal = utils.get_bg('Normal'),
    -- snip
}

and as best I can tell utils.get_bg is the core of the problem here.

M.get_bg = function(name, fallback)
	vim.notify(vim.inspect(name))
	local id = vim.api.nvim_get_hl_id_by_name(name)
	vim.notify(vim.inspect(id))
	if not id then
		return fallback
	end

	local background = vim.fn.synIDattr(id, 'bg')
	vim.notify(vim.inspect(background))
	if not background or background == '' then
		return fallback
	end

	return background
end

I've popped in a few notify statements, and here's the output for the normal group:

"Normal" <- The name passed in, seems fine
64 <- We get a valid ID back
"none" <- synIDattr fails to get the background :/

The issue is with vim.fn.synIDattr, it's giving back a none value and since no fallback is defined this entire function throws back a none value leading to the error up top.

Recreating the Error

To recreate the error you can pass in the following commands to neovim's command line (assuming you have a proper installation of modes):

  1. highlight Normal guibg=#00000
  2. lua require("modes").setup()

At this point above, no errors should be shown as the Normal bg group is not none.

  1. highlight Normal guibg=NONE
  2. lua require("modes").setup()

Now the error should appear.

Potential Fix

The most expedient way to resolve this is to add back the fallback for the normal group:

default_colors = {
    -- snip
    normal = utils.get_bg('Normal', 'Normal'),
    -- snip
}