0

I am having difficulty adding a source to nvim-cmp: I am failing to add cmp-luasnip-choice to nvim-cmp. I have listed my minimal configuration below.

A test Lua snippet with a ChoiceNode basically works, but the completion does not.

The command CmpStatus results in:

# ready source names
- luasnip
# unavailable source names
- luasnip_choice

I have tried various options (neovim stable/nightly with minimal configuration: lazy, colorscheme, cmp, LuaSnip, cmp-luasnip-choice, cmp_luasnip) without success.

The installation of cmp-buffer or cmp-calc worked without any problems.

Registering the source manually

lua require("cmp").register_source("luasnip_choice", require("cmp_luasnip_choice").source.new())

resulted in

# unavailable source names
- luasnip_choice
- luasnip_choice

Any ideas?

lazy.nvim configuration:

return {
    "hrsh7th/nvim-cmp",
    dependencies = {
        { "L3MON4D3/LuaSnip",
            opts = function()
                require("luasnip.loaders.from_lua").lazy_load({ paths = { "./snippets" } })
            end
        },
        "saadparwaiz1/cmp_luasnip",
        "L3MON4D3/cmp-luasnip-choice",
    },
    version = false,
    event = { "InsertEnter" },
    config = function()
        local cmp = require("cmp")
        local luasnip = require("luasnip")

        vim.keymap.set({"i", "s"}, "<C-e>", function()
            if luasnip.choice_active() then
                luasnip.change_choice(1)
            end
        end, {silent = true})

        cmp.setup({
            snippet = {
                expand = function(args)
                    luasnip.lsp_expand(args.body)
                end,
            },
            sources = cmp.config.sources({
                { name = "luasnip" },
                { name = "luasnip_choice" },
            }),
            mapping = cmp.mapping.preset.insert({
                ["<CR>"] = cmp.mapping.confirm {
                    behavior = cmp.ConfirmBehavior.Insert,
                    select = true,
                },
            })
        })
    end
}

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.