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.75k stars 261 forks source link

If the location of a local plugin is a symlink, `PackerSync` generates an error #1048

Closed bryanforbes closed 1 year ago

bryanforbes commented 1 year ago

Steps to reproduce

Starting at 2b0af3b20f3ddf18ee2d5022dd80635dbc35eb1c, if the path given to a local plugin is a symlink, the following error occurs if PackerSync is run and the symlink in the packer directory exists:

[packer.nvim] [ERROR 18:15:15] async.lua:20: Error in coroutine: ...packer/opt/packer.nvim/lua/packer/plugin_types/local.lua:56: attempt to index a nil value

In my setup, I'm using fzf installed with Homebrew, so the main path is a symlink to the "cellar" binary:

  use({
    '/opt/homebrew/opt/fzf',
    cond = function()
      return vim.fn.executable('fzf') == 1
    end,
  })

/opt/homebrew/opt/fzf is a symlink pointing (currently) to /opt/homebrew/Cellar/fzf/0.33.0.

I added some print() statements after line 53 of local.lua:

      local resolved_path = vim.fn.resolve(to)
      print('From: ' .. from)
      print('To: ' .. to)
      print('Resolved: ' .. resolved_path)

And when the updater code is run, it gives the following output

From: /opt/homebrew/opt/fzf
To: /Users/bryan/.local/share/nvim/site/pack/packer/opt/fzf
Resolved: /opt/homebrew/Cellar/fzf/0.33.0

Actual behaviour

An error occurs if the symlink in the packer directory exists:

[packer.nvim] [ERROR 18:15:15] async.lua:20: Error in coroutine: ...packer/opt/packer.nvim/lua/packer/plugin_types/local.lua:56: attempt to index a nil value

Expected behaviour

If the symlink exists and points to the correct directory, nothing happens. If the symlink exists and points to the wrong directory, it is updated. If the symlink does not exist, it is created.

wbthomason commented 1 year ago

Ah, thanks for the report. I didn't consider the case that local plugins (which are handled by symlinking) might themselves be symlinks.