hrsh7th / nvim-cmp

A completion plugin for neovim coded in Lua.
MIT License
7.77k stars 385 forks source link

Error "Vim:E976: Using a Blob as a String" when trying to type "snippet" word with nvim-cmp and LuaSnip #2025

Open TomasRojoBiran opened 2 weeks ago

TomasRojoBiran commented 2 weeks ago

FAQ

Announcement

Minimal reproducible full config

-- ~/.config/nvim/init.lua -- Minimal configuration for reproducing the issue with nvim-cmp and LuaSnip using LazyVim

-- LazyVim Setup vim.cmd [[set runtimepath+=~/.local/share/nvim/lazy/LazyVim]]

require('lazy').setup({ 'neovim/nvim-lspconfig', 'williamboman/mason.nvim', 'williamboman/mason-lspconfig.nvim', 'WhoIsSethDaniel/mason-tool-installer.nvim', 'j-hui/fidget.nvim', 'folke/lazydev.nvim', 'hrsh7th/nvim-cmp', 'hrsh7th/cmp-nvim-lsp', 'hrsh7th/cmp-buffer', 'hrsh7th/cmp-path', 'hrsh7th/cmp-cmdline', 'L3MON4D3/LuaSnip', 'saadparwaiz1/cmp_luasnip', 'rafamadriz/friendly-snippets', }, { defaults = { lazy = true }, })

-- LSP Setup local lspconfig = require('lspconfig') local capabilities = require('cmp_nvim_lsp').default_capabilities() local cmp = require('cmp')

require('mason').setup() require('mason-lspconfig').setup({ ensure_installed = { 'lua_ls' } }) require('mason-tool-installer').setup({ ensure_installed = { 'stylua' } })

lspconfig.lua_ls.setup { capabilities = capabilities, settings = { Lua = { diagnostics = { globals = {'vim'} }, }, }, }

-- LuaSnip Setup local luasnip = require('luasnip') require('luasnip.loaders.from_vscode').lazy_load()

-- nvim-cmp Setup cmp.setup({ snippet = { expand = function(args) luasnip.lsp_expand(args.body) end, }, sources = { { name = 'nvim_lsp' }, { name = 'luasnip' }, { name = 'buffer' }, { name = 'path' }, }, })

-- LSP floating preview configuration local open_floating_preview = vim.lsp.util.open_floating_preview function vim.lsp.util.open_floating_preview(contents, syntax, opts, ...) opts = opts or {} opts.border = opts.border or "rounded" return open_floating_preview(contents, syntax, opts, ...) end

Description

when i try writing 'snippet' i have a big error: image

Steps to reproduce

Steps to Reproduce

Save the minimal configuration provided above to ~/.config/nvim/init.lua.

Start Neovim with the configuration above.

Open any file and start typing the word "snippet" to trigger the completion popup.

Observe the error message displayed: "Vim:E976: Using a Blob as a String". i cannot even manually extpand a snippet, i dont know why too.

Expected behavior

I expect nvim-cmp to display the completion menu without any errors when typing words such as "snippet". The completion suggestions should be correctly displayed, and snippet expansion should function properly without causing any errors. I am not kidding when i am saying that i have been trying to make this work for days, i really hope you can help me.

Actual behavior

When typing the word "snippet" or similar, the following error message is displayed: image

Additional context

Neovim version: latest nvim-cmp version: Latest, installed via Lazy.nvim LuaSnip version: Latest, installed via Lazy.nvim Operating system: Arch Linux Disabling the nvim_lsp source in nvim-cmp eliminates the error, but this also removes LSP-based completion, which is not ideal. The error seems to be related to how nvim-cmp handles or displays content in the completion popup, potentially related to snippet expansion. I've tried updating all plugins, simplifying my configuration, and checking for compatibility issues, but the error persists. See attached screenshot for the error message stack trace, the last error is the one i gave you the screenshots of, when you try writing "snippet": the messages:

