nixvim
nixvim copied to clipboard
modules/keymaps: improve `lua` deprecation
Summary
- Take advantage of the module system in the keymap submodule
- Use
showDefsto better print the actual definitions and locations (e.g. improves how_type="override"is shown) - Removed
normalizeMapping(inlined intoaction'sapplyfunction) - Also show warning for
keymapsOnEvent
Testing
When adding the following test case:
{
keymaps = [
{
key = ",";
action = "function() print('lua true') end";
lua = true;
}
{
key = ".";
action = "function() print('lua false') end";
lua = false;
}
{
key = ".";
action = "function() print('lua mkDefault true') end";
lua = pkgs.lib.mkDefault true;
}
{
key = ".";
action.__raw = "function() print('raw lua') end";
}
];
}
The following warning is printed:
trace: warning: Nixvim (keymaps): the `lua` option is deprecated and will be removed in 24.11.
You should use a "raw" `action` instead:
e.g. `action.__raw = "<lua code>"` or `action = helpers.mkRaw "<lua code>"`.
Definitions:
- In `<unknown-file>': true
- In `<unknown-file>': false
- In `<unknown-file>': true
Note:
mkDefault truecorrectly prints astruethanks to usingshowDefsrather thantoPretty.- EDIT: This happens because overrides are resolved in the
luaDefssubmodule config not becauseshowDefsstrips them. So this is actually unintended behavior!
- EDIT: This happens because overrides are resolved in the
<unknown-file>is shown because I used a test case, this would normally be an actual file path.
Extra submodule option
To access options.lua.definitionsWithLocations from outside the submodule, I created a luaDefs option. This probably isn't the correct approach, but IDK how to correctly access the lua sub-option from outside a list of submodule.