HampusHauffman / block.nvim

209 stars 2 forks source link

block.lua:41: attempt to call field 'unpack' (a nil value) #3

Closed nyngwang closed 1 year ago

nyngwang commented 1 year ago
Error executing Lua callback: ...ng/.local/share/nvim/lazy/block.nvim/lua/block/block.lua:41: attempt to call field 'unpack' (a nil value)
stack traceback:
    ...ng/.local/share/nvim/lazy/block.nvim/lua/block/block.lua:41: in function 'convert_ts_node'
    ...ng/.local/share/nvim/lazy/block.nvim/lua/block/block.lua:138: in function 'update'
    ...ng/.local/share/nvim/lazy/block.nvim/lua/block/block.lua:147: in function 'add_buff_and_start'
    ...ng/.local/share/nvim/lazy/block.nvim/lua/block/block.lua:165: in function <...ng/.local/share/nvim/lazy/block.nvim/lua/block/block.lua:162>
use {
  'HampusHauffman/block.nvim',
  config = function ()
    require('block').setup {
      percent = 0.8, -- e.g. 0.8 would change each box to be 20% darker than the last and 1.2 would be 20% brighter.
      depth = 4, -- after this the colors reset.
      automatic = false,
    }
  end
}
chrisgrieser commented 1 year ago

also got this error, also using default settings.

neovim 0.9.1 (homebrew)
macOS 13.4 (M1)
Neovide 0.10.4 (homebrew)
HampusHauffman commented 1 year ago

Do you have Treesitter installed for the filetype you're opening?

HampusHauffman commented 1 year ago

https://github.com/HampusHauffman/block.nvim/commit/6c5b0e13fdfe7ae0b97accb52274066e8ccb7a88 Curious if this was the issue. If you could please try it again after updating. Mind you calling Block on files types that are not supported or not installed with treesitter wont work (but shouldnt throw an error)

chrisgrieser commented 1 year ago

using on lua files, where I also have the treesitter parser installed

still getting the very same error with the update

OneSleeve commented 1 year ago

Running into the same issue.

IndianBoy42 commented 1 year ago

This is not a treesitter problem or related to that commit, as the error says there is no table.unpack on your systems. table.unpack and table.pack were added in lua 5.2 moving it from builtin functions to inside the table metatable. luajit is based on lua 5.1, with some 5.2 additions backported. If luajit is compiled with LUAJIT_ENABLE_LUA52COMPAT it enables a few more 5.2 features, among which is table.unpack and table.pack in addition to the builtins unpack, pack. It seems some people have it (author) and some don't

Anyway just use unpack, pack

OneSleeve commented 1 year ago

Thank you!

Changing table.unpack to unpack worked.

HampusHauffman commented 1 year ago

https://github.com/HampusHauffman/block.nvim/commit/93b8163bca9f39d95362b1a968a6a5a5f3a6d492 Yes thank you @IndianBoy42!

chrisgrieser commented 1 year ago

nice, thanks @IndianBoy42.

btw @HampusHauffman, you can catch this type of problem early on by telling the lua-lsp to use LuaJIT.

create a file named .luarc.json with the following content and put it into the root folder of your plugin.

{
    "runtime.version": "LuaJIT"
}

Then, using lua code not valid in LuaJIT like table.unpack should result in a diagnostic message by the lua LSP: CleanShot 2023-06-15 at 13 14 35@2x

nyngwang commented 1 year ago

While the error disappeared, it doesn't show me the highlight after calling :BlockOn.

HampusHauffman commented 1 year ago

@nyngwang Hard to troubleshoot if just nothing happens :/

nyngwang commented 1 year ago

@HampusHauffman I just found a clue that if I call the setup the second time manually after the Lua LSP has been loaded then calling :Block again will show the coloring.

HampusHauffman commented 1 year ago

@nyngwang Could you show me the setup you have in your plugin manager?

nyngwang commented 1 year ago

Yes, I'm using the same one:

update: I realized that it has nothing to do with Lua LSP.

use {
  'HampusHauffman/block.nvim',
  config = function ()
    require('block').setup {
      percent = 0.8, -- e.g. 0.8 would change each box to be 20% darker than the last and 1.2 would be 20% brighter.
      depth = 4, -- after this the colors reset.
      automatic = false,
    }
  end
}
HampusHauffman commented 1 year ago

@nyngwang Does that mean you solved it?

nyngwang commented 1 year ago

No. I'm still finding the reason why I need to call the setup again to ensure that :BlockOn will take effect after entering Neovim. But I found that I don't have to wait for the Lua LSP to finish before calling setup.

nyngwang commented 1 year ago

@HampusHauffman My bad, I should create a new issue, since the title of this issue had been resolved. Let me close this and tag you there.