LSP Capabilities: { textDocument = { completion = { completionItem = { commitCharactersSupport = true, deprecatedSupport = true, insertReplaceSupport = true, insertTextModeSupport = { valueSet = { 1, 2 } }, labelDetailsSupport = true, preselectSupport = true, resolveSupport = { properties = { "documentation", "detail", "additionalTextEdits", "sortText", "filterText", "insertText", "textEdit", "insertTextFormat", "insertTextMode" } }, snippetSupport = true, tagSupport = { valueSet = { 1 } } }, completionList = { itemDefaults = { "commitCharacters", "editRange", "insertTextFormat", "insertTextMode", "data" } }, contextSupport = true, dynamicRegistration = false, insertTextMode = 1 } } } Error executing vim.schedule lua callback: ....local/share/nvim/lazy/nvim-cmp/lua/cmp/utils/window.lua:310: Error executing lua: Vim:E976: Using a Blob as a String stack traceback: [C]: in function 'strdisplaywidth' ....local/share/nvim/lazy/nvim-cmp/lua/cmp/utils/window.lua:312: in function <....local/share/nvim/lazy/nvim-cmp/lua/cmp/utils/window.lua:310> [C]: in function 'nvim_buf_call' ....local/share/nvim/lazy/nvim-cmp/lua/cmp/utils/window.lua:310: in function 'get_content_height' ....local/share/nvim/lazy/nvim-cmp/lua/cmp/utils/window.lua:236: in function 'info' ....local/share/nvim/lazy/nvim-cmp/lua/cmp/utils/window.lua:83: in function 'set_style' ....local/share/nvim/lazy/nvim-cmp/lua/cmp/utils/window.lua:113: in function 'open' ...ocal/share/nvim/lazy/nvim-cmp/lua/cmp/view/docs_view.lua:115: in function 'open' /home/rojo/.local/share/nvim/lazy/nvim-cmp/lua/cmp/view.lua:299: in function 'callback' .../.local/share/nvim/lazy/nvim-cmp/lua/cmp/utils/async.lua:138: in function '' vim/_editor.lua: in function <vim/_editor.lua:0> stack traceback: [C]: in function 'nvim_buf_call' ....local/share/nvim/lazy/nvim-cmp/lua/cmp/utils/window.lua:310: in function 'get_content_height' ....local/share/nvim/lazy/nvim-cmp/lua/cmp/utils/window.lua:236: in function 'info' ....local/share/nvim/lazy/nvim-cmp/lua/cmp/utils/window.lua:83: in function 'set_style' ....local/share/nvim/lazy/nvim-cmp/lua/cmp/utils/window.lua:113: in function 'open' ...ocal/share/nvim/lazy/nvim-cmp/lua/cmp/view/docs_view.lua:115: in function 'open' /home/rojo/.local/share/nvim/lazy/nvim-cmp/lua/cmp/view.lua:299: in function 'callback' .../.local/share/nvim/lazy/nvim-cmp/lua/cmp/utils/async.lua:138: in function '' vim/_editor.lua: in function <vim/_editor.lua:0>

TomasRojoBiran commented 2 weeks ago

oh, this are my keymaps btw of both, cmp and luasnip, this are sepparated in another files called keymaps.lua of all my plugins keymaps:

-- luaSnip keybindings local ls = require("luasnip") vim.keymap.set({ "i" }, "", function() ls.expand() end, { silent = true }) vim.keymap.set({ "i", "s" }, "<C-;>", function() ls.jump(1) end, { silent = true }) vim.keymap.set({ "i", "s" }, "<C-,>", function() ls.jump(-1) end, { silent = true }) vim.keymap.set({ "i", "s" }, "", function() if ls.choice_active() then ls.change_choice(1) end end, { silent = true })

-- cmp keybindings local cmp = require('cmp') local cmp_select = { behavior = cmp.SelectBehavior.Select } vim.keymap.set('i', '', function() cmp.mapping.select_prev_item(cmp_select)() end, { silent = true, desc = 'nvim-cmp: Previous Item' }) vim.keymap.set('i', '', function() cmp.mapping.select_next_item(cmp_select)() end, { silent = true, desc = 'nvim-cmp: Next Item' }) vim.keymap.set('i', '', function() cmp.mapping.confirm({ select = true })() end, { silent = true, desc = 'nvim-cmp: Confirm' }) vim.keymap.set('i', '', function() cmp.mapping.complete()() end, { silent = true, desc = 'nvim-cmp: Complete' })