fix: init function is called before plugin is loaded

main
LeMarsu 2024-06-03 03:18:44 +02:00
parent 3732144c33
commit 2eaecf17a0
3 changed files with 13 additions and 18 deletions

View File

@ -157,29 +157,26 @@ The dependencies is a list of element of either:
The Plugin configuration object accepts the following properties:
| name | default | description |
|----------------|---------|-----------------------------------------------------------------|
| `plugin` | N/A | The plugin to load² **REQUIRED** |
| `init` | `null` | Lua code (as string of path) to call before loading the plugin³ |
| `config` | `null` | Lua code (as string of path) to call after loading the plugin |
| `dependencies` | `[]` | The plugin dependencies |
| `lazy` | `false` | Should the plugin be loaded lazily |
| `cmd` | `[]` | Command to put as place_holder to lazy load the plugin |
| `ft` | `[]` | Filetype to watch to lazy load the plugin |
| name | default | description |
|----------------|---------|----------------------------------------------------------------|
| `plugin` | N/A | The plugin to load² **REQUIRED** |
| `init` | `null` | Lua code (as string of path) to call before loading the plugin |
| `config` | `null` | Lua code (as string of path) to call after loading the plugin |
| `dependencies` | `[]` | The plugin dependencies³ |
| `lazy` | `false` | Should the plugin be loaded lazily |
| `cmd` | `[]` | Command to put as place_holder to lazy load the plugin |
| `ft` | `[]` | Filetype to watch to lazy load the plugin |
> ² The plugin can be either a nix package or an object with only `name` and
> `src` as properties. The latter will be used to create a nix package of your
> plugin on the fly.
> ³ When the plugin is not lazy, the `init` function is called after the plugin
> is loaded as all non lazy plugin are loaded automatically.
> ⁴ `nix` handles the installation of your plugin, therefore, this list is
> ³ `nix` handles the installation of your plugin, therefore, this list is
> **NOT** to declare dependencies that the nix package of the plugin doesn't
> know. This will tell `sloth-flake` in what order your plugins should be
> loaded.
> Setting this property implicitly set `lazy` to `true`.
> Setting this property implicitly set `lazy` to `true`.
### neovim (lua)

View File

@ -49,6 +49,7 @@
hasCommands = p.cmd != [];
hasFileTypes = p.ft != [];
lazy = p.lazy || hasCommands || hasFileTypes;
optional = lazy || p.init != null;
};
normalizeOrImportPlugin = dep:

View File

@ -31,10 +31,7 @@
normalizedPlugins
++ (deps.normalizePlugins [runtimePlugin sloth-flake]);
extractPlugin = p: {
inherit (p) plugin;
optional = p.lazy;
};
extractPlugin = p: {inherit (p) optional plugin;};
extractPlugins = map extractPlugin;
customRC = let