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

Highlight issue with 3 Hex chars #127

Open
rodhash opened this issue Nov 9, 2024 · 2 comments
Open

Highlight issue with 3 Hex chars #127

rodhash opened this issue Nov 9, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@rodhash
Copy link

rodhash commented Nov 9, 2024

Hello,

It seems I have a similar issue as in #44 but in the CMP integrated menu.

I'm using the CMP integration taken from README.

It's working for the most part but even with --white defined it shows no HL color in the CMP menu and in the "var" variable:
image

Now I noticed that, if I use a different CMP integration like the lspkind I get a different result:
image

It seems this formatting function is not working for --white as it's returning the color glyph directly from lspkind:

        formatting = {
                format = function(entry, item)
                        local color_item = require("nvim-highlight-colors").format(entry, { kind = item.kind })
                        item = require("lspkind").cmp_format({
                                -- any lspkind format settings here
                        })(entry, item)
                        if color_item.abbr_hl_group then
                                item.kind_hl_group = color_item.abbr_hl_group
                                item.kind = color_item.abbr
                        end
                        return item
                end
        },

Using the below minimal config I see the same issue:

image

Minimal:

-- DO NOT change the paths and don't remove the colorscheme
local root = vim.fn.fnamemodify("./.repro", ":p")

-- set stdpaths to use .repro
for _, name in ipairs({ "config", "data", "state", "cache" }) do
  vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end

-- bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
  vim.fn.system({ "git", "clone", "--filter=blob:none", "https://github.com/folke/lazy.nvim.git", lazypath, })
end
vim.opt.runtimepath:prepend(lazypath)

-- install plugins
local plugins = {
  "folke/tokyonight.nvim",
  "folke/noice.nvim",
  -- add any other plugins here
  "nvim-neo-tree/neo-tree.nvim",
  "nvim-lua/plenary.nvim",
  "rodhash/nvim-web-devicons",
  "MunifTanjim/nui.nvim",
  "rcarriga/nvim-notify",
  "nvim-lua/plenary.nvim",
  "nvim-treesitter/nvim-treesitter",
  "ray-x/lsp_signature.nvim",

  -- LSP
  "neovim/nvim-lspconfig",
  "williamboman/mason.nvim",
  "williamboman/mason-lspconfig.nvim",

  -- Completion
  "hrsh7th/nvim-cmp",
  "hrsh7th/cmp-nvim-lsp",
  "hrsh7th/nvim-cmp",
  "hrsh7th/cmp-buffer",

  -- vsnip
  "hrsh7th/cmp-vsnip",
  "hrsh7th/vim-vsnip",

  -- others
  'brenoprata10/nvim-highlight-colors',
  'onsails/lspkind.nvim',
}
require("lazy").setup(plugins, {
  root = root .. "/plugins",
})

vim.cmd.colorscheme("tokyonight")
-- add anything else here

local nvim_set_hl = vim.api.nvim_set_hl

require("noice").setup({
  lsp = {
    signature = {
      enabled = false,
    },
  }}
)

require("mason").setup()
require("mason-lspconfig").setup {
    ensure_installed = { "cssls", "tailwindcss" },
}
require'lsp_signature'.setup() -- no need to specify bufnr if you don't use toggle_key

-- CMP

  -- Set up nvim-cmp.
  local cmp = require'cmp'

    cmp.setup({
      formatting = {
              format = function(entry, item)
                      local color_item = require("nvim-highlight-colors").format(entry, { kind = item.kind })
                      item = require("lspkind").cmp_format({
                              -- any lspkind format settings here
                      })(entry, item)
                      if color_item.abbr_hl_group then
                              item.kind_hl_group = color_item.abbr_hl_group
                              item.kind = color_item.abbr
                      end
                      return item
              end
      },

      snippet = {
        -- REQUIRED - you must specify a snippet engine
        expand = function(args)
          vim.fn["vsnip#anonymous"](args.body) -- For `vsnip` users.
          -- require('luasnip').lsp_expand(args.body) -- For `luasnip` users.
          -- require('snippy').expand_snippet(args.body) -- For `snippy` users.
          -- vim.fn["UltiSnips#Anon"](args.body) -- For `ultisnips` users.
        end,
      },
      window = {
        completion = cmp.config.window.bordered(),
        documentation = cmp.config.window.bordered(),
      },
      mapping = cmp.mapping.preset.insert({
        ['<C-b>'] = cmp.mapping.scroll_docs(-4),
        ['<C-f>'] = cmp.mapping.scroll_docs(4),
        ['<C-Space>'] = cmp.mapping.complete(),
        ['<C-e>'] = cmp.mapping.abort(),
        ['<CR>'] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
        ['<C-h>'] = function() cmp.complete() end,
      }),
      sources = cmp.config.sources({
        { name = 'nvim_lsp' },
        { name = 'vsnip' },
        { name = "buffer" },
        -- { name = 'luasnip' }, -- For luasnip users.
        -- { name = 'ultisnips' }, -- For ultisnips users.
        -- { name = 'snippy' }, -- For snippy users.
      })
    })


  -- Set up lspconfig.
  local capabilities = require('cmp_nvim_lsp').default_capabilities()
  capabilities.textDocument.completion.completionItem.snippetSupport = true
  capabilities.offsetEncoding = { "utf-16" }

  -- require('lspconfig').terraformls.setup({
  --   filetypes = { "terraform", "tf", "terraform-vars" },
  --   capabilities = capabilities
  -- })
  --
  require('lspconfig')['cssls'].setup {
    capabilities = capabilities
  }

  require('nvim-highlight-colors').setup({
    exclude_buftypes = { "nofile" },
    exclude_filetypes = { "nofile" },
  })

ps: I had to exclude "nofile" because another issue happened but I don't think we need to discuss that here.

Any idea why some colors (like --white) are having this issue?

Thanks.

@rodhash
Copy link
Author

rodhash commented Nov 9, 2024

Oh that's interesting, it worked now.

It seems the bug happens when colors are set with 3 Hex chars:

/* Issues in CMP menu and vars lines */
  --white: #fff;

/* No issues */
  --white: #ffffff;

@rodhash rodhash changed the title Highlight issue with --white Highlight issue with 3 RGB cars Nov 9, 2024
@rodhash rodhash changed the title Highlight issue with 3 RGB cars Highlight issue with 3 RGB chars Nov 9, 2024
@rodhash rodhash changed the title Highlight issue with 3 RGB chars Highlight issue with 3 Hex chars Nov 9, 2024
@minusf
Copy link

minusf commented Nov 12, 2024

I can confirm this issue. 3 letter colors are highlighted, however when used in variables, it's not highlighted.

Screenshot 2024-11-12 at 15 19 07

@brenoprata10 brenoprata10 added the bug Something isn't working label Nov 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants