Skip to content

modules/keymaps: improve lua deprecation#1795

Closed
MattSturgeon wants to merge 1 commit intonix-community:mainfrom
MattSturgeon:keymap_lua
Closed

modules/keymaps: improve lua deprecation#1795
MattSturgeon wants to merge 1 commit intonix-community:mainfrom
MattSturgeon:keymap_lua

Conversation

@MattSturgeon
Copy link
Copy Markdown
Member

@MattSturgeon MattSturgeon commented Jul 2, 2024

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.

- 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`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant