nvim-neorocks / rocks-treesitter.nvim

A "just works" tree-sitter setup for rocks.nvim!
GNU General Public License v3.0
30 stars 3 forks source link

Error While Opening Files with Tree-sitter Parsers Using Rocks.nvim #23

Closed alexanderjeurissen closed 2 weeks ago

alexanderjeurissen commented 1 month ago

Description: An error is encountered when opening files with various Tree-sitter parsers using rocks.nvim. The error message suggests a problem with loading the Tree-sitter parsers, indicating a failure to load the parsers for multiple languages.

Minimal Configuration:

Error Message:

Error detected while processing BufReadPost Autocommands for "*":
Error executing lua callback: ...rew/Cellar/neovim/0.10.1/share/nvim/runtime/filetype.lua:35: Error executing lua: ...rew/Cellar/neovim/0.10.1/share/nvim/runtime/filetype.lua:36: BufReadPost Autocommands for "*"..FileType Autocommands for "*": Vim(append):Error executing lua callback: ....10.1/share/
nvim/runtime/lua/vim/treesitter/language.lua:112: Failed to load parser for language 'toml': uv_dlopen: no error
stack traceback:
        [C]: in function '_ts_add_language'
        ....10.1/share/nvim/runtime/lua/vim/treesitter/language.lua:112: in function 'add'
        ...1/share/nvim/runtime/lua/vim/treesitter/languagetree.lua:111: in function 'new'
        .../neovim/0.10.1/share/nvim/runtime/lua/vim/treesitter.lua:41: in function '_create_parser'
        .../neovim/0.10.1/share/nvim/runtime/lua/vim/treesitter.lua:108: in function 'get_parser'
        .../neovim/0.10.1/share/nvim/runtime/lua/vim/treesitter.lua:416: in function 'start'
        .../nvim/rocks/rocks_rtp/lua/rocks_treesitter/highlight.lua:114: in function 'do_highlight'
        .../nvim/rocks/rocks_rtp/lua/rocks_treesitter/highlight.lua:141: in function <.../nvim/rocks/rocks_rtp/lua/rocks_treesitter/highlight.lua:135>
        [C]: in function 'nvim_cmd'
        ...rew/Cellar/neovim/0.10.1/share/nvim/runtime/filetype.lua:36: in function <...rew/Cellar/neovim/0.10.1/share/nvim/runtime/filetype.lua:35>
        [C]: in function 'nvim_buf_call'
        ...rew/Cellar/neovim/0.10.1/share/nvim/runtime/filetype.lua:35: in function <...rew/Cellar/neovim/0.10.1/share/nvim/runtime/filetype.lua:10>
stack traceback:
        [C]: in function 'nvim_cmd'
        ...rew/Cellar/neovim/0.10.1/share/nvim/runtime/filetype.lua:36: in function <...rew/Cellar/neovim/0.10.1/share/nvim/runtime/filetype.lua:35>
        [C]: in function 'nvim_buf_call'
        ...rew/Cellar/neovim/0.10.1/share/nvim/runtime/filetype.lua:35: in function <...rew/Cellar/neovim/0.10.1/share/nvim/runtime/filetype.lua:10>
stack traceback:
        [C]: in function 'nvim_buf_call'
        ...rew/Cellar/neovim/0.10.1/share/nvim/runtime/filetype.lua:35: in function <...rew/Cellar/neovim/0.10.1/share/nvim/runtime/filetype.lua:10>

Debug Steps Taken:

  1. Checked runtime paths:
    • :lua print(vim.inspect(package.path))
      • Result: "/opt/homebrew/Cellar/luarocks/3.9.1/share/lua/5.1/?.lua;/opt/homebrew/share/lua/5.1/?.lua;/opt/homebrew/share/lua/5.1/?/init.lua;/opt/homebrew/lib/lua/5.1/?.lua;/opt/homebrew/lib/lua/5.1/?/init.lua;./?.lua;./?/init.lua;/Users/alexander/.luarocks/share/lua/5.1/?.lua;/Users/alexander/.luarocks/share/lua/5.1/?/init.lua;/Users/alexander/.local/share/nvim/rocks/share/lua/5.1/?.lua;/Users/alexander/.local/share/nvim/rocks/share/lua/5.1/?/init.lua;/Users/alexander/.local/share/nvim/rocks/share/lua/5.1/init.lua"
    • :lua print(vim.inspect(package.cpath))
      • Result: "/opt/homebrew/lib/lua/5.1/?.so;/opt/homebrew/lib/lua/5.1/loadall.so;./?.so;/Users/alexander/.luarocks/lib/lua/5.1/?.so;/Users/alexander/.local/share/nvim/rocks/lib/lua/5.1/?.so;/Users/alexander/.local/share/nvim/rocks/lib64/lua/5.1/?.so;/Users/alexander/.local/share/nvim/rocks/lib/lua/5.1/?.dylib;/Users/alexander/.local/share/nvim/rocks/lib64/lua/5.1/?.dylib;/Users/alexander/.local/share/nvim/rocks/lib/lua/5.1/?.dll;/Users/alexander/.local/share/nvim/rocks/lib64/lua/5.1/?.dll"

Additional Notes:

System Information:

mrcjkb commented 1 month ago

Hey :wave:

uv_dlopen: no error usually indicates that luarocks failed to detect your system architecture and has installed the parser for the wrong one. I should add a troubleshooting section to the rocks(-treesitter).nvim readmes, you are not the first person to encounter this.

