Exafunction / codeium.nvim

A native neovim extension for Codeium
MIT License
647 stars 50 forks source link

Failed when using as a cmp sources #22

Closed CharlesChiuGit closed 1 year ago

CharlesChiuGit commented 1 year ago

Below error happened when I enable codeium as a cmp source. I think it might related to the callbacks from codeium server not fitting cmp's format. This makes it unusable as a cmp source.

My codeium setup: require("codeium").setup({}) OS: Ubuntu 22.04 with all the required tools installed.

圖片

EricDriussi commented 1 year ago

Hi there! I do have it working with cmp.

Your error message seems a bit strange, what are you trying to concatenate on line 86 exactly? Could it be a lazy loading issue? I'm pretty sure this plugin needs to be available by the time cmp is loaded.

CharlesChiuGit commented 1 year ago

Aha! That's probably why, thanks for the hint! In my cmp.lua line 86, it's formatting cmp sources like so:

圖片

        formatting = {
            fields = { "kind", "abbr", "menu" },
            format = function(entry, vim_item)
                local kind = lspkind.cmp_format({
                    mode = "symbol_text",
                    maxwidth = 50,
                    symbol_map = vim.tbl_deep_extend("force", icons.kind, icons.type, icons.cmp),
                })(entry, vim_item)
                local strings = vim.split(kind.kind, "%s", { trimempty = true })
                kind.kind = " " .. strings[1] .. " "
                kind.menu = "    (" .. strings[2] .. ")"
                return kind
            end,
        },

Maybe I just need to add a codeium icon for lspkind to display.

EricDriussi commented 1 year ago

That sounds like it should fix it :tada:

For reference, I use a much more boring approach where my format function looks like:

format = function(entry, item)
        -- Icons
        item.kind = string.format("%s", require("plugins.completion.icons")[item.kind])
        -- Sources Labels
        item.menu = ({
            nvim_lsp = "[L]",
            codeium = "IA",
            buffer = "[B]",
            path = "[P]",
            luasnip = "[S]",
            emoji = "[E]",
        })[entry.source.name]
        return item
end,

And the icons are just a dumb table (Suggestion is the one for Codeium):

return {
    Text = "₸",
    Method = "m",
    Function = "⨍",
    Constructor = "🛠",
    Field = "",
    Variable = "",
    Class = "🖧",
    Interface = "",
    Module = "",
    Property = "",
    Unit = "",
    Value = "",
    Enum = "",
    Keyword = "⚿",
    Snippet = "",
    Color = "",
    File = "🖹",
    Reference = "",
    Folder = "",
    EnumMember = "",
    Constant = "ℇ",
    Struct = "",
    Event = "",
    Operator = "",
    TypeParameter = "ナ",
    Suggestion = "✨",
}

I would suggest you mess around with the format function to figure out why strings[2] is coming out nil. Can't really be any more specific since I don't use lspkind so I'm missing context there :stuck_out_tongue:

Good luck!

CharlesChiuGit commented 1 year ago

Tks! Will try after I got home.

CharlesChiuGit commented 1 year ago

fixed with PR #25