wbthomason / packer.nvim

A use-package inspired plugin manager for Neovim. Uses native packages, supports Luarocks dependencies, written in Lua, allows for expressive config
MIT License
7.9k stars 263 forks source link

Error installing nvim-treesitter-textobjects due to plugin_utils.post_update_hook #776

Open mjlbach opened 2 years ago

mjlbach commented 2 years ago

I dug into this a bit but ran out of time before solving it. It's been bothering me for awhile (as this is the only plugin that "fails" installing (although in reality it works fine).

Steps to reproduce

local on_windows = vim.loop.os_uname().version:match 'Windows'

local function join_paths(...)
  local path_sep = on_windows and '\\' or '/'
  local result = table.concat({ ... }, path_sep)
  return result
end

vim.cmd [[set runtimepath=$VIMRUNTIME]]

local temp_dir = vim.loop.os_getenv 'TEMP' or '/tmp'

vim.cmd('set packpath=' .. join_paths(temp_dir, 'nvim', 'site'))

local package_root = join_paths(temp_dir, 'nvim', 'site', 'pack')
local install_path = join_paths(package_root, 'packer', 'start', 'packer.nvim')
local compile_path = join_paths(install_path, 'plugin', 'packer_compiled.lua')

if vim.fn.isdirectory(install_path) == 0 then
  vim.fn.system { 'git', 'clone', 'https://github.com/wbthomason/packer.nvim', install_path }
end

local use = require('packer').use
require('packer').startup({function()
  use 'wbthomason/packer.nvim' -- Package manager
  use 'nvim-treesitter/nvim-treesitter-textobjects'
  use 'nvim-treesitter/nvim-treesitter'
end,
  config = {
    package_root = package_root,
    compile_path = compile_path,
  },
})

call :PackerInstall

Actual behaviour

[packer.nvim] [ERROR 21:41:15] async.lua:20: Error in coroutine: ...ack/packer/start/packer.nvim/lua/packer/plugin_utils.lua:20
4: Vim(lua):E5108: Error executing lua ...eesitter-textobjects/lua/nvim-treesitter-textobjects.lua:1: module 'nvim-treesitter.q
uery' not found:
[packer.nvim] ^Ino field package.preload['nvim-treesitter.query']
[packer.nvim] ^Ino file './nvim-treesitter/query.lua'
[packer.nvim] ^Ino file '/home/michael/Repositories/neovim_development/neovim-worktree/neovim/.deps/usr/share/luajit-2.1.0-beta
3/nvim-treesitter/query.lua'
[packer.nvim] ^Ino file '/usr/local/share/lua/5.1/nvim-treesitter/query.lua'
[packer.nvim] ^Ino file '/usr/local/share/lua/5.1/nvim-treesitter/query/init.lua'
[packer.nvim] ^Ino file '/home/michael/Repositories/neovim_development/neovim-worktree/neovim/.deps/usr/share/lua/5.1/nvim-tree
sitter/query.lua'
[packer.nvim] ^Ino file '/usr/local/share/lua/5.1/nvim-treesitter/query/init.lua'
[packer.nvim] ^Ino file '/home/michael/Repositories/neovim_development/neovim-worktree/neovim/.deps/usr/share/lua/5.1/nvim-tree
sitter/query.lua'
[packer.nvim] ^Ino file '/home/michael/Repositories/neovim_development/neovim-worktree/neovim/.deps/usr/share/lua/5.1/nvim-tree
sitter/query/init.lua'
[packer.nvim] ^Ino file '/home/michael/.cache/nvim/packer_hererocks/2.1.0-beta3/share/lua/5.1/nvim-treesitter/query.lua'
[packer.nvim] ^Ino file '/home/michael/.cache/nvim/packer_hererocks/2.1.0-beta3/share/lua/5.1/nvim-treesitter/query/init.lua'
[packer.nvim] ^Ino file '/home/michael/.cache/nvim/packer_hererocks/2.1.0-beta3/lib/luarocks/rocks-5.1/nvim-treesitter/query.lu
a'
[packer.nvim] ^Ino file '/home/michael/.cache/nvim/packer_hererocks/2.1.0-beta3/lib/luarocks/rocks-5.1/nvim-treesitter/query/in
it.lua'
[packer.nvim] ^Ino file './nvim-treesitter/query.so'
[packer.nvim] ^Ino file '/usr/local/lib/lua/5.1/nvim-treesitter/query.so'
[packer.nvim] ^Ino file '/home/michael/Repositories/neovim_development/neovim-worktree/neovim/.deps/usr/lib/lua/5.1/nvim-treesi
tter/query.so'
[packer.nvim] ^Ino file '/usr/local/lib/lua/5.1/loadall.so'
[packer.nvim] ^Ino file '/home/michael/.cache/nvim/packer_hererocks/2.1.0-beta3/lib/lua/5.1/nvim-treesitter/query.so'
[packer.nvim] ^Ino file './nvim-treesitter.so'
[packer.nvim] ^Ino file '/usr/local/lib/lua/5.1/nvim-treesitter.so'
[packer.nvim] ^Ino file '/home/michael/Repositories/neovim_development/neovim-worktree/neovim/.deps/usr/lib/lua/5.1/nvim-treesi
tter.so'
[packer.nvim] ^Ino file '/usr/local/lib/lua/5.1/loadall.so'
[packer.nvim] ^Ino file '/home/michael/.cache/nvim/packer_hererocks/2.1.0-beta3/lib/lua/5.1/nvim-treesitter.so'
[packer.nvim] stack traceback:
[packer.nvim] ^I[C]: in function 'require'
[packer.nvim] ^I...eesitter-textobjects/lua/nvim-treesitter-textobjects.lua:1: in main chunk
[packer.nvim] ^I[C]: in function 'require'
[packer.nvim] ^I[string ":lua"]:1: in main chunk
[packer.nvim] ^I[C]: in function 'resume'
[packer.nvim] ^I.../site/pack/packer/start/packer.nvim/lua/packer/async.lua:12: in function <.../site/pack/packer/start/packer.
nvim/lua/packer/async.lua:11>

Expected behaviour

nvim-treesitter-textobjects installs without error

packer files

Plugin specification file(s) Post or link your plugin specification files here, if you aren't able to provide a minimal reproducer
packer log file Post the contents of ~/.cache/nvim/packer.nvim.log here
[ERROR Sat 15 Jan 2022 09:51:27 PM PST 1.7614831807791e+14] .../site/pack/packer/start/packer.nvim/lua/packer/async.lua:20: Error in coroutine: ...ack/packer/start/packer.nvim/lua/packer/plugin_utils.lua:204: Vim(lua):E5108: Error executing lua ...eesitter-textobjects/lua/nvim-treesitter-textobjects.lua:1: module 'nvim-treesitter.query' not found:
    no field package.preload['nvim-treesitter.query']
    no file './nvim-treesitter/query.lua'
    no file '/home/michael/Repositories/neovim_development/neovim-worktree/neovim/.deps/usr/share/luajit-2.1.0-beta3/nvim-treesitter/query.lua'
    no file '/usr/local/share/lua/5.1/nvim-treesitter/query.lua'
    no file '/usr/local/share/lua/5.1/nvim-treesitter/query/init.lua'
    no file '/home/michael/Repositories/neovim_development/neovim-worktree/neovim/.deps/usr/share/lua/5.1/nvim-treesitter/query.lua'
    no file '/home/michael/Repositories/neovim_development/neovim-worktree/neovim/.deps/usr/share/lua/5.1/nvim-treesitter/query/init.lua'
    no file '/home/michael/.cache/nvim/packer_hererocks/2.1.0-beta3/share/lua/5.1/nvim-treesitter/query.lua'
    no file '/home/michael/.cache/nvim/packer_hererocks/2.1.0-beta3/share/lua/5.1/nvim-treesitter/query/init.lua'
    no file '/home/michael/.cache/nvim/packer_hererocks/2.1.0-beta3/lib/luarocks/rocks-5.1/nvim-treesitter/query.lua'
    no file '/home/michael/.cache/nvim/packer_hererocks/2.1.0-beta3/lib/luarocks/rocks-5.1/nvim-treesitter/query/init.lua'
    no file './nvim-treesitter/query.so'
    no file '/usr/local/lib/lua/5.1/nvim-treesitter/query.so'
    no file '/home/michael/Repositories/neovim_development/neovim-worktree/neovim/.deps/usr/lib/lua/5.1/nvim-treesitter/query.so'
    no file '/usr/local/lib/lua/5.1/loadall.so'
    no file '/home/michael/.cache/nvim/packer_hererocks/2.1.0-beta3/lib/lua/5.1/nvim-treesitter/query.so'
    no file './nvim-treesitter.so'
    no file '/usr/local/lib/lua/5.1/nvim-treesitter.so'
    no file '/home/michael/Repositories/neovim_development/neovim-worktree/neovim/.deps/usr/lib/lua/5.1/nvim-treesitter.so'
    no file '/usr/local/lib/lua/5.1/loadall.so'
    no file '/home/michael/.cache/nvim/packer_hererocks/2.1.0-beta3/lib/lua/5.1/nvim-treesitter.so'
stack traceback:
    [C]: in function 'require'
    ...eesitter-textobjects/lua/nvim-treesitter-textobjects.lua:1: in main chunk
    [C]: in function 'require'
    [string ":lua"]:1: in main chunk
    [C]: in function 'resume'
    .../site/pack/packer/start/packer.nvim/lua/packer/async.lua:12: in function <.../site/pack/packer/start/packer.nvim/lua/packer/async.lua:11>
wbthomason commented 2 years ago

Thanks for the report! I wonder if this is related to a bug I saw recently wherein even start plugins had to be packadded before they could be required (or Neovim had to be restarted). I don't recall that being the case previously, so I should check if something changed upstream. Regardless, I think a fix should be to packadd in the install logic.

wbthomason commented 2 years ago

Ah, nevermind. I know what causes this.

We explicitly source files for start plugins after installation, but this is interacting in a weird way with how Neovim refreshes its package.path, causing the module to not be found. The fix is still the same, I believe.

wbthomason commented 2 years ago

As discussed in #786, my guess was wrong. I now think this has to do with install order. If we ensure that nvim-treesitter is installed first, then nvim-treesitter-textobjects installs just fine. The problem is that nvim-treesitter-textobjects tends to finish downloading first, and packer currently does not constrain dependencies to be loaded for the first time before plugins that depend on them.

This is a clearer fix (in that it's an issue with packer and not upstream), but a more involved fix. We'll need to add logic for ordering post-install loads/hooks.

mjlbach commented 2 years ago

Yeah, I had initially assumed that "requires" were loaded before the requirer, but I see now that does not seem to be the case.

wbthomason commented 2 years ago

It should be, though.

wbthomason commented 2 years ago

I don't have time to fix this today, but it's on my radar now.

mjlbach commented 2 years ago

No worries :) Thanks for looking into it!

MarkoSagadin commented 2 years ago

Hello, sorry for bumping this issue, however, I am facing the same issue. Is there now a way to bypass this behaviour, or to atleast get some human readable warning that nvim-treesitter will work as expected once neovim is restarted?