Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
3 tasks done
Saplyn opened this issue Aug 1, 2024 · 10 comments
Open
3 tasks done

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

Saplyn opened this issue Aug 1, 2024 · 10 comments
Labels
🐛 Bug Something isn't working 🤝 Contributions Welcome Not on the roadmap but can be picked up by someone

Comments

@Saplyn
Copy link

Saplyn commented Aug 1, 2024

Issues

  • I have checked existing issues and there are no issues with the same problem.

Plugin Version

  • I am using the latest version of the plugin

Neovim Version

  • I am using the 0.6 neovim version or later

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

  • Install the plugin
  • Restart NeoVim
  • Open a package.json
  • Wait and observe the bug (no color)

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

  • I'm using gnome-terminal
  • The output of echo $TERM is xterm-256color
  • I'm using Ubuntu 22.04, with zsh & oh-my-zsh

Help

No, sorry.

Implementation help

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

@Saplyn Saplyn added the 🐛 Bug Something isn't working label Aug 1, 2024
@GitMurf
Copy link

GitMurf commented Aug 6, 2024

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

@GitMurf
Copy link

GitMurf commented Aug 6, 2024

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
Copy link

GitMurf commented Aug 6, 2024

I think it is related to #141

@GitMurf
Copy link

GitMurf commented Aug 6, 2024

Ok I believe here is the problem:

if colorscheme == "default" then
M.__register_highlight_groups()
return
end

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
Copy link
Author

Saplyn commented Aug 6, 2024

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
Copy link
Author

Saplyn commented Aug 6, 2024

I found that:

  • My terminal works with guifg= but not ctermfg=, and vim.o.termguicolors is true, which means this function should be correct
  • When I comment out those two "manually register" lines, :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.

@GitMurf
Copy link

GitMurf commented Aug 6, 2024

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: #155 (comment)

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
Copy link
Owner

vuki656 commented Aug 8, 2024

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?

@vuki656 vuki656 added the 🤝 Contributions Welcome Not on the roadmap but can be picked up by someone label Aug 8, 2024
@folliehiyuki
Copy link

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
Copy link
Owner

vuki656 commented Aug 24, 2024

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

rahulkrishnakumar added a commit to rahulkrishnakumar/nvim that referenced this issue Sep 20, 2024
- fixed package-info coler issue - Closes:#7
- ref discussiong: [[BUG] No Colors for both up_to_date and
outdated](vuki656/package-info.nvim#155)
rahulkrishnakumar added a commit to rahulkrishnakumar/nvim that referenced this issue Sep 20, 2024
- fixed package-info coler issue - closes #7
- ref discussiong: [[BUG] No Colors for both up_to_date and
outdated](vuki656/package-info.nvim#155
rahulkrishnakumar added a commit to rahulkrishnakumar/nvim that referenced this issue Sep 20, 2024
- fixed package-info coler issue - closes #7
- ref discussiong: [[BUG] No Colors for both up_to_date and
outdated](vuki656/package-info.nvim#155)
rahulkrishnakumar added a commit to rahulkrishnakumar/nvim that referenced this issue Sep 20, 2024
- fixed package-info coler issue - closes #7
- ref discussiong: [ No Colors for both up_to_date and
outdated](vuki656/package-info.nvim#155)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 Bug Something isn't working 🤝 Contributions Welcome Not on the roadmap but can be picked up by someone
Projects
None yet
Development

No branches or pull requests

4 participants