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

View File

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

View File

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