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.72k stars 263 forks source link

Priority order for implicit, optional, sequencing #1183

Open bluebrown opened 1 year ago

bluebrown commented 1 year ago

Describe the feature

Hi, it is currently possible to enforce sequencing by using the after key. However, I think this is not very practical as it creates tight coupling between plugins and may prevent plugins to load if something in the after list is not present.

Oftentimes, a plugin may be able to run without a given other plugin. If the other plugin is found, it may perform extra config settings. For example, imagine in your config function you want to check if the user has telescope enabled, and if so, use that, otherwise some default. If telescope exists, then we want sequencing, but if not, then we don't care.

So I propose a priority key in the options. By default, it would be 0 for everything, meaning they can be installed in parallel. This would allow a plugin to increase its priority, ensuring it will be installed before any other plugin. It would also remove the explicit coupling.

require("packer").startup(function(use)
  use({ "wbthomason/packer.nvim", opt = true })

  -- use the priority key to ensure telescope is installed before
  -- any other plugin with default prio 0
  use({"nvim-telescope/telescope.nvim", priority = -1 })

  use({
    "myplug",
    config = function()
     -- setup some plugin
      local p = require("myplug") 
      p.setup()

      -- register the plugin with telescope, if its there
      local ok, ts = pcall(require("telescope"))
      if ok then ts.load_extension(p.as_telescope_extension()) end
     end,
  })
end)
duarm commented 1 year ago

can't the order of the use call be used instead of the priority value? No idea how packer implements compilation and how it invalidates the compiled code, so not sure how to implement this.