nvf icon indicating copy to clipboard operation
nvf copied to clipboard

Colorizer not attaching to buffers

Open Jappie3 opened this issue 1 year ago • 14 comments

⚠️ Please verify that this bug has NOT been reported before.

  • [X] I checked all existing issues and didn't find a similar issue

Description

Colorizer does not attach when opening a buffer, when running :ColorizerAttachToBuffer it correctly highlights colors

👟 Reproduction steps

minimal reproducible example:

{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
    nvf.url = "github:notashelf/nvf";
  };

  outputs = {
    self,
    nixpkgs,
    ...
  } @ inputs: {
    packages."x86_64-linux" = {
      default =
        (inputs.nvf.lib.neovimConfiguration {
          modules = [
            {
              config.vim.theme.enable = true;
              config.vim.ui.colorizer.enable = true;
            }
          ];
          inherit (nixpkgs.legacyPackages."x86_64-linux") pkgs;
        })
        .neovim;
    };
  };
}
nix run

type 'green' or 'red' -> no color highlighting run :ColorizerAttachToBuffer -> color highlighting

👀 Expected behavior

Colorizer should work without explicitly attaching it to the buffer

😓 Actual Behavior

It did not attach to the buffer

💻 Metadata

  • system: "x86_64-linux" - host os: Linux 6.6.58, NixOS, 24.11 (Vicuna), 24.11.20241029.807e915 - multi-user?: yes - sandbox: yes - version: nix-env (Lix, like Nix) 2.91.0 System type: x86_64-linux Additional system types: aarch64-linux, i686-linux Features: gc, signed-caches System configuration file: /etc/nix/nix.conf User configuration files: /home/jasper/.config/nix/nix.conf:/etc/xdg/nix/nix.conf:/home/jasper/.nix-profile/etc/xdg/nix/nix.conf:/nix/profile/etc/xdg/nix/nix.conf:/home/jasper/.local/state/nix/profile/etc/xdg/nix/nix.conf:/etc/profiles/per-user/jasper/etc/xdg/nix/nix.conf:/nix/var/nix/profiles/default/etc/xdg/nix/nix.conf:/run/current-system/sw/etc/xdg/nix/nix.conf Store directory: /nix/store State directory: /nix/var/nix Data directory: /nix/store/xjcvjdif1fv2zdsywa2g2r2rahymqbdm-lix-2.91.0/share - nixpkgs: /nix/store/m68ikm8045fj7ys7qvgr608z9l70hh1k-source

📝 Relevant log output

no clue how to get nvim logs tbh

Jappie3 avatar Nov 02 '24 12:11 Jappie3

nvf does not enable the names feature for colorizer by default. You will need to enable it manually in colorizer.setupOpts. See: https://github.com/NotAShelf/nvf/blob/main/modules/plugins/ui/colorizer/colorizer.nix

NotAShelf avatar Nov 02 '24 12:11 NotAShelf

even adding colorizer.setupOpts.names = true;:

{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
    nvf.url = "github:notashelf/nvf";
  };

  outputs = {
    self,
    nixpkgs,
    ...
  } @ inputs: {
    packages."x86_64-linux" = {
      default =
        (inputs.nvf.lib.neovimConfiguration {
          modules = [
            {
              config.vim.theme.enable = true;
              config.vim.ui.colorizer = {
                enable = true;
                setupOpts.names = true;
              };
            }
          ];
          inherit (nixpkgs.legacyPackages."x86_64-linux") pkgs;
        })
        .neovim;
    };
  };
}

it still does not attach to the buffer automatically, I manually have to run :ColorizerAttachToBuffer

Jappie3 avatar Nov 02 '24 12:11 Jappie3

That is unusual, I'll take a look shortly.

NotAShelf avatar Nov 02 '24 13:11 NotAShelf