You should be able to work around this as follows:

vim.g.rocks_nvim = {
  -- ...
  luarocks_config = {
    arch = "macosx-aarch64" , -- or arch = "macosx-x86_64" , depending on your architecture
  },
}

If this solves the issue for you, please leave this open. I'll close it when I've added the troubleshooting section.

mrcjkb commented 1 month ago

:thinking: It might also be possible for rocks.nvim to use vim.uv to detect the architecture and set that config automatically.

alexanderjeurissen commented 1 month ago

Hi @mrcjkb I can confirm that this solves the issue.

I think it would be a good enhancement indeed to get this from vim.uv and to allow the user to override it if they need/desire to.

I created a rough POC to determine the arch using vim.uv:

-- Function to determine architecture
local function get_arch(sysname, machine)
  local arch_map = {
    Darwin = {
      arm64 = "macosx-aarch64",
      x86_64 = "macosx-x86_64"
    },
    Linux = {
      x86_64 = "linux-x86_64",
      arm64 = "linux-aarch64",
      aarch64 = "linux-aarch64"
    },
    Windows_NT = {
      x86_64 = "win32-x86_64",
      arm64 = "win32-arm64",
      [""] = "win32-arm64"  -- catch-all for other ARM variants
    }
  }

  return arch_map[sysname] and arch_map[sysname][machine]
end

-- Get the system architecture
local uname = vim.uv.os_uname()
local arch = get_arch(uname.sysname, uname.machine)
mrcjkb commented 1 month ago

Thanks, that's very helpful 😄 🙏 We can also use this to disable the binary servers for unsupported architectures:

alexanderjeurissen commented 1 month ago

@mrcjkb Hi wanted to check back in,

Tree-sitter parsers are installing smoothly now,

However there is one tree sitter parser that I encountered the original error with recently: tree-sitter-norg I'm not sure what is different about that parser but somehow it seems that the arch is not respected, strangely enough the tree-sitter-norg-meta parser does get installed correctly..

vim.treesitter: require("vim.treesitter.health").check()

- Nvim runtime ABI version: 14
- ERROR Parser "norg" failed to load (path: /Users/alexander/.local/share/nvim/site/pack/luarocks/opt/tree-sitter-norg/parser/norg.so): ...3a714/share/nvim/runtime/lua/vim/treesitter/language.lua:112: Failed to load parser for language 'norg': uv_dlopen: no error
- OK Parser: javascript           ABI: 14, path: /Users/alexander/.local/share/nvim/site/pack/luarocks/opt/tree-sitter-javascript/parser/javascript.so
- OK Parser: go                   ABI: 14, path: /Users/alexander/.local/share/nvim/site/pack/luarocks/opt/tree-sitter-go/parser/go.so
- OK Parser: json                 ABI: 14, path: /Users/alexander/.local/share/nvim/site/pack/luarocks/opt/tree-sitter-json/parser/json.so
- OK Parser: lua                  ABI: 14, path: /Users/alexander/.local/share/nvim/site/pack/luarocks/opt/tree-sitter-lua/parser/lua.so
- OK Parser: toml                 ABI: 14, path: /Users/alexander/.local/share/nvim/site/pack/luarocks/opt/tree-sitter-toml/parser/toml.so
- OK Parser: typescript           ABI: 14, path: /Users/alexander/.local/share/nvim/site/pack/luarocks/opt/tree-sitter-typescript/parser/typescript.so
- OK Parser: xml                  ABI: 14, path: /Users/alexander/.local/share/nvim/site/pack/luarocks/opt/tree-sitter-xml/parser/xml.so
- OK Parser: tsx                  ABI: 14, path: /Users/alexander/.local/share/nvim/site/pack/luarocks/opt/tree-sitter-tsx/parser/tsx.so
- OK Parser: tmux                 ABI: 14, path: /Users/alexander/.local/share/nvim/site/pack/luarocks/opt/tree-sitter-tmux/parser/tmux.so
- OK Parser: sql                  ABI: 14, path: /Users/alexander/.local/share/nvim/site/pack/luarocks/opt/tree-sitter-sql/parser/sql.so
- OK Parser: scss                 ABI: 13, path: /Users/alexander/.local/share/nvim/site/pack/luarocks/opt/tree-sitter-scss/parser/scss.so
- OK Parser: norg_meta            ABI: 14, path: /Users/alexander/.local/share/nvim/site/pack/luarocks/opt/tree-sitter-norg-meta/parser/norg_meta.so
- OK Parser: graphql              ABI: 13, path: /Users/alexander/.local/share/nvim/site/pack/luarocks/opt/tree-sitter-graphql/parser/graphql.so
- OK Parser: gitcommit            ABI: 14, path: /Users/alexander/.local/share/nvim/site/pack/luarocks/opt/tree-sitter-gitcommit/parser/gitcommit.so
- OK Parser: ruby                 ABI: 14, path: /Users/alexander/.local/share/nvim/site/pack/luarocks/opt/tree-sitter-ruby/parser/ruby.so
mrcjkb commented 1 month ago

@alexanderjeurissen tree-sitter-norg currently has issues on macOS (either M1 only or both M1 and x86_64; I'm not sure).

See also: https://github.com/nvim-neorg/tree-sitter-norg/issues/67

You might have to install it manually for now.