Skip to content
This repository has been archived by the owner on Oct 24, 2023. It is now read-only.

'Loaded' function should be triggered before 'Config' function in plugin spec. #12

Open
koshell opened this issue Jun 14, 2023 · 0 comments

Comments

@koshell
Copy link

koshell commented Jun 14, 2023

{
  -- [string] Specifies the full name of the package.
  -- This is the only required field; all other fields are optional.
  "user/package",

  -- This should be triggered every time the package is loaded
  -- [function] Code to run after the package is loaded into neovim.
  function()
    require "package".setup(...)
  end,

  -- This should be triggered after install or update 
  -- AFTER the loaded function is triggered
  -- [function] Code to run after the package is installed or updated.
  config = function()
    os.execute(...)
  end,
}

Currently to the best of my ability to tell it appears that config() is ran as soon as the plugin is updated, as in as soon as the new git is pulled or similar. Instead it should be called once the plugin is actually loaded.

As an example my mason spec currently looks like this:

return {
	"williamboman/mason.nvim",
	function()
		require("mason").setup()
	end,
	config = function()
		require("mason").setup()
		vim.cmd("MasonUpdate")
	end,
}

Because the config function is being executed before the 'loaded' function I need to manually load the plugin twice, once if it updates, then a second time for when it would normally be loaded.

This does appear to function fine (although running a plugins setup function twice could possible cause issues with other plugins that I haven't tried) but I feel like this is a much nicer pattern:

return {
	"williamboman/mason.nvim",
	function()
		require("mason").setup()
	end,
	config = function()
		vim.cmd("MasonUpdate")
	end,
}
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant