Skip to content

Document explicit custom plugin requires when order matters #2038

Description

@TyceHerrman

the new vim.pack config has the convenience loader:

-- require 'custom.plugins'

I think there should also be something about explicit ordering for custom plugin modules where setup order matters:

require 'custom.plugins.colorscheme'
require 'custom.plugins.ui'
require 'custom.plugins.git'

Current code

lua/custom/plugins/init.lua currently auto-loads every Lua file in lua/custom/plugins/:

local plugins_dir = vim.fs.joinpath(vim.fn.stdpath 'config', 'lua', 'custom', 'plugins')
for file_name, type in vim.fs.dir(plugins_dir) do
  if type == 'file' and file_name:match '%.lua$' and file_name ~= 'init.lua' then
    local module = file_name:gsub('%.lua$', '')
    require('custom.plugins.' .. module)
  end
end

for independent modules - great. however, since vim.pack plugin files are imperative Lua and may call vim.pack.add, define commands/keymaps, or immediately run setup(), load order can matter.

Suggested change

Update the init.lua to add short blurb about load ordering in vim.pack world:

  -- NOTE: You can add your own plugins, configuration, etc from `lua/custom/plugins/*.lua`
  --
  -- For independent modules, uncomment this convenience loader:
  -- require 'custom.plugins'
  --
  -- If you have a custom module that depends on another plugin or module being set up first,
  -- require modules explicitly in the order they should run:
  --
  -- require 'custom.plugins.colorscheme'
  -- require 'custom.plugins.ui'
  -- require 'custom.plugins.git'

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions