Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 33 additions & 23 deletions modules/keymaps.nix
Original file line number Diff line number Diff line change
Expand Up @@ -54,32 +54,42 @@ in
# TODO remove entirely in 25.05?
warnings =
let
# All keymap options that have historically supported the `lua` sub-option
keymapOptions = [
options.keymaps
options.keymapsOnEvents
# NOTE: lsp `diagnostic` and `lspBuf` don't use `mapOptionSubmodule` yet
# So we only need `lua` deprecation in lsp's `extra` option
options.plugins.lsp.keymaps.extra
# NOTE: tmux-navigator added `mapOptionSubmodule` support _after_ branching off 24.05
options.plugins.tmux-navigator.keymaps
]
# NOTE: barbar added `mapOptionSubmodule` support shortly _before_ branching off 24.05
++ builtins.attrValues (builtins.removeAttrs options.plugins.barbar.keymaps [ "silent" ]);
keymapsUsingLua =
lib.pipe
# All keymap options that have historically supported the `lua` sub-option
[
options.keymaps.valueMeta.list
(lib.concatMap (ev: ev.list) (lib.attrValues options.keymapsOnEvents.valueMeta.attrs))

# NOTE: lsp `diagnostic` and `lspBuf` don't use `mapOptionSubmodule` yet
# So we only need `lua` deprecation in lsp's `extra` option
options.plugins.lsp.keymaps.extra.valueMeta.list

# NOTE: tmux-navigator added `mapOptionSubmodule` support _after_ branching off 24.05
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" ]
))
]
[
lib.concatLists
(lib.filter (meta: meta.configuration.options.lua.isDefined or false))
(map (meta: meta.configuration.options))
];
in
lib.pipe keymapOptions [
(map (opt: (opt.type.getSubOptions opt.loc).lua))
(lib.filter (opt: opt.isDefined))
(map (opt: ''
${"\n"}
The `${lib.showOption opt.loc}' option is deprecated and will be removed in 24.11.
lib.optional (keymapsUsingLua != [ ]) ''
The `lua` keymap option is deprecated and will be removed in 26.05.

You should use a "raw" `action` instead;
e.g. `action.__raw = "<lua code>"` or `action = lib.nixvim.mkRaw "<lua code>"`.
You should use a "raw" `action` instead;
e.g. `action.__raw = "<lua code>"` or `action = lib.nixvim.mkRaw "<lua code>"`.

${lib.options.showDefs opt.definitionsWithLocations}
''))
];
${lib.concatMapStringsSep "\n" (
m: "- `${m.lua}' is defined in " + lib.options.showFiles m.lua.files
) keymapsUsingLua}
'';

extraConfigLua = lib.mkIf (config.keymaps != [ ]) ''
-- Set up keybinds {{{
Expand Down
55 changes: 55 additions & 0 deletions tests/test-sources/modules/keymaps.nix
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,59 @@
];
};
};

luaWarning = {
imports = [
(lib.modules.setDefaultModuleLocation "test-module" {
keymaps = [
{
lua = true;
key = "a";
action = "function() print('keymaps') end";
}
];
keymapsOnEvents.InsertEnter = [
{
lua = true;
key = "a";
action = "function() print('keymap on InsertEnter') end";
}
];
plugins.lsp.keymaps.extra = [
{
lua = true;
key = "a";
action = "function() print('plugins.lsp.keymaps.extra') end";
}
];
plugins.tmux-navigator.keymaps = [
{
lua = true;
key = "a";
action = "function() print('plugins.tmux-navigator.keymaps') end";
}
];
plugins.barbar.keymaps.first = {
lua = true;
key = "a";
action = "function() print('plugins.barbar.keymaps') end";
};
})
];

test.warnings = expect: [
(expect "count" 1)
(expect "any" "The `lua` keymap option is deprecated and will be removed")
(expect "any" "You should use a \"raw\" `action` instead;")
(expect "any" "e.g. `action.__raw = \"<lua code>\"` or `action = lib.nixvim.mkRaw \"<lua code>\"`.")
(expect "any" "- `keymaps.\"[definition 1-entry 1]\".lua' is defined in `test-module'")
(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'")
];

test.runNvim = false;
};
}