laytan / tailwind-sorter.nvim

Easily sort Tailwind classes in Neovim.
MIT License
134 stars 11 forks source link

Bug: attempt to call field 'get' #27

Closed mmirus closed 1 year ago

mmirus commented 1 year ago

Hey there! Thanks for the plugin!

After updating to the most recent commit, when I run TailwindSort, I receive:

Error executing Lua callback: ...lazy/tailwind-sorter.nvim/lua/tailwind-sorter/tsutil.lua:74: attempt to call field 'get' (a nil value)                                                                         
stack traceback:                                                                                                                                                                                                
        ...lazy/tailwind-sorter.nvim/lua/tailwind-sorter/tsutil.lua:74: in function 'fn'                                                                                                                        
        /usr/share/nvim/runtime/lua/vim/treesitter/languagetree.lua:210: in function 'for_each_tree'                                                                                                            
        ...lazy/tailwind-sorter.nvim/lua/tailwind-sorter/tsutil.lua:70: in function 'get_query_matches'                                                                                                         
        ...m/lazy/tailwind-sorter.nvim/lua/tailwind-sorter/init.lua:49: in function 'sort'                                                                                                                      
        ...m/lazy/tailwind-sorter.nvim/lua/tailwind-sorter/init.lua:22: in function <...m/lazy/tailwind-sorter.nvim/lua/tailwind-sorter/init.lua:21>

I'm guessing that this commit breaks compatibility with neovim 0.8.

Reverting to https://github.com/laytan/tailwind-sorter.nvim/commit/7a32f59c0cc8a73022be2c93fcbac1de825abfb9 fixes the error.

If that's correct, would it be possible to maintain compatibility in some form with the current stable neovim release? I (and likely many other) don't like to run nightly.

Worst case, I can pin to the last good commit.

laytan commented 1 year ago

Hey, thanks for bringing this up!

I will go over the plugin tomorrow and make sure everything works on the stable neovim branch as well.

Will also add testing on the stable version to the ci so this doesn't happen again!

jayroh commented 1 year ago

Yeah, ran into this here as well. Changing tailwind-sorter.nvim/lua/tailwind-sorter/tsutil.lua#74 to:

local query = vim.treesitter.query.get_query(lang, 'tailwind')

... fixes it.

Output from :lua print(vim.inspect(require'vim.treesitter.query')):

{
  add_directive = <function 1>,
  add_predicate = <function 2>,
  get_node_text = <function 3>,
  get_query = <function 4>,
  get_query_files = <function 5>,
  list_directives = <function 6>,
  list_predicates = <function 7>,
  parse_query = <function 8>,
  set_query = <function 9>
}

neovim info:

❯ nvim --version
NVIM v0.8.3
Build type: Release
LuaJIT 2.1.0-beta3
mmirus commented 1 year ago

Thanks both! @laytan LMK if there's anything I can do to help test.

laytan commented 1 year ago

@jayroh Thanks! Yes it would fix it on stable, on nightly I think that function is deprecated in favor of the one I used here. I will have to add a check to choose between the 2.

laytan commented 1 year ago

@mmirus @jayroh This is now fixed on the main branch and the v2.2.1 release.

mmirus commented 1 year ago

Thank you for the quick fix, @laytan! :partying_face:

jayroh commented 1 year ago

Yessss! Thanks so much!