From a635b5689484279ab552ad211ce318d6d0f7614b Mon Sep 17 00:00:00 2001 From: Matt Sturgeon Date: Fri, 21 Nov 2025 09:01:15 +0000 Subject: [PATCH] plugins/barbar: add nullOr workaround for keymaps lua warning Currently, `types.either` has support for the new valueMeta attribute added by v2 check and merge, while `types.nullOr` does not. The `lua` option deprecation warning implemented in `modules/keymaps.nix` requires `valueMeta`, so re-implement `nullOr` using `types.either` as a workaround. --- modules/keymaps.nix | 1 - plugins/by-name/barbar/default.nix | 36 +++++++++++++++++++------- tests/test-sources/modules/keymaps.nix | 3 +-- 3 files changed, 28 insertions(+), 12 deletions(-) diff --git a/modules/keymaps.nix b/modules/keymaps.nix index 38b73f08..785f1bfe 100644 --- a/modules/keymaps.nix +++ b/modules/keymaps.nix @@ -69,7 +69,6 @@ in options.plugins.tmux-navigator.keymaps.valueMeta.list # NOTE: barbar added `mapOptionSubmodule` support shortly _before_ branching off 24.05 - # FIXME: types.nullOr doesn't propagate valueMeta as it doesn't implement v2 check+merge (lib.mapAttrsToList (name: opt: opt.valueMeta) ( builtins.removeAttrs options.plugins.barbar.keymaps [ "silent" ] )) diff --git a/plugins/by-name/barbar/default.nix b/plugins/by-name/barbar/default.nix index b8fc285d..1985f30b 100644 --- a/plugins/by-name/barbar/default.nix +++ b/plugins/by-name/barbar/default.nix @@ -5,7 +5,6 @@ let defaultNullOpts keymaps mkNullOrOption - mkNullOrOption' mkNullOrStr ; keymapsActions = { @@ -45,6 +44,22 @@ let orderByLanguage = "OrderByLanguage"; orderByWindowNumber = "OrderByWindowNumber"; }; + + # As of 2025-11-21, `either` supports `valueMeta`, while `nullOr` does not. + # The `lua` deprecation warning in `modules/keymaps.nix` requires `valueMeta`, + # so re-implement `nullOr` using `types.either` as a workaround. + # + # TODO: Remove with the warning, or once `nullOr` supports v2 check and merge. + v2NullOr = + type: + let + v1 = lib.types.nullOr type; + v2 = lib.types.either (lib.types.enum [ null ]) type; + in + v2 + // { + inherit (v1) description descriptionClass getSubOptions; + }; in lib.nixvim.plugins.mkNeovimPlugin { name = "barbar"; @@ -56,14 +71,17 @@ lib.nixvim.plugins.mkNeovimPlugin { extraOptions = { keymaps = mapAttrs ( optionName: funcName: - mkNullOrOption' { - type = keymaps.mkMapOptionSubmodule { - defaults = { - mode = "n"; - action = "Buffer${funcName}"; - }; - lua = true; - }; + lib.mkOption { + type = v2NullOr ( + keymaps.mkMapOptionSubmodule { + defaults = { + mode = "n"; + action = "Buffer${funcName}"; + }; + lua = true; + } + ); + default = null; apply = v: if v == null then null else keymaps.removeDeprecatedMapAttrs v; description = "Keymap for function Buffer${funcName}"; } diff --git a/tests/test-sources/modules/keymaps.nix b/tests/test-sources/modules/keymaps.nix index 05891d77..23bec4c6 100644 --- a/tests/test-sources/modules/keymaps.nix +++ b/tests/test-sources/modules/keymaps.nix @@ -141,8 +141,7 @@ (expect "any" "- `keymapsOnEvents.InsertEnter.\"[definition 1-entry 1]\".lua' is defined in `test-module'") (expect "any" "- `plugins.lsp.keymaps.extra.\"[definition 1-entry 1]\".lua' is defined in `test-module'") (expect "any" "- `plugins.tmux-navigator.keymaps.\"[definition 1-entry 1]\".lua' is defined in `test-module'") - # FIXME: nullOr breaks our warning - # (expect "any" "- `plugins.barbar.keymaps.first.lua' is defined in `test-module'") + (expect "any" "- `plugins.barbar.keymaps.first.lua' is defined in `test-module'") ]; test.runNvim = false;