2.3 KiB
| sidebar_position |
|---|
| 7 |
🔥 Developers
To make it easier for users to install your plugin, you can include a package spec in your repo.
Best Practices
-
If your plugin needs
setup(), then create a simplelazy.luafile like this:return { "me/my-plugin", opts = {} } -
Plugins that are pure lua libraries should be lazy-loaded with
lazy = true.{ "nvim-lua/plenary.nvim", lazy = true } -
Only use
dependenciesif a plugin needs the dep to be installed AND loaded. Lua plugins/libraries are automatically loaded when they arerequire()d, so they don't need to be independencies.:::tip[GOOD]
{ "folke/todo-comments.nvim", opts = {} }, { "nvim-lua/plenary.nvim", lazy = true },:::
:::danger[BAD]
{ "folke/todo-comments.nvim", opts = {}, -- This will always load plenary as soon as todo-comments loads, -- even when todo-comments doesn't use it. dependencies = { "nvim-lua/plenary.nvim", lazy = true }, },:::
-
Inside a
buildfunction or*.luabuild file, usecoroutine.yield(status_msg)to show progress. -
Don't change the
cwdin your build function, since builds run in parallel and changing thecwdwill affect other builds.
Building
The spec build property can be one of the following:
fun(plugin: LazyPlugin): a function that builds the plugin.*.lua: a Lua file that builds the plugin (likebuild.lua)":Command": a Neovim command"rockspec": this will runluarocks makein the plugin's directory This is automatically set by therockspecpackage source.- any other string will be run as a shell command
- a
listof any of the above to run multiple build steps - if no
buildis specified, but abuild.luafile exists, that will be used instead.
Build functions and *.lua files run asynchronously in a coroutine.
Use coroutine.yield(status_msg) to show progress.
Yielding will also schedule the next coroutine.resume() to run in the next tick, so you can do long-running tasks without blocking Neovim.
:::tip
If you need to know the directory of your build lua file, you can use:
local dir = vim.fn.fnamemodify(debug.getinfo(1, "S").source:sub(2), ":p:h")
:::