From 2eaecf17a0b5abb0ea15196efe1dc45e5d49735f Mon Sep 17 00:00:00 2001 From: LeMarsu Date: Mon, 3 Jun 2024 03:18:44 +0200 Subject: [PATCH] fix: init function is called before plugin is loaded --- README.md | 25 +++++++++++-------------- lib/deps.nix | 1 + lib/mkNeovimPkg.nix | 5 +---- 3 files changed, 13 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index bafe3f5..98b03b6 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/lib/deps.nix b/lib/deps.nix index 4633c55..6b96ef3 100644 --- a/lib/deps.nix +++ b/lib/deps.nix @@ -49,6 +49,7 @@ hasCommands = p.cmd != []; hasFileTypes = p.ft != []; lazy = p.lazy || hasCommands || hasFileTypes; + optional = lazy || p.init != null; }; normalizeOrImportPlugin = dep: diff --git a/lib/mkNeovimPkg.nix b/lib/mkNeovimPkg.nix index ec50049..2e55ea3 100644 --- a/lib/mkNeovimPkg.nix +++ b/lib/mkNeovimPkg.nix @@ -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