nvim-neorocks / rocks.nvim

Neovim plugin management inspired by Cargo, powered by luarocks
GNU General Public License v3.0
556 stars 7 forks source link

macOS: Luarocks installs parsers for the wrong architecture #458

Closed bottd closed 1 day ago

bottd commented 4 days ago

This was originally working for me, but I have had no luck troubleshooting in the past couple of days. I get the following error in :checkhealth for any parser installed using rocks.nvim:

- ERROR Parser "toml" failed to load (path: /Users/drakebott/.local/share/nvim/site/pack/luarocks/opt/tree-sitter-toml/parser/toml.so): ....10.0/share/nvim/runtime/lua/vim/treesitter/language.lua:112: Failed to load parser for language 'toml': uv_dlopen: no error
- ERROR Parser "toml.so" failed to load (path: /Users/drakebott/.local/share/nvim/site/pack/luarocks/opt/tree-sitter-toml/parser/toml.so.dSYM): ....10.0/share/nvim/runtime/lua/vim/treesitter/language.lua:101: 'toml.so' is not a valid language name

For a minimal reproduction on my machine I removed and reinstalled a clean Neovim 0.10.0, placed the rocks bootstrap script in init.lua and used the following rocks.toml:

[plugins]
"rocks.nvim" = "2.33.0" # rocks.nvim can also manage itself :D
"rocks-treesitter.nvim" = "scm"
tree-sitter-toml = "scm"
mrcjkb commented 4 days ago

Hey :wave:

I presume you're using our rocks_binaries server to install the parser (i.e., you don't need to compile it locally)?

The uv_dlopen error you're seeing is because of an architecture issue. It's likely you're using aarch64 parsers with an x86_64 (Intel) Neovim build (or vice versa).

Maybe you're running into the same problem as this one? (see the edit).

bottd commented 3 days ago

It looks like my Neovim install is aarch64, but the parser file I have downloaded was compiled for x86_64. How can I change what arch I download parsers for? Could this be caused by something else I have installed being x86_64 like luarocks?

mrcjkb commented 3 days ago

Is your Lua or Luarocks install running on Rosetta? Ideally, you would want to make sure it's built against the same architecture as Neovim.

But there are some other options:

Overriding the luarocks config with a file path will soon be deprecated in favour of a table:

bottd commented 3 days ago

Creating a custom luarocks config file to add arch = "macosx-aarch64" fixed it on reinstall, thanks! I also have this additional healthcheck error alongside each successful parser load of the parser:

- ERROR Parser "toml.so" failed to load (path: /Users/drakebott/.local/share/nvim/site/pack/luarocks/opt/tree-sitter-toml/parser/toml.so.dSYM): ....10.0/share/nvim/runtime/lua/vim/treesitter/language.lua:101: 'toml.so' is not a valid language name

mrcjkb commented 3 days ago

It looks like Neovim is getting confused by the .dSYM file extension.

What are the contents of the /Users/drakebott/.local/share/nvim/site/pack/luarocks/opt/tree-sitter-toml/parser/ directory? If there's a toml.so and a toml.so.dSYM file, does it go away (and still work) if you delete the .dSYM file? And if you reinstall the parser, does it reappear?

It appears to be a file with debug symbols. But I don't know if it's generated at runtime (e.g. when something goes wrong) or at compile time.

bottd commented 3 days ago

That directory has:

toml.so
toml.so.dSYM

If I delete it stays gone until I reinstall tree-sitter-toml then I have toml.so.dSYM again.

mrcjkb commented 3 days ago

Thanks 🙏

That means it's getting created at compile time. I've created an issue to work around this in the luarocks build backend for tree-sitter parsers.

bottd commented 3 days ago

I'm finding more parser errors I was unaware of. Some parsers I need like tree-sitter-rust or tree-sitter-javascript are erroring out when I load them:

tree-sitter-rust

Error in decoration provider treesitter/highlighter.win:
Error executing lua: ...m/0.10.0/share/nvim/runtime/lua/vim/treesitter/query.lua:252: Query error at 370:2. Invalid node type "empty_type":
(empty_type "!" @type.builtin)
 ^

stack traceback:
        [C]: in function '_ts_parse_query'
        ...m/0.10.0/share/nvim/runtime/lua/vim/treesitter/query.lua:252: in function 'fn'
        ...ovim/0.10.0/share/nvim/runtime/lua/vim/func/_memoize.lua:58: in function 'fn'
        ...ovim/0.10.0/share/nvim/runtime/lua/vim/func/_memoize.lua:58: in function 'get'
        ....0/share/nvim/runtime/lua/vim/treesitter/highlighter.lua:28: in function 'new'
        ....0/share/nvim/runtime/lua/vim/treesitter/highlighter.lua:240: in function 'get_query'
        ....0/share/nvim/runtime/lua/vim/treesitter/highlighter.lua:188: in function 'fn'
        ...0/share/nvim/runtime/lua/vim/treesitter/languagetree.lua:491: in function 'for_each_tree'
        ....0/share/nvim/runtime/lua/vim/treesitter/highlighter.lua:175: in function 'prepare_highlight_states'
        ....0/share/nvim/runtime/lua/vim/tr

tree-sitter-javascript

Error in decoration provider treesitter/highlighter.win:
Error executing lua: ...m/0.10.0/share/nvim/runtime/lua/vim/treesitter/query.lua:252: Query error at 80:2. Invalid node type "function":
(function
 ^

stack traceback:
        [C]: in function '_ts_parse_query'
        ...m/0.10.0/share/nvim/runtime/lua/vim/treesitter/query.lua:252: in function 'fn'
        ...ovim/0.10.0/share/nvim/runtime/lua/vim/func/_memoize.lua:58: in function 'fn'
        ...ovim/0.10.0/share/nvim/runtime/lua/vim/func/_memoize.lua:58: in function 'get'
        ....0/share/nvim/runtime/lua/vim/treesitter/highlighter.lua:28: in function 'new'
        ....0/share/nvim/runtime/lua/vim/treesitter/highlighter.lua:240: in function 'get_query'
        ....0/share/nvim/runtime/lua/vim/treesitter/highlighter.lua:188: in function 'fn'
        ...0/share/nvim/runtime/lua/vim/treesitter/languagetree.lua:491: in function 'for_each_tree'
        ....0/share/nvim/runtime/lua/vim/treesitter/highlighter.lua:175: in function 'prepare_highlight_states'
        ....0/share/nvim/runtime/lua/vim/treesitter/highlighter.lua
mrcjkb commented 3 days ago

That looks like some of your queries (likely provided by another plugin) are incompatible with the parser. Are you using the master branch of nvim-treesitter by any chance?

bottd commented 3 days ago

I don't remember why but I was installing nvim-treesitter with rev = "v0.9.2^{}". I removed this and installed with only git = "nvim-treesitter/nvim-treesitter" now the previously mentioned parsers are working! Thanks again

mrcjkb commented 3 days ago

git = "nvim-treesitter/nvim-treesitter" will install the master branch, which still adds queries (that may be out of sync with the luarocks parsers) to the runtimepath.

We recommend either using the main branch (but that is for neovim nightly) or using nvim-treesitter-legacy-api. The scm version is equivalent to the nvim-treesitter master branch, but doesn't add any queries to the runtimepath.

bottd commented 3 days ago

I tried installing nvim-treesitter-legacy-api earlier. My plugins that use treesitter worked, but I couldn't use :TSUpdate or :TSInstall commands so I switched back to nvim-treesitter. I will update my config to use the main branch

mrcjkb commented 1 day ago

Yep, TSUpdate and TSInstall aren't needed if you're using luarocks to manage the parsers.