packer.nvim icon indicating copy to clipboard operation
packer.nvim copied to clipboard

Running PackerCompile loads another instance of event lazy-loaded plugins if events are fired again.

Open Pranav-Badrinathan opened this issue 4 years ago • 1 comments

  • nvim --version: v0.6.0
  • git --version: 2.31.1.windows.1
  • Operating system/version: Windows 11
  • Terminal name/version: Windows Terminal

Steps to reproduce

This happened with cmp-path and cmp-cmdline, both of which were loading on the CmdlineEnter event. To reproduce my exact case:

  1. Install nvim-cmp and cmp-cmdline and set cmp-cmdline to load on CmdlineEnter.
  2. Open any file and start typing the :colorscheme command on the command line. You should only see one suggestion: image
  3. Run :PackerCompile or :PackerSync.
  4. Retry typing :colorscheme and you should see not one, but 2 suggestions:
    image
  5. Repeating step 3 and step 4 should increase results by 1 each time.

Actual behaviour

The command :PackerCompile seems to mess with event loaded plugins, and loads another new instance each time that event fires after compiling.

Expected behaviour

It should remember the active events and not launch another instance again, or just reload all plugins on compile, stopping the previous instance beforehand.

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 It seems that the log file I have is not the most recent and displays some errors that were due to configuring stuff previously. Anyways, if you still need it: https://pastebin.com/218vfDxE

packer compiled file

Post the contents of packer_compiled.lua here

-- Automatically generated packer.nvim plugin loader code

if vim.api.nvim_call_function('has', {'nvim-0.5'}) ~= 1 then
  vim.api.nvim_command('echohl WarningMsg | echom "Invalid Neovim version for packer.nvim! | echohl None"')
  return
end

vim.api.nvim_command('packadd packer.nvim')

