1
0
Fork 0
mirror of https://github.com/nix-community/nixvim.git synced 2025-11-25 19:51:06 +01:00

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.
This commit is contained in:
Matt Sturgeon 2025-11-21 09:01:15 +00:00
parent d0b0b75a13
commit a635b56894
3 changed files with 28 additions and 12 deletions

View file

@ -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" ]
))

View file

@ -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 {
lib.mkOption {
type = v2NullOr (
keymaps.mkMapOptionSubmodule {
defaults = {
mode = "n";
action = "<Cmd>Buffer${funcName}<CR>";
};
lua = true;
};
}
);
default = null;
apply = v: if v == null then null else keymaps.removeDeprecatedMapAttrs v;
description = "Keymap for function Buffer${funcName}";
}

View file

@ -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;