brenoprata10 / nvim-highlight-colors

Highlight colors for neovim
720 stars 33 forks source link

Clarify integration with `nvim-cmp` format() #109

Closed savchenko closed 4 months ago

savchenko commented 4 months ago

An example in the readme assumes that format isn't being already used. However, it is often declared as a function, e.g.

format = function(_, item)
  -- many customisations...
  return item
end

How do I correctly hook nvim-highlight-colours there?

nickp-real commented 4 months ago

https://github.com/brenoprata10/nvim-highlight-colors/blob/f4b659383a940b4f3121bca550c3461dec6d1a16/lua/nvim-highlight-colors/init.lua#L175

In the code, I assume you can use it by

format = function(entry, item)
  -- ...custom config
  return require("nvim-highlight-colors").format(entry, item)
end

Or assuming you have to modify the icon or other things since the function returns item table, idk haven't tried it yet.

format = function(entry, item)
  item = require("nvim-highlight-colors").format(entry, item)
  -- item.abbr = ...
  return item
end

edit: after I tweak my config I ended up with this

formatting = {
  fields = { "kind", "abbr", "menu" },
  format = function(entry, item)
    item = require("nvim-highlight-colors").format(entry, item)
    -- the item.abbr returns the user's virtual object eg. the square when it's Color entry
    if item.abbr == "" then
      -- I have kind_icons table looks like kind_icons = { Text = "Tt (this is icon)", ...more icons }
      item.kind = string.format("%s", kind_icons[item.menu])
    else
      item.kind = item.abbr
    end
    item.abbr = item.word
    item.kind_hl_group = item.abbr_hl_group or nil
    item.abbr_hl_group = nil
    return item
end,
}

The problem I found is the highlight group (nvim-highlight-000000, ...) doesn't link the bg highlight to the current theme highlight (maybe using the Normal group) and another one is when I have a custom tailwind variable, it doesn't apply eg text-primary

This is the result, some work when you first see it (type the text and it shows) then when scrolling down and scrolling back, the background color turns to the highlight color group instead image

before select item image

after select item image

my config with a custom icon image

brenoprata10 commented 4 months ago

An example in the readme assumes that format isn't being already used. However, it is often declared as a function, e.g.

format = function(_, item)
  -- many customisations...
  return item
end

How do I correctly hook nvim-highlight-colours there?

Hey o/

I've updated the readme. Please check it out :)