local no_errors, error_msg = pcall(function()

  local time
  local profile_info
  local should_profile = false
  if should_profile then
    local hrtime = vim.loop.hrtime
    profile_info = {}
    time = function(chunk, start)
      if start then
        profile_info[chunk] = hrtime()
      else
        profile_info[chunk] = (hrtime() - profile_info[chunk]) / 1e6
      end
    end
  else
    time = function(chunk, start) end
  end
  
local function save_profiles(threshold)
  local sorted_times = {}
  for chunk_name, time_taken in pairs(profile_info) do
    sorted_times[#sorted_times + 1] = {chunk_name, time_taken}
  end
  table.sort(sorted_times, function(a, b) return a[2] > b[2] end)
  local results = {}
  for i, elem in ipairs(sorted_times) do
    if not threshold or threshold and elem[2] > threshold then
      results[i] = elem[1] .. ' took ' .. elem[2] .. 'ms'
    end
  end

  _G._packer = _G._packer or {}
  _G._packer.profile_output = results
end

time([[Luarocks path setup]], true)
local package_path_str = "C:\\Users\\PRANA~1.LAP\\AppData\\Local\\Temp\\nvim\\packer_hererocks\\2.1.0-beta3\\share\\lua\\5.1\\?.lua;C:\\Users\\PRANA~1.LAP\\AppData\\Local\\Temp\\nvim\\packer_hererocks\\2.1.0-beta3\\share\\lua\\5.1\\?\\init.lua;C:\\Users\\PRANA~1.LAP\\AppData\\Local\\Temp\\nvim\\packer_hererocks\\2.1.0-beta3\\lib\\luarocks\\rocks-5.1\\?.lua;C:\\Users\\PRANA~1.LAP\\AppData\\Local\\Temp\\nvim\\packer_hererocks\\2.1.0-beta3\\lib\\luarocks\\rocks-5.1\\?\\init.lua"
local install_cpath_pattern = "C:\\Users\\PRANA~1.LAP\\AppData\\Local\\Temp\\nvim\\packer_hererocks\\2.1.0-beta3\\lib\\lua\\5.1\\?.so"
if not string.find(package.path, package_path_str, 1, true) then
  package.path = package.path .. ';' .. package_path_str
end

if not string.find(package.cpath, install_cpath_pattern, 1, true) then
  package.cpath = package.cpath .. ';' .. install_cpath_pattern
end

time([[Luarocks path setup]], false)
time([[try_loadstring definition]], true)
local function try_loadstring(s, component, name)
  local success, result = pcall(loadstring(s), name, _G.packer_plugins[name])
  if not success then
    vim.schedule(function()
      vim.api.nvim_notify('packer.nvim: Error running ' .. component .. ' for ' .. name .. ': ' .. result, vim.log.levels.ERROR, {})
    end)
  end
  return result
end

time([[try_loadstring definition]], false)
time([[Defining packer_plugins]], true)
_G.packer_plugins = {
  LuaSnip = {
    load_after = {
      cmp_luasnip = true
    },
    loaded = false,
    needs_bufread = true,
    path = "C:\\Users\\prana.LAPTOP-MODAKBGP\\AppData\\Local\\nvim-data\\site\\pack\\packer\\opt\\LuaSnip",
    url = "https://github.com/L3MON4D3/LuaSnip"
  },
  ["ayu-vim"] = {
    loaded = false,
    needs_bufread = false,
    path = "C:\\Users\\prana.LAPTOP-MODAKBGP\\AppData\\Local\\nvim-data\\site\\pack\\packer\\opt\\ayu-vim",
    url = "https://github.com/ayu-theme/ayu-vim"
  },
  ["cmp-buffer"] = {
    after_files = { "C:\\Users\\prana.LAPTOP-MODAKBGP\\AppData\\Local\\nvim-data\\site\\pack\\packer\\opt\\cmp-buffer\\after\\plugin\\cmp_buffer.lua" },
    load_after = {},
    loaded = true,
    needs_bufread = false,
    path = "C:\\Users\\prana.LAPTOP-MODAKBGP\\AppData\\Local\\nvim-data\\site\\pack\\packer\\opt\\cmp-buffer",
    url = "https://github.com/hrsh7th/cmp-buffer"
  },
  ["cmp-cmdline"] = {
    after_files = { "C:\\Users\\prana.LAPTOP-MODAKBGP\\AppData\\Local\\nvim-data\\site\\pack\\packer\\opt\\cmp-cmdline\\after\\plugin\\cmp_cmdline.lua" },
    load_after = {},
    loaded = false,
    needs_bufread = false,
    only_cond = false,
    path = "C:\\Users\\prana.LAPTOP-MODAKBGP\\AppData\\Local\\nvim-data\\site\\pack\\packer\\opt\\cmp-cmdline",
    url = "https://github.com/hrsh7th/cmp-cmdline"
  },
  ["cmp-nvim-lsp"] = {
    loaded = true,
    path = "C:\\Users\\prana.LAPTOP-MODAKBGP\\AppData\\Local\\nvim-data\\site\\pack\\packer\\start\\cmp-nvim-lsp",
    url = "https://github.com/hrsh7th/cmp-nvim-lsp"
  },
  ["cmp-path"] = {
    after_files = { "C:\\Users\\prana.LAPTOP-MODAKBGP\\AppData\\Local\\nvim-data\\site\\pack\\packer\\opt\\cmp-path\\after\\plugin\\cmp_path.lua" },
    load_after = {},
    loaded = false,
    needs_bufread = false,
    only_cond = false,
    path = "C:\\Users\\prana.LAPTOP-MODAKBGP\\AppData\\Local\\nvim-data\\site\\pack\\packer\\opt\\cmp-path",
    url = "https://github.com/hrsh7th/cmp-path"
  },
  cmp_luasnip = {
    after = { "LuaSnip" },
    after_files = { "C:\\Users\\prana.LAPTOP-MODAKBGP\\AppData\\Local\\nvim-data\\site\\pack\\packer\\opt\\cmp_luasnip\\after\\plugin\\cmp_luasnip.lua" },
    loaded = false,
    needs_bufread = false,
    only_cond = false,
    path = "C:\\Users\\prana.LAPTOP-MODAKBGP\\AppData\\Local\\nvim-data\\site\\pack\\packer\\opt\\cmp_luasnip",
    url = "https://github.com/saadparwaiz1/cmp_luasnip"
  },
  ["feline.nvim"] = {
    loaded = true,
    path = "C:\\Users\\prana.LAPTOP-MODAKBGP\\AppData\\Local\\nvim-data\\site\\pack\\packer\\start\\feline.nvim",
    url = "https://github.com/feline-nvim/feline.nvim"
  },
  ["friendly-snippets"] = {
    loaded = false,
    needs_bufread = false,
    only_cond = false,
    path = "C:\\Users\\prana.LAPTOP-MODAKBGP\\AppData\\Local\\nvim-data\\site\\pack\\packer\\opt\\friendly-snippets",
    url = "https://github.com/rafamadriz/friendly-snippets"
  },
  ["gitsigns.nvim"] = {
    loaded = true,
    path = "C:\\Users\\prana.LAPTOP-MODAKBGP\\AppData\\Local\\nvim-data\\site\\pack\\packer\\start\\gitsigns.nvim",
    url = "https://github.com/lewis6991/gitsigns.nvim"
  },
  gruvbox = {
    loaded = false,
    needs_bufread = false,
    path = "C:\\Users\\prana.LAPTOP-MODAKBGP\\AppData\\Local\\nvim-data\\site\\pack\\packer\\opt\\gruvbox",
    url = "https://github.com/morhetz/gruvbox"
  },
  ["nest.nvim"] = {
    loaded = true,
    path = "C:\\Users\\prana.LAPTOP-MODAKBGP\\AppData\\Local\\nvim-data\\site\\pack\\packer\\start\\nest.nvim",
    url = "https://github.com/LionC/nest.nvim"
  },
  ["nvim-autopairs"] = {
    loaded = true,
    path = "C:\\Users\\prana.LAPTOP-MODAKBGP\\AppData\\Local\\nvim-data\\site\\pack\\packer\\start\\nvim-autopairs",
    url = "https://github.com/windwp/nvim-autopairs"
  },
  ["nvim-cmp"] = {
    after = { "cmp-cmdline", "cmp-buffer", "cmp-path" },
    loaded = true,
    only_config = true
  },
  ["nvim-comment"] = {
    loaded = true,
    path = "C:\\Users\\prana.LAPTOP-MODAKBGP\\AppData\\Local\\nvim-data\\site\\pack\\packer\\start\\nvim-comment",
    url = "https://github.com/terrortylor/nvim-comment"
  },
  ["nvim-lspconfig"] = {
    loaded = true,
    path = "C:\\Users\\prana.LAPTOP-MODAKBGP\\AppData\\Local\\nvim-data\\site\\pack\\packer\\start\\nvim-lspconfig",
    url = "https://github.com/neovim/nvim-lspconfig"
  },
  ["nvim-treesitter"] = {
    loaded = true,
    path = "C:\\Users\\prana.LAPTOP-MODAKBGP\\AppData\\Local\\nvim-data\\site\\pack\\packer\\start\\nvim-treesitter",
    url = "https://github.com/nvim-treesitter/nvim-treesitter"
  },
  ["nvim-web-devicons"] = {
    loaded = false,
    needs_bufread = false,
    path = "C:\\Users\\prana.LAPTOP-MODAKBGP\\AppData\\Local\\nvim-data\\site\\pack\\packer\\opt\\nvim-web-devicons",
    url = "https://github.com/kyazdani42/nvim-web-devicons"
  },
  ["packer.nvim"] = {
    loaded = true,
    path = "C:\\Users\\prana.LAPTOP-MODAKBGP\\AppData\\Local\\nvim-data\\site\\pack\\packer\\start\\packer.nvim",
    url = "https://github.com/wbthomason/packer.nvim"
  },
  ["palenight.vim"] = {
    loaded = true,
    path = "C:\\Users\\prana.LAPTOP-MODAKBGP\\AppData\\Local\\nvim-data\\site\\pack\\packer\\start\\palenight.vim",
    url = "https://github.com/drewtempelmeyer/palenight.vim"
  },
  ["plenary.nvim"] = {
    loaded = true,
    path = "C:\\Users\\prana.LAPTOP-MODAKBGP\\AppData\\Local\\nvim-data\\site\\pack\\packer\\start\\plenary.nvim",
    url = "https://github.com/nvim-lua/plenary.nvim"
  },
  sonokai = {
    loaded = true,
    path = "C:\\Users\\prana.LAPTOP-MODAKBGP\\AppData\\Local\\nvim-data\\site\\pack\\packer\\start\\sonokai",
    url = "https://github.com/sainnhe/sonokai"
  },
  ["telescope-fzf-native.nvim"] = {
    loaded = true,
    path = "C:\\Users\\prana.LAPTOP-MODAKBGP\\AppData\\Local\\nvim-data\\site\\pack\\packer\\start\\telescope-fzf-native.nvim",
    url = "https://github.com/nvim-telescope/telescope-fzf-native.nvim"
  },
  ["telescope.nvim"] = {
    loaded = true,
    path = "C:\\Users\\prana.LAPTOP-MODAKBGP\\AppData\\Local\\nvim-data\\site\\pack\\packer\\start\\telescope.nvim",
    url = "https://github.com/nvim-telescope/telescope.nvim"
  },
  ["vim-endwise"] = {
    loaded = true,
    path = "C:\\Users\\prana.LAPTOP-MODAKBGP\\AppData\\Local\\nvim-data\\site\\pack\\packer\\start\\vim-endwise",
    url = "https://github.com/tpope/vim-endwise"
  },
  ["vim-matchup"] = {
    loaded = true,
    path = "C:\\Users\\prana.LAPTOP-MODAKBGP\\AppData\\Local\\nvim-data\\site\\pack\\packer\\start\\vim-matchup",
    url = "https://github.com/andymass/vim-matchup"
  }
}

time([[Defining packer_plugins]], false)
-- Config for: nvim-cmp
time([[Config for nvim-cmp]], true)
try_loadstring("\27LJ\2\n*\0\0\3\0\2\0\0046\0\0\0'\2\1\0B\0\2\1K\0\1\0\15cmp_config\frequire\0", "config", "nvim-cmp")
time([[Config for nvim-cmp]], false)
-- Load plugins in order defined by `after`
time([[Sequenced loading]], true)
vim.cmd [[ packadd cmp-buffer ]]
time([[Sequenced loading]], false)
vim.cmd [[augroup packer_load_aucmds]]
vim.cmd [[au!]]
  -- Event lazy-loads
time([[Defining lazy-load event autocommands]], true)
vim.cmd [[au InsertCharPre * ++once lua require("packer.load")({'friendly-snippets', 'cmp_luasnip'}, { event = "InsertCharPre *" }, _G.packer_plugins)]]
vim.cmd [[au CmdlineEnter * ++once lua require("packer.load")({'cmp-cmdline', 'cmp-path'}, { event = "CmdlineEnter *" }, _G.packer_plugins)]]
time([[Defining lazy-load event autocommands]], false)
vim.cmd("augroup END")
if should_profile then save_profiles() end

end)

if not no_errors then
  vim.api.nvim_command('echohl ErrorMsg | echom "Error in packer_compiled: '..error_msg..'" | echom "Please check your config for correctness" | echohl None')
end

Pranav-Badrinathan avatar Dec 27 '21 18:12 Pranav-Badrinathan

Can confirm this, most noticeable with nvim-cmp sometimes I got 3 line of the same completion

kuntau avatar Dec 28 '21 03:12 kuntau