Open Saplyn opened 3 months ago
I am having the same issue. I am also using lazyvim. I wonder if it has to do with lazy loading?
I can confirm it seems the problem is when using any kind of lazy loading with lazyvim. If you set "lazy = false" it should work (but ofcourse is always loading at startup). @Saplyn can you confirm that lazy = false works for you as well?
I think it is related to #141
Ok I believe here is the problem: https://github.com/vuki656/package-info.nvim/blob/018bc10e28b00e28e239b1fff7c497304f8b1bf5/lua/package-info/config.lua#L123-L127
This runs during plugin setup and when not using lazyvim lazy loading then the color scheme will be "default" as it has not been set yet and therefore the M.__register_highlight_groups()
function will run which registers the highlight groups.
When we use any sort of lazy loading then the color scheme is NOT default and therefore this does not run and the highlight groups never get registered.
I confirmed my hunch by NOT lazy loading which normally the highlight groups then get registered properly, but I added a vim.schedule(fn()) wrapper around the plugin setup() function so that it gets run "last" after the current call stack and by that time the problem exists as the color scheme is set and therefore no longer "default". Basically vim.schedule() is a way of representing the effect of lazy loading.
config = function(_, opts)
vim.schedule(function()
require('package-info').setup(opts)
end)
end,
cc @vuki656
Thanks for you comments! The bad news is that your solution doesn't seem to work out for me, but good news is that I found a workaround:
return {
"vuki656/package-info.nvim",
dependencies = { "MunifTanjim/nui.nvim" },
ft = "json",
opts = {
colors = { -- specify both colors
up_to_date = "#0DB9D7",
outdated = "#d19a66",
},
},
config = function(_, opts)
require("package-info").setup(opts)
-- manually register them
vim.cmd([[highlight PackageInfoUpToDateVersion guifg=]] .. opts.colors.up_to_date)
vim.cmd([[highlight PackageInfoOutdatedVersion guifg=]] .. opts.colors.outdated)
end,
}
This workaround works with or without lazy load, and demonstrates that the problem should be related to the highlight group does not correct registered.
I found that:
guifg=
but not ctermfg=
, and vim.o.termguicolors
is true, which means this function should be correct:highlight PackageInfo
tab can't invoke any auto-complete, but when add those two lines back, tab auto-completes both groups. So the problem should be the hightlight group not registered.Yes you are correct. The problem is highlight groups not being registered. The root cause of the problem is lazy loading because the plugin assumes you are loading the plugin immediately at startup. As described in more detail here: https://github.com/vuki656/package-info.nvim/issues/155#issuecomment-2270512637
I also added something similar where I registered the highlights in my config function which is a temporary fix for now. I also re-registered the autocmds the plugin adds to make sure they are done properly when lazy loading.
Hey @GitMurf @Saplyn. Yeah I didn't take into account lazy loading when making the plugin.
Would any of you be willing to open a PR to fix this?
Is it better to allow the user to control the style/color by setting the highlight groups directly themselves (or inside their theme plugins), instead of using a configuration option?
When the plugin is loaded, it can check whether the highlight groups were already defined. If none is found, the default values will be set.
Is it better to allow the user to control the style/color by setting the highlight groups directly themselves (or inside their theme plugins), instead of using a configuration option?
When the plugin is loaded, it can check whether the highlight groups were already defined. If none is found, the default values will be set.
Yeah that makes more sense. Feel free to open a PR
Issues
Plugin Version
Neovim Version
Neovim Version
Branch
master
Actual behavior
Both
up_to_date
andoutdated
has no color, no matter the config.Expected behavior
The color should appear, at least the default ones.
Steps to reproduce
package.json
Package info config
I'm using
lazy.nvim
for package manager andLazyVim
distro.Other information
echo $TERM
isxterm-256color
Help
No, sorry.
Implementation help
Sorry I'm new to this editor, however I would try my best to help provide any information needed.