Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

attempt to call local 'fn' (a table value) #1933

Open
2 tasks done
sahinakkaya opened this issue May 16, 2024 · 9 comments
Open
2 tasks done

attempt to call local 'fn' (a table value) #1933

sahinakkaya opened this issue May 16, 2024 · 9 comments
Labels
bug Something isn't working

Comments

@sahinakkaya
Copy link

FAQ

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

Announcement

Minimal reproducible full config

if has('vim_starting')
  set encoding=utf-8
endif
scriptencoding utf-8

if &compatible
  set nocompatible
endif

let s:plug_dir = expand('/tmp/plugged/vim-plug')
if !filereadable(s:plug_dir .. '/plug.vim')
  execute printf('!curl -fLo %s/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim', s:plug_dir)
end

execute 'set runtimepath+=' . s:plug_dir
call plug#begin(s:plug_dir)
Plug 'hrsh7th/nvim-cmp'
Plug 'hrsh7th/cmp-buffer'
Plug 'hrsh7th/cmp-nvim-lsp'
Plug 'hrsh7th/vim-vsnip'
Plug 'neovim/nvim-lspconfig'
call plug#end()
PlugInstall | quit

" Setup global configuration. More on configuration below.
lua << EOF
local cmp = require "cmp"
cmp.setup {
  snippet = {
    expand = function(args)
      vim.fn["vsnip#anonymous"](args.body)
    end,
  },

  mapping = {
    ["<Tab>"] = cmp.mapping(function(fallback)
      if cmp.visible() then
        cmp.select_next_item()
      else
        fallback()
      end
    end, { "i", "s", "c" }),
    ['<CR>'] = cmp.mapping.confirm({ select = true })
  },
    sorting = {
      priority_weight = 2,
      comparators = {
        cmp.config.compare.exact,
        cmp.config.compare.locality,
        cmp.config.compare.recently_used,
        cmp.config.compare.score,
        cmp.config.compare.sources,
        cmp.config.compare.offset
      },
    },
  sources = cmp.config.sources({
    { name = "nvim_lsp" },
    { name = "buffer" },
  }),
}
EOF

lua << EOF
local capabilities = require('cmp_nvim_lsp').default_capabilities()

require'lspconfig'.cssls.setup {
  capabilities = capabilities,
}
EOF

Description

When I open nvim with some comparators defined in nvim-cmp, they are giving me error in the title.

Steps to reproduce

Open nvim with nvim -u cmp-repro.vim cmp-repro.vim and just insert any character. You will see an error in the bottom.

Expected behavior

I should be able to use all comparators.

Actual behavior

I get an error any time completion list is updated.

Additional context

❯ nvim --version
NVIM v0.10.0
Build type: Debug
LuaJIT 2.1.1713484068
Run "nvim -V1 -v" for more info
@sahinakkaya sahinakkaya added the bug Something isn't working label May 16, 2024
@croyleje
Copy link

croyleje commented May 23, 2024

I have the same problem was able to fix by rolling back the latest neovim update.

@sahinakkaya
Copy link
Author

sahinakkaya commented May 23, 2024

You mean I should rollback to nvim 0.9.5? When your car has a flat tire, you replace the tire not the car.

@erynofwales
Copy link

Several of the items in the compare module are tables with __call metamethods rather than simple functions. The recently_used comparator is one of those.

Commenting that one out in my comparators list fixed the problem for me.

@sahinakkaya
Copy link
Author

sahinakkaya commented Jun 8, 2024

Commenting that one out in my comparators list fixed the problem for me.

Yeah, of course. Just another "workaround". I don't want to downgrade neovim, I don't want to "hide" the problem by commenting it out. I want it to be fixed. That's why I opened this. In fact, I already know the problem is related with comparators:

When I open nvim with some comparators defined in nvim-cmp, they are giving me error in the title.

Instead of suggesting workarounds please upvote the issue so that it can get some attention from developers.

@Shougo
Copy link

Shougo commented Jun 9, 2024

OK. I have reproduced.

@Shougo
Copy link

Shougo commented Jun 9, 2024

It seems misc.merge() is broken.

misc.merge = function(tbl1, tbl2)
  local is_dict1 = type(tbl1) == 'table' and (not islist(tbl1) or vim.tbl_isempty(tbl1))
  local is_dict2 = type(tbl2) == 'table' and (not islist(tbl2) or vim.tbl_isempty(tbl2))
  if is_dict1 and is_dict2 then
    local new_tbl = {}
    for k, v in pairs(tbl2) do
      if tbl1[k] ~= misc.none then
        new_tbl[k] = misc.merge(tbl1[k], v)
      end
    end
    for k, v in pairs(tbl1) do
      if tbl2[k] == nil then
        if v ~= misc.none then
          new_tbl[k] = misc.merge(v, {})
        else
          new_tbl[k] = nil
        end
      end
    end
    return new_tbl
  end

  if tbl1 == misc.none then
    return nil
  elseif tbl1 == nil then
    return misc.merge(tbl2, {})
  else
    return tbl1
  end
end

misc.merge brokes metatable. __call is removed. So it will be error.

@Shougo
Copy link

Shougo commented Jun 9, 2024

I have fixed it in #1956. Please test.

@futsuuu
Copy link

futsuuu commented Oct 27, 2024

@sahinakkaya cmp.config.compare.sources does not exist. I think you can fix the error by removing nil-containing lists from your config.

local comparators = {
    cmp.config.compare.exact,
    cmp.config.compare.locality,
    cmp.config.compare.recently_used,
    cmp.config.compare.score,
    cmp.config.compare.sources,  -- == nil
    cmp.config.compare.offset
}
assert(vim.islist(comparators) == false)

misc.merge() detects dict-like tables with vim.islist() and merges them, so comparators field (list-like table) and its elements can not to be merged.
But if you put nil in the list-like table, vim.islist() returns false and then misc.merge() tries to merge comparators.

@Shougo
Copy link

Shougo commented Nov 6, 2024

OK. It seems configuration bug.
cmp.config.compare.sources does not exist(it is exists once?).

But I think nil check is needed for it...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants