packer.nvim
packer.nvim copied to clipboard
Some plugin names break packer_compiled.lua
nvimv0.7.2packer90b323bccc04ad9b23c971a85813a1405c7725a8
Using a plugin name that is a reserved word in lua breaks the packer_compiled.lua file.
use { 'tpope/vim-repeat', as = 'repeat' }
[packer.nvim] [ERROR 18:10:09] async.lua:20: Error in coroutine: ...ox/config/nvim/pack/sys/start/packer.nvim/lua/packer.lua:725: Vim(source):E5112: Error while creating lua chunk: ...e/dir/src/sandbox/config/nvim/plugin/packer_compiled.lua:217: unexpected symbol near 'repeat'
This appears to be due to using the builtin vim.inspect as a means to stringify a table as lua code, however its output is not guaranteed to be deserializable as valid lua code.
https://github.com/wbthomason/packer.nvim/blob/3a9f9801f683946b9f1047d8f4bf9946c29e927d/lua/packer/compile.lua#L178
vim.inspect({ ['if'] = true })
-- {
-- if = true
-- }
The following patch works around the issue by manually escaping the plugin names in the output object, but it's rather brittle, and still relies on vim.inspect for the plugin configs:
-- Crude `vim.inspect` replacement that unconditionnaly escapes plugin names to avoid invalid keys such as lua keywords
-- Assumes the plugin objects are properly serialized by vim.inspect
local out = '{\n'
for k, v in pairs(result) do
-- indent:
local objstr = table.concat(vim.split(vim.inspect(v), '\n'), '\n ')
local objkeystr = ' [' .. string.format('%q', k) .. '] = ' .. objstr .. ',\n'
out = out .. objkeystr
end
out = out .. '}'
return out