Open RafaelZasas opened 6 months ago
I realize now that this doesnt actually have any opinion on what the completion menu contains, just how it is styled.
Nevertheless, I got it working as follows:
local cmp = require("cmp")
local lsp_zero = require("lsp-zero")
local cmp_action = lsp_zero.cmp_action()
local cmp_format = lsp_zero.cmp_format()
local tailwindcss_colors = require("tailwindcss-colorizer-cmp")
local cmp_formatter = function(entry, vim_item)
-- vim_item as processed by tailwindcss-colorizer-cmp
vim_item = tailwindcss_colors.formatter(entry, vim_item)
-- change menu (name of source)
vim_item.menu = ({
nvim_lsp = "[LSP]",
buffer = "[Buffer]",
path = "[Path]",
emoji = "[Emoji]",
luasnip = "[LuaSnip]",
vsnip = "[VSCode Snippet]",
calc = "[Calc]",
spell = "[Spell]",
})[entry.source.name]
return vim_item
end
cmp.setup({
-- same preselect and completion as before
-- same sources as before
-- Same mappings as before
formatting = {
-- changing the order of fields so the icon is the first
fields = { "menu", "abbr", "kind" },
format = cmp_formatter,
},
-- same window and snippet as before
})
Thanks man, I was looking for something similar for my lsp-zero config, I didn't want to deep so much and thanks god I found you!!!
I am following This Guide to setup my LSP, Auto complete and LSP installations.
In the guide, it is stated that the
name
for the sources property oncmp.setup
is not the same as the plugin name.What is the source name for this plugin?
Am I able to use this plugin alongside other CMP sources?
This is my config for cmp:
I was able to get the plugin to work, and show tailwindcss colors by replacing
cmp_format
withformat = require("tailwindcss-colorizer-cmp").formatter }
but then I lose autocompletion from my LSP, which is not ideal.I see that other CMP sources such as buffer follow a similar pattern of including a
after/plugin/insert_source_name.lua
. With contents of (something like):I tried including
cmp.register_source('tailwindcss-colors', require('tailwindcss-colorizer-cmp').formatter)
and then adding{name = 'tailwindcss-colors'}
to the sources, but I got shouted at by cmp when trying to trigger autocomplete.I'm a bit stuck.