vuki656 / package-info.nvim

✍️ All the npm/yarn/pnpm commands I don't want to type
GNU General Public License v3.0
480 stars 27 forks source link

[BUG] No Colors for both `up_to_date` and `outdated` #155

Open Saplyn opened 2 months ago

Saplyn commented 2 months ago

Issues

Plugin Version

Neovim Version

Neovim Version

NVIM v0.10.0
Build type: RelWithDebInfo
LuaJIT 2.1.1713484068
Compilation: /usr/bin/cc -O2 -g -Og -g -flto -fno-fat-lto-objects -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wshadow -Wconversion -Wvla -Wdouble-promotion -Wmissing-noreturn -Wmissing-format-attribute -Wmissing-prototypes -fsigned-char -fstack-protector-strong -Wno-conversion -fno-common -Wno-unused-result -Wimplicit-fallthrough -fdiagnostics-color=always  -DUNIT_TESTING -DHAVE_UNIBILIUM -D_GNU_SOURCE -DINCLUDE_GENERATED_DECLARATIONS -I/build/nvim/parts/nvim/build/.deps/usr/include/luajit-2.1 -I/build/nvim/parts/nvim/build/.deps/usr/include -I/build/nvim/parts/nvim/build/build/src/nvim/auto -I/build/nvim/parts/nvim/build/build/include -I/build/nvim/parts/nvim/build/build/cmake.config -I/build/nvim/parts/nvim/build/src -I/usr/include 

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/usr/share/nvim"

Run :checkhealth for more info

Branch

master

Actual behavior

Both up_to_date and outdated has no color, no matter the config.

vue is "outdated"

image

Expected behavior

The color should appear, at least the default ones.

Steps to reproduce

Package info config

I'm using lazy.nvim for package manager and LazyVim distro.

-- lua/plugins/package-info.lua
return {
  "vuki656/package-info.nvim",
  dependencies = { "MunifTanjim/nui.nvim" },
  ft = "json",
  opts = {
    colors = {
      up_to_date = "#0DB9D7",
    },
    package_manager = "npm",
  },
}

Other information

Help

No, sorry.

Implementation help

Sorry I'm new to this editor, however I would try my best to help provide any information needed.

GitMurf commented 2 months ago

I am having the same issue. I am also using lazyvim. I wonder if it has to do with lazy loading?

GitMurf commented 2 months ago

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?

GitMurf commented 2 months ago

I think it is related to #141

GitMurf commented 2 months ago

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

Saplyn commented 2 months ago

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.

Saplyn commented 2 months ago

I found that:

GitMurf commented 2 months ago

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.

vuki656 commented 1 month ago

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?

folliehiyuki commented 1 month ago

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.

vuki656 commented 1 month ago

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