Skip to content

bad argument #2 to 'to_utfindex'  #2196

@eyalk11

Description

@eyalk11

FAQ

  • I have checked the FAQ and it didn't resolve my problem.

Announcement

Minimal reproducible full config

Not needed

Description

C:/Users/ekarni/.vim/plugged/nvim-cmp/lua/cmp/context.lua:56: bad argument #2 to 'to_utfindex' (number expected, got string)

# stacktrace:
  - nvim-cmp\lua\cmp\context.lua:56 _in_ **new**
  - nvim-cmp\lua\cmp\context.lua:25 _in_ **empty**
  - nvim-cmp\lua\cmp\context.lua:44 _in_ **new**
  - nvim-cmp\lua\cmp\core.lua:28 _in_ **new**
  - nvim-cmp\lua\cmp\init.lua:12
  - ~/AppData/Local/nvim/lua/plugins/cmp.lua:26 _in_ **config**
  - avante.nvim\lua\avante\init.lua:497 _in_ **setup**
  - ~\.vim\t.lua:2

Happens all the time when importing nvim-cmp.

To resolve (sorry for not creating pr) .

diff --git a/lua/cmp/utils/misc.lua b/lua/cmp/utils/misc.lua
index 5eafc55..8f4e92e 100644
--- a/lua/cmp/utils/misc.lua
+++ b/lua/cmp/utils/misc.lua
@@ -197,9 +197,9 @@ end
 ---@return integer
 misc.to_utfindex = function(text, vimindex)
   vimindex = vimindex or #text + 1
-  if vim.fn.has('nvim-0.11') == 1 then
-    return vim.str_utfindex(text, 'utf-16', math.max(0, math.min(vimindex - 1, #text)))      
-  end
+  --if vim.fn.has('nvim-0.11') == 1 then
+    --return vim.str_utfindex(text, 'utf-16', math.max(0, math.min(vimindex - 1, #text)))    
+  --end
   return vim.str_utfindex(text, math.max(0, math.min(vimindex - 1, #text)))
 end

b5311ab is the commit in nvim-cmp



NVIM v0.11.0-dev-250+g61aabe073
Build type: RelWithDebInfo
LuaJIT 2.1.1716656478
Run ":verbose version" for more info

Steps to reproduce

xxxx

Expected behavior

yyyy

Actual behavior

sdasdasd

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions