nvim-neorocks / rocks.nvim

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

Processing of luarocks fails when cwd is rocks or plugin directory #312

Open salkin-mada opened 5 months ago

salkin-mada commented 5 months ago

I just stumbled upon this: cd ~/.local/share/nvim/rocks/share/lua/5.1/rocks and then running neovim throws:

Error detected while processing /Users/salkin/.local/share/nvim/rocks/lib/luarocks/rocks-5.1/rocks-git.nvim/1.5.0-1/plugin/rocks-git.lua:                                  
E5113: Error while calling lua chunk: ./fzy.lua:21: loop or previous error loading module 'fzy'                                                                            
stack traceback:                                                                                                                                                           
        [C]: in function 'require'                                                                                                                                         
        ./fzy.lua:21: in main chunk                                                                                                                                        
        [C]: in function 'require'                                                                                                                                         
        ...lkin/.local/share/nvim/rocks/share/lua/5.1/rocks/fzy.lua:21: in main chunk                                                                                      
        [C]: in function 'require'                                                                                                                                         
        ....local/share/nvim/rocks/share/lua/5.1/rocks/commands.lua:53: in main chunk                                                                                      
        [C]: in function 'require'                                                                                                                                         
        ....local/share/nvim/rocks/share/lua/5.1/rocks/api/init.lua:27: in main chunk                                                                                      
        [C]: in function 'require'                                                                                                                                         
        ...ks/rocks-5.1/rocks-git.nvim/1.5.0-1/plugin/rocks-git.lua:4: in main chunk                                                                                       
Error detected while processing /Users/salkin/.local/share/nvim/rocks/lib/luarocks/rocks-5.1/rocks-treesitter.nvim/scm-1/plugin/rocks-treesitter.lua:                      
E5113: Error while calling lua chunk: ...are/nvim/rocks/share/lua/5.1/rocks_treesitter/config.lua:14: loop or previous error loading module 'rocks.api'                    
stack traceback:                                                                                                                                                           
        [C]: in function 'require'                                                                                                                                         
        ...are/nvim/rocks/share/lua/5.1/rocks_treesitter/config.lua:14: in main chunk                                                                                      
        [C]: in function 'require'                                                                                                                                         
        .../rocks-treesitter.nvim/scm-1/plugin/rocks-treesitter.lua:5: in main chunk                                                                                       
Error detected while processing /Users/salkin/.local/share/nvim/rocks/lib/luarocks/rocks-5.1/rocks.nvim/2.26.0-1/plugin/rocks.lua:                                         
E5113: Error while calling lua chunk: .../luarocks/rocks-5.1/rocks.nvim/2.26.0-1/plugin/rocks.lua:33: loop or previous error loading module 'rocks.commands'               
stack traceback:                                                                                                                                                           
        [C]: in function 'require'                                                                                                                                         
        .../luarocks/rocks-5.1/rocks.nvim/2.26.0-1/plugin/rocks.lua:33: in main chunk

Then doing a cd .. to get out of the rocks folder into ~/.local/share/nvim/rocks/share/lua/5.1 Run neovim from that cwd -> it is fine. All good. I can even navigate with netrw/fzf to the rocks folder and open/edit files. All good.

So rocks.nvim fails if cwd is the rocks path it self?

NVIM v0.10.0-dev-3045+gefaf37a2b Build type: RelWithDebInfo LuaJIT 2.1.1713484068 Run "nvim -V1 -v" for more info

mrcjkb commented 5 months ago

:thinking: I suppose it could be a bug in the luarocks loader? Does it happen if you set enable_luarocks_loader = false in your vim.g.rocks_nvim config?

salkin-mada commented 5 months ago

Can you reproduce?

I added:

-- Lua Rocks --
local rocks_config = {
    rocks_path = vim.env.HOME .. "/.local/share/nvim/rocks",
    luarocks_binary = vim.env.HOME .. "/.local/share/nvim/rocks/bin/luarocks",
    enable_luarocks_loader = false
}

vim.g.rocks_nvim = rocks_config

and did the same cd and nvim as mentioned before. Same error

salkin-mada commented 5 months ago

A bug in rocks-git maybe?

mrcjkb commented 5 months ago

Can you reproduce?

No, because I have rocks.nvim installed with nix. @vhyrro are you able to reproduce this?

boydkelly commented 5 months ago

I also was just migrating my config files (from lazy) and had a lot of issues with this the last few days. My setup files are in the plugin directory. I finally figured out that if that is my cwd then I get the above errors for a good portion (but not all) of my setup files. I haven`t investigated that further as my workaround was just to back out of the plugin before editing any files there. Not sure what other info I might be able to provide.... (I am super happy with nvim-rocks!!!) Thanks!!

sample errors if cwd is nvim-rocks/plugin(otherwise no errors):

Error detected while processing /var/home/bkelly/.config/nvim-rocks/plugin/conform.lua:
E5113: Error while calling lua chunk: ./conform.lua:43: loop or previous error loading module 'conform'
stack traceback:
        [C]: in function 'require'
        ./conform.lua:43: in main chunk
        [C]: in function 'require'
        /var/home/bkelly/.config/nvim-rocks/plugin/conform.lua:43: in main chunk
Error detected while processing /var/home/bkelly/.config/nvim-rocks/plugin/dressing.lua:
E5113: Error while calling lua chunk: ./dressing.lua:36: loop or previous error loading module 'dressing'
stack traceback:
        [C]: in function 'require'
        ./dressing.lua:36: in main chunk
        [C]: in function 'require'
        /var/home/bkelly/.config/nvim-rocks/plugin/dressing.lua:36: in main chunk
Error detected while processing /var/home/bkelly/.config/nvim-rocks/plugin/fidget.lua:
E5113: Error while calling lua chunk: ./fidget.lua:1: loop or previous error loading module 'fidget'
stack traceback:
        [C]: in function 'require'
        ./fidget.lua:1: in main chunk
        [C]: in function 'require'
        /var/home/bkelly/.config/nvim-rocks/plugin/fidget.lua:1: in main chunk
Error detected while processing /var/home/bkelly/.config/nvim-rocks/plugin/fzf-lua.lua:
E5113: Error while calling lua chunk: ./fzf-lua.lua:1: loop or previous error loading module 'fzf-lua'
stack traceback:
        [C]: in function 'require'
        ./fzf-lua.lua:1: in main chunk
        [C]: in function 'require'
        /var/home/bkelly/.config/nvim-rocks/plugin/fzf-lua.lua:1: in main chunk
mrcjkb commented 4 months ago

@boydkelly thanks for the input and nice words. I just set up a minimal plain (non-nix) rocks.nvim installation (with NVIM_APPNAME set to rocksvim, no plugins installed), and tried the following:

cd ~/.config/rocksvim
mkdir plugin
cd plugin
nvim dressing.lua

and did not encounter any errors. Do you have a link to your rocks.toml so that I can try and bisect it?

salkin-mada commented 4 months ago

@boydkelly what system are you on? I am having trouble reproducing this on Arch in any of the mentioned paths, but on the macOS ~/.local/share/nvim/rocks/share/lua/5.1/rocks is fail. Also I cant reproduce the error in my plugins folder on any of the systems -> ~/.config/nvim/lua/plugins/

mrcjkb commented 4 months ago

@boydkelly what system are you on? I am having trouble reproducing this on Arch in any of the mentioned paths, but on the macOS ~/.local/share/nvim/rocks/share/lua/5.1/rocks is fail. Also I cant reproduce the error in my plugins folder on any of the systems -> ~/.config/nvim/lua/plugins/

Ooh, could it be a path with spaces in it or something? :thinking:

boydkelly commented 4 months ago

@mrcjkb So strange! I am in a Fedora 40 container. I did have luarocks installed in the container and removed that but still the same issue. Here is the complete repo. (Its working mostly, although a work in progress moving from lazy) https://gitlab.com/boydkelly/nvim-rocks.git

I am also using NVIM_APPNAME=nvim-rocks, and was wondering if that somehow might be a problem? I will try to move it all to ./config/nvim and see if that makes any difference. For now I just have to not edit any of the files in plugin.

My config does seem to be mostly working otherwise. Couple of issues that I will report later if I don't solve.

Just an fyi, I don't have to edit a file in plugin. If plugin is my cwd, then just running nvim-rocks will output an ton of those errors, but if i start nvim-rocks anywhere else it works fine.

mrcjkb commented 4 months ago

Thanks. I'll see if I can reproduce it with your config later 👀

kflak commented 4 months ago

Running into a similar issue here on my Arch Linux install after the last Rocks update. I can edit files just fine from anywhere but my plugin config folder, which in my case is ~/.config/nvim/lua/rocks-plugs

Errors:

Error detected while processing /home/kf/.local/share/nvim/rocks/lib/luarocks/rocks-5.1/luasnip/2.3.0-1/plugin/luasnip.lua:
E5113: Error while calling lua chunk: ....local/share/nvim/rocks/share/lua/5.1/luasnip/config.lua:100: attempt to index a boolean value
stack traceback:
        ....local/share/nvim/rocks/share/lua/5.1/luasnip/config.lua:100: in function '_setup'
        ...ib/luarocks/rocks-5.1/luasnip/2.3.0-1/plugin/luasnip.lua:79: in main chunk

and

Vim:E5113: Error while calling lua chunk: ....local/share/nvim/rocks/share/lua/5.1/luasnip/config.lua:100: attempt to index a boolean value
stack traceback:                                                                                                                                  
^I....local/share/nvim/rocks/share/lua/5.1/luasnip/config.lua:100: in function '_setup'                                                           
^I...ib/luarocks/rocks-5.1/luasnip/2.3.0-1/plugin/luasnip.lua:79: in main chunk                                                                   
^I[C]: at 0x61d5a6b8f110                                                                                                                          
^I[C]: in function 'pcall'                                                                                                                        
^I.../.local/share/nvim/rocks/share/lua/5.1/rocks/runtime.lua:35: in function 'packadd'                                                           
^I.../.local/share/nvim/rocks/share/lua/5.1/rocks/runtime.lua:61: in function 'source_start_plugins'                                              
^I.../luarocks/rocks-5.1/rocks.nvim/2.27.1-1/plugin/rocks.lua:59: in main chunk 

My dotfiles are here, hopefully they can help you replicate.

mrcjkb commented 4 months ago

@boydkelly I just installed all of your plugins with NVIM_APPNAME = nvim-rocks.

@kflak the symptom seems related, but the error message looks different. It seems to be something thrown by luasnip. What makes it even stranger is that there's nothing but a parenthesis at the specified location (config.lua, line 100) at the v2.3.0 tag. There's a call to require("luasnip") at line 99. Maybe there's something funky going on with the luarocks loader and that is returning a boolean instead of a module? But others have not been able to work around the issue by setting the enable_luarocks_loader config to false.

mrcjkb commented 4 months ago

@kflak I just tried with you config too, and couldn't reproduce it either. Maybe somehow your installations (rocks or plugins) got corrupted? You could try cleaning and reinstalling rocks.nvim and/or the affected plugins.

kflak commented 4 months ago

@kflak I just tried with you config too, and couldn't reproduce it either. Maybe somehow your installations (rocks or plugins) got corrupted? You could try cleaning and reinstalling rocks.nvim and/or the affected plugins.

OK, I've managed to narrow it down to luasnip. The error doesn't happen when I install it with rocks-git, so there's something smelly with the rocks package, I suppose...

mrcjkb commented 4 months ago

@kflak I just tried with you config too, and couldn't reproduce it either. Maybe somehow your installations (rocks or plugins) got corrupted? You could try cleaning and reinstalling rocks.nvim and/or the affected plugins.

OK, I've managed to narrow it down to luasnip. The error doesn't happen when I install it with rocks-git, so there's something smelly with the rocks package, I suppose...

Maybe the bug was fixed but not released yet?

kflak commented 4 months ago

@kflak I just tried with you config too, and couldn't reproduce it either. Maybe somehow your installations (rocks or plugins) got corrupted? You could try cleaning and reinstalling rocks.nvim and/or the affected plugins.

OK, I've managed to narrow it down to luasnip. The error doesn't happen when I install it with rocks-git, so there's something smelly with the rocks package, I suppose...

Maybe the bug was fixed but not released yet?

Kind of doubt it, there hasn't been a commit there since 14 April, and I didn't have this problem before now...

mrcjkb commented 4 months ago

Kind of doubt it, there hasn't been a commit there since 14 April, and I didn't have this problem before now...

I'm seeing commits on April 16, 21 and 30.

boydkelly commented 4 months ago

Just an update here. I made a basic install with only:

[rocks]

# List of Neovim plugins to install alongside their versions.
# If the plugin name contains a dot then you must add quotes to the key name!
[plugins]
"rocks.nvim" = "2.29.0"
"rocks-git.nvim" = "1.5.1"
"rocks-treesitter.nvim" = "scm"
tree-sitter-vimdoc = "scm"
tree-sitter-lua = "scm"
"oil.nvim" = "2.9.0"

https://gitlab.com/boydkelly/nvim-nb.git

I still get the following error starting neovim if my cwd is plugin:

Error detected while processing /var/home/bkelly/.config/nvim-nb/plugin/oil.lua:
E5113: Error while calling lua chunk: ./oil.lua:1: loop or previous error loading module 'oil'
stack traceback:
        [C]: in function 'require'
        ./oil.lua:1: in main chunk
        [C]: in function 'require'
        /var/home/bkelly/.config/nvim-nb/plugin/oil.lua:1: in main chunk

I get this same error in both an Arch and Fedora container, as well as on a Fedora workstation. Albeit both the Arch and Fedora containers are toolboxes and share the same bash profile etc. However I don't see anything in PATH or environment that could affect this. The Fedora container contains a bunch of development stuff, but the Arch install is only the base container image + neovim.

boydkelly commented 2 months ago

ok I think at least in my case I can see the issue. It appears to me to be a problem with lua5.4 and/or the way its configured in Fedora.

bkelly@toolbox:~  $ luarocks path
export LUA_PATH='/usr/share/lua/5.4/?.lua;/usr/local/share/lua/5.4/?.lua;/usr/local/share/lua/5.4/?/init.lua;/usr/share/lua/5.4/?/init.lua;/usr/local/lib/lua/5.4/?.lua;/usr/local/lib/lua/5.4/?/init.lua;/usr/lib/lua/5.4/?.lua;/usr/lib/lua/5.4/?/init.lua;./?.lua;./?/init.lua;/var/home/bkelly/.luarocks/share/lua/5.4/?.lua;/var/home/bkelly/.luarocks/share/lua/5.4/?/init.lua'
export LUA_CPATH='/usr/local/lib/lua/5.4/?.so;/usr/lib/lua/5.4/?.so;/usr/local/lib/lua/5.4/loadall.so;/usr/lib/lua/5.4/loadall.so;./?.so;/var/home/bkelly/.luarocks/lib/lua/5.4/?.so'

I think this may explain why its trying to process the lua files in the cwd: ;./?.lua;./?/i

What led me to this was that recently i could no longer run Rocks update (sync would work). In the logs when attempting an updateI get a lot of --force-lock errors and in effect if I run luarocks on the command line i get:

bkelly@toolbox:~  $ luarocks --force-lock
Usage: luarocks [-h] [--version] [--dev] [--server <server>]
       [--only-server <server>] [--only-sources <url>]
       [--namespace <namespace>] [--lua-dir <prefix>]
       [--lua-version <ver>] [--tree <tree>] [--local] [--global]
       [--no-project] [--verbose] [--timeout <seconds>] [<command>]
       ...

Error: unknown option '--force-lock'

bkelly@toolbox:~  $ lua -v
Lua 5.4.6  Copyright (C) 1994-2023 Lua.org, PUC-Rio
bkelly@toolbox:~  $ luarocks --version
/usr/bin/luarocks 3.9.2
LuaRocks main command-line interface

Notable as well that I was getting the same issues with Arch, and both Arch (oci container) and Fedora are using lua 5.4 by default. There is a lua-compat 5.1 package in Fedora and I installed that but no luck there. Just installing an F38 container to test that... But is there also a config file where I can 'reset' the LUA_PATH?
(Even F36 is using lua 5.4)

boydkelly commented 2 months ago

Maybe this should go elsewhere but it seems to be related. I am using git to manage my dotfiles. So I have this alias to config that points to git. alias config='/usr/bin/git --git-dir=$HOME/.cfg/ --work-tree=$HOME I also used a plugin called baredot.nvim that takes this into account so i can use neogit etc withing nvim to manager that. Its not by any means a necessity, but I found that it interfered with Rocks update. But even with that removed, i have not noticed at least 3 times that Rocks update has somehow deleted all my dotofiles. In the log there were two messages i noted. One something to the effect that /home/bkelly/ worktree already exists, and also some message about symlinks not possible. Since I closed nvim I lost those messages. I just ran Rocks update now, and there is no log produced, but a config (git) status shows all my dotfiles deleted:

bkelly@toolbox:~  $ config status
On branch main
Changes not staged for commit:
  (use "git add/rm <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
    deleted:    .bash/themes/aphrodite/aphrodite.theme.sh
    deleted:    .bashrc.d/aliases.sh
    deleted:    .bashrc.d/anki.sh
    deleted:    .bashrc.d/env.sh
    deleted:    .bashrc.d/fzf.sh
    deleted:    .bashrc.d/nims.sh
    deleted:    .bashrc.d/npm.sh
    deleted:    .bashrc.d/path.sh
    deleted:    .bashrc.d/prompt.sh

Not a huge problem. I can do a config (git) restore .config and get them back. But why is Rocks even looking at my home directory worktree? Is this the same 'LUA_PATH" issue and I was in ~ when I ran the command?

Addendum: Got one of the messages doing Rocks sync:

    6   ERROR | 2024-07-24 10:52:49 | ...m-rocks/rocks/rocks_rtp/lua/rocks/operations/helpers.lua:93 | Failed to install nvim-cmp      
    5   ERROR | 2024-07-24 10:52:49 | ...nvim-rocks/rocks/rocks_rtp/lua/rocks/operations/sync.lua:47 | SYNC ERROR: Failed to install n»
    4   ERROR | 2024-07-24 10:52:56 | .../share/nvim-rocks/rocks/rocks_rtp/lua/rocks/luarocks.lua:65 | luarocks CLI FAILED             
    3   ERROR | 2024-07-24 10:52:56 | .../share/nvim-rocks/rocks/rocks_rtp/lua/rocks/luarocks.lua:66 | Warning: Failed searching manif»
    2   fatal: working tree '/var/home/bkelly' already exists.                                                                         
    1                                                                                                                                  
   14   Error: Failed cloning git repository. 

But this time my .config files are intact.

mrcjkb commented 2 months ago

/usr/bin/luarocks 3.9.2

The --force-lock error is because luarocks 3.9.2 doesn't support that flag. rocks.nvim requires luarocks >= 3.11 (3.11.1 recommended, because 3.11.0 has a bug preventing you from being able to reinstall or update dev rocks).

rocks.nvim has luarocks >= 3.11.1 as a dependency, so you should be able to use luarocks 3.9 to bootstrap it. But you need to make sure vim.g.rocks_nvim.luarocks_binary is not set if you want rocks.nvim to use the bundled luarocks install. Perhaps doing this is enough to solve your issue, since it won't be using the Fedora bundle? :thinking:

The LUA_PATH and LUA_CPATH variables could indeed be causing problems. You can check this by running :lua =package.path and :lua =package.cpath, which are the paths that rocks.nvim passes on to luarocks when invoking the luarocks CLI. Newer versions of rocks.nvim also pass a LUAROCKS_CONFIG, which may have previously been causing problems if set globally.