also color highlighting by name (e.g. 'blue', 'green') worked with the first flake example I posted... so either my system config (where it is enabled) is leaking (which could also mean that there's some incompatibility) or something weird is happening...

Jappie3 avatar Nov 02 '24 13:11 Jappie3

Sorry, I forgot to respond to this earlier but colorizer has been updated not so long ago. Has this been resolved? Or does it still occur after the update?

NotAShelf avatar Feb 11 '25 17:02 NotAShelf

No worries, not like this is a high priority issue

Using the minimal reproducible example from the initial report - but with nvf pinned like this (master threw an error when running) nvf.url = "github:notashelf/nvf/a78026438cc8e280a696bcadb60f5c8f93b96a12"; (commit from 2 days ago) - colorizer still does not attach to buffers by default. After manually running :ColorizerAttachToBuffer it works.

Just to make sure, config.vim.ui.colorizer.enable = true; should be enough to enable it right?

Jappie3 avatar Feb 11 '25 18:02 Jappie3

That should be it, yes. I've got colorizer working in my setup without any additional setups, maybe a missing soft-dependency?

NotAShelf avatar Feb 11 '25 18:02 NotAShelf

can you try nix runing this flake.nix?

{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
    nvf.url = "github:notashelf/nvf/a78026438cc8e280a696bcadb60f5c8f93b96a12";
  };

  outputs = {
    self,
    nixpkgs,
    ...
  } @ inputs: {
    packages."x86_64-linux" = {
      default =
        (inputs.nvf.lib.neovimConfiguration {
          modules = [
            {
              config.vim.theme.enable = true;
              config.vim.ui.colorizer.enable = true;
            }
          ];
          inherit (nixpkgs.legacyPackages."x86_64-linux") pkgs;
        })
        .neovim;
    };
  };
}

Jappie3 avatar Feb 11 '25 19:02 Jappie3

I am having the same issue. Got nearly my whole config switched over to nvf and got stuck on this plugin. When I go to a HTML file it does same thing as OP, have to run :ColorizerAttachToBuffer to make it work. But I cant get tailwindcss to work even running :ColorizerAttachToBuffer. I'm pretty sure I have tailwind enabled correctly.

ui.colorizer = {
  enable = true;
  setupOpts = {
    mode = "background";
    tailwind = true;
    names = true;
    RGB = true;
    RRGGBB = true;
    };
};

KodNova avatar Feb 18 '25 04:02 KodNova

Had this issues and was able to resolve by including filetypes in the setup I think its related to this comment

          ui = {
            colorizer = {
              enable = true;
              setupOpts = {
                filetypes = { 
                  "*" = {
                    RGB = true;
                    RRGGBB = true;
                    always_update = true;
                    css = true;
                    mode = "background";
                  };
                };
              };
            };
          };

jsjjohnston avatar Feb 23 '25 22:02 jsjjohnston

can confirm: the below flake works (highlights colors) when opening a file with an 'regular' or common file extension - e.g. .html works, .aoeuaoeu doesn't.

at this point I'm not sure if we should keep this issue open here or if this is an intended limitation of colorizer... as far as I'm concerned this is a good solution and we can close it

flake
{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
    nvf.url = "github:notashelf/nvf";
  };

  outputs =
    {
      self,
      nixpkgs,
      ...
    }@inputs:
    {
      packages."x86_64-linux" = {
        default =
          (inputs.nvf.lib.neovimConfiguration {
            modules = [
              {
                config = {
                  vim = {
                    theme.enable = true;
                    ui.colorizer.enable = true;
                    ui.colorizer.setupOpts = {
                      filetypes = {
                        "*" = {
                          RGB = true;
                          RRGGBB = true;
                          always_update = true;
                          css = true;
                          mode = "background";
                        };
                      };
                    };
                  };
                };
              }
            ];
            inherit (nixpkgs.legacyPackages."x86_64-linux") pkgs;
          }).neovim;
      };
    };
}

Jappie3 avatar Feb 24 '25 08:02 Jappie3

I think it might be a good idea to provide some default value for colorizer filetypes, so that attaching to buffers works ootb.

NotAShelf avatar Feb 24 '25 08:02 NotAShelf

Would it be possible to make an option similar to vim.languages.enableLSP that would add colorizer filetypes for enabled languages?

On a kind of unrelated note. Any idea why my colorizer still does not work for my tailwind colours?

ui.colorizer = {
  enable = true;
  setupOpts = {
    filetypes = {
      "*" = {
        mode = "background";
        tailwind = true;
        names = true;
        RGB = true;
        RRGGBB = true;
       };
     };
   };
};

KodNova avatar Feb 25 '25 17:02 KodNova

I've been trying to reduce our reliance on top-level options such as enableLSP. I also don't think it is necessary to support all languages with colorizer.

Instead I'll default to CSS and SCSS, which I think is a good default; additional filetypes can be added on user's own discretion.

NotAShelf avatar Feb 27 '25 21:02 NotAShelf