roobert / tailwindcss-colorizer-cmp.nvim

:rainbow: A Neovim plugin to add vscode-style TailwindCSS completion to nvim-cmp
323 stars 3 forks source link

How to combine with a previous config for format? #15

Open hrqmonteiro opened 8 months ago

hrqmonteiro commented 8 months ago
formatting = {
    fields = { "kind", "abbr" },
    kind_icons = icons.kind,
    format = function(entry, vim_item)
      local max_width = my_formatting.max_width
      if max_width ~= 0 and #vim_item.abbr > max_width then
        vim_item.abbr = string.sub(vim_item.abbr, 1, max_width - 1) .. icons.ui.Ellipsis
      end
      if use_icons then
        vim_item.kind = my_formatting.kind_icons[vim_item.kind]

        if entry.source.name == "copilot" then
          vim_item.kind = icons.git.Octoface
          vim_item.kind_hl_group = "CmpItemKindCopilot"
        end

        if entry.source.name == "cmp_tabnine" then
          vim_item.kind = icons.misc.Robot
          vim_item.kind_hl_group = "CmpItemKindTabnine"
        end

        if entry.source.name == "crates" then
          vim_item.kind = icons.misc.Package
          vim_item.kind_hl_group = "CmpItemKindCrate"
        end

        if entry.source.name == "lab.quick_data" then
          vim_item.kind = icons.misc.CircuitBoard
          vim_item.kind_hl_group = "CmpItemKindConstant"
        end

        if entry.source.name == "emoji" then
          vim_item.kind = icons.misc.Smiley
          vim_item.kind_hl_group = "CmpItemKindEmoji"
        end
      end
      vim_item.menu = my_formatting.source_names[entry.source.name]
      vim_item.dup = my_formatting.duplicates[entry.source.name]
          or my_formatting.duplicates_default
      return vim_item
    end,
  }

I have this in my config. How do i insert your plugin into it so my config is not wasted?

dddddjent commented 8 months ago

Currently I do something like this. I don't know if this is reasonable

format = function(entry, vim_item)
    local tw_item = require("tailwindcss-colorizer-cmp").formatter(entry, vim_item)
    if tw_item.kind == "XX" then
         return tw_item
    end
     -- do your own things
end