Nvim-cmp issues when cycling through snippets

Hie Everyone,
I’m encountering an issue everytime I cycle through a snippet option in my menu as shown in my image

And the following is my config for nvim-cmp:

local cmp_status_ok, cmp = pcall(require, "cmp")
if not cmp_status_ok then
        return
end

local snip_status_ok, luasnip = pcall(require, "luasnip")
if not snip_status_ok then
        return
end

local ok, lspkind = pcall(require, "lspkind")
if not ok then
        return
end

local snippets = require("luasnip.loaders.from_vscode")
snippets.load({ include = { vim.bo.filetype } })
snippets.lazy_load()
luasnip.config.set_config({
        history = true,
        region_check_events = "InsertEnter",
        updateevents = "TextChanged,TextChangedI",
        -- minimal increase in priority
        enable_autosnippets = true,
})

local lsp_signature = require("lsp_signature")
lsp_signature.setup({
        bind = true,
        handler_opts = {
                border = "rounded",
        },
})
local has_words_before = function()
        unpack = unpack or table.unpack
        local line, col = unpack(vim.api.nvim_win_get_cursor(0))
        return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil
end

--if vim.g.config.plugins.copilot.enable then
--      local icons = require("user.utils.icons")
--    table.insert(format.symbol_map, { Copilot = icons.apps.Copilot })
--end
local function get_lsp_completion_context(completion, source)
        local config_ok, source_name = pcall(function()
                return source.source.client.config.name
        end)
        if not config_ok then
                return nil
        end
        if source_name == "tsserver" or source_name == "typescript-tools" then
                return completion.detail
        elseif source_name == "pyright" then
                if completion.labelDetails ~= nil then
                        return completion.labelDetails.description
                end
        end
end
cmp.setup({

        preselect = cmp.PreselectMode.None,
        snippet = {
                expand = function(args)
                        luasnip.lsp_expand(args.body) -- For `luasnip` users.
                end,
        },
        mapping = cmp.mapping.preset.insert({
                ["<C-k>"] = cmp.mapping.select_prev_item(),
                ["<C-j>"] = cmp.mapping.select_next_item(),
                ["<C-b>"] = cmp.mapping(cmp.mapping.scroll_docs(-4), { "i", "c" }),
                ["<C-f>"] = cmp.mapping(cmp.mapping.scroll_docs(4), { "i", "c" }),
                ["<C-Space>"] = cmp.mapping(cmp.mapping.complete(), { "i", "c" }),
                ["<C-y>"] = cmp.config.disable, -- Specify `cmp.config.disable` if you want to remove the default `<C-y>` mapping.
                ["<C-e>"] = cmp.mapping({
                        i = cmp.mapping.abort(),
                        c = cmp.mapping.close(),
                }),
                -- Accept currently selected item. If none selected, `select` first item.
                -- Set `select` to `false` to only confirm explicitly selected items.
                ["<CR>"] = cmp.mapping.confirm({ select = true, behavior = cmp.ConfirmBehavior.Replace }),
                ["<Tab>"] = cmp.mapping(function(fallback)
                        if cmp.visible() then
                                cmp.select_next_item()
                                -- You could replace the expand_or_jumpable() calls with expand_or_locally_jumpable()
                                -- they way you will only jump inside the snippet region
                        elseif luasnip.expand_or_jumpable() then
                                luasnip.expand_or_jump()
                        elseif has_words_before() then
                                cmp.complete()
                        else
                                fallback()
                        end
                end, { "i", "s" }),
                ["<S-Tab>"] = cmp.mapping(function(fallback)
                        if cmp.visible() then
                                cmp.select_prev_item()
                        elseif luasnip.jumpable(-1) then
                                luasnip.jump(-1)
                        else
                                fallback()
                        end
                end, { "i", "s" }),
        }),
        formatting = {
                fields = { "kind", "abbr", "menu" },
                format = function(entry, vim_item)
                        local kind = require("lspkind").cmp_format({
                                mode = "symbol_text",
                                ellipsis_char = "...",
                                maxwidth = 50,
                                symbol_map = source_mapping,
                        })(entry, vim_item)
                        local custom_menu_icon = {
                                calc = " 󰃬 ",
                                --NOTE: requires a nerdfont to be rendered
                                --you could include other sources here as well
                        }
                        local strings = vim.split(kind.kind, "%s", { trimempty = true })
                        kind.kind = " " .. (strings[1] or "") .. " "
                        if entry.source.name == "calc" then
                                -- Get the custom icon for 'calc' source
                                -- Replace the kind glyph with the custom icon
                                vim_item.kind = custom_menu_icon.calc
                        end
                        kind.menu = "    (" .. (strings[2] or "") .. ")"
                        local completion_context = get_lsp_completion_context(entry.completion_item, entry.source)
                        if completion_context ~= nil and completion_context ~= "" then
                                item_with_kind.menu = item_with_kind.menu .. [[ -> ]] .. completion_context
                        end
                        return kind
                end,
        },
        sources = cmp.config.sources({
                { name = "copilot" },
                { name = "nvim_lsp" },
                { name = "path" },
                { name = "buffer" },
                { name = "nvim_lsp_signature_help" },
                { name = "copilot" },
                { name = "emoji" },
                { name = "crates" },
                { name = "calc" },
                { name = "rg",                     keyword_length = 5 },
                { name = "luasnip" },
        }),
        -- window = {
        --         completion = cmp.config.window.bordered({
        --                 -- winhighlight = "NormalFloat:NormalFloat,FloatBorder:FloatBorder",
        --         }),
        --         documentation = cmp.config.window.bordered({
        --                 -- winhighlight = "NormalFloat:NormalFloat,FloatBorder:FloatBorder",
        --         }),
        -- },
        experimental = {
                ghost_text = true,
                -- native_menu = false,
        },
})
vim.cmd([[
  highlight! default link CmpItemKind CmpItemMenuDefault
]])
-- gray
vim.api.nvim_set_hl(0, "CmpItemAbbrDeprecated", { bg = "NONE", strikethrough = true, fg = "#808080" })
-- blue
vim.api.nvim_set_hl(0, "CmpItemAbbrMatch", { bg = "NONE", fg = "#569CD6" })
vim.api.nvim_set_hl(0, "CmpItemAbbrMatchFuzzy", { link = "CmpIntemAbbrMatch" })
-- light blue
vim.api.nvim_set_hl(0, "CmpItemKindVariable", { bg = "NONE", fg = "#9CDCFE" })
vim.api.nvim_set_hl(0, "CmpItemKindInterface", { link = "CmpItemKindVariable" })
vim.api.nvim_set_hl(0, "CmpItemKindText", { link = "CmpItemKindVariable" })
-- pink
vim.api.nvim_set_hl(0, "CmpItemKindFunction", { bg = "NONE", fg = "#C586C0" })
vim.api.nvim_set_hl(0, "CmpItemKindMethod", { link = "CmpItemKindFunction" })
-- front
vim.api.nvim_set_hl(0, "CmpItemKindKeyword", { bg = "NONE", fg = "#D4D4D4" })
vim.api.nvim_set_hl(0, "CmpItemKindProperty", { link = "CmpItemKindKeyword" })

vim.opt.completeopt = { "menu", "menuone", "noselect" }

If ther is anyone who can help me figure out whats wrong in my config

That looks like it could be a bug in nvim-cmp.

I suggest you find a way to reproduce it:

  • Minimal config (as few plugins as possible, as many as needed)
  • Language server / neovim LSP configuration
  • File or code snippet.

and then file a bug report with the steps to reproduce.

Thanks , I actually had to rebuild my config incrementally , not sure where the issue was