nixvim icon indicating copy to clipboard operation
nixvim copied to clipboard

modules/keymaps: improve `lua` deprecation

Open MattSturgeon opened this issue 1 year ago • 0 comments

Summary

  • Take advantage of the module system in the keymap submodule
  • Use showDefs to better print the actual definitions and locations (e.g. improves how _type="override" is shown)
  • Removed normalizeMapping (inlined into action's apply function)
  • 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 true correctly prints as true thanks to using showDefs rather than toPretty.
    • EDIT: This happens because overrides are resolved in the luaDefs submodule config not because showDefs strips them. So this is actually unintended behavior!
  • <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.

MattSturgeon avatar Jul 02 '24 03:07 MattSturgeon