mirror of
https://github.com/nix-community/nixvim.git
synced 2025-06-23 09:18:38 +02:00
plugins/which-key: deprecate v2 registrations
These have been replaced in v3 with a new spec. As we will soon migrate which-key to `settings` options, I've named the new option `settings.spec` so that we do not need to "rename" it again soon. This commit **does not** actually add a freeform settings option.
This commit is contained in:
parent
2415edc0cb
commit
2089eb407d
2 changed files with 96 additions and 40 deletions
|
@ -3,6 +3,7 @@
|
||||||
helpers,
|
helpers,
|
||||||
pkgs,
|
pkgs,
|
||||||
config,
|
config,
|
||||||
|
options,
|
||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
with lib;
|
with lib;
|
||||||
|
@ -14,11 +15,44 @@ with lib;
|
||||||
|
|
||||||
registrations = mkOption {
|
registrations = mkOption {
|
||||||
type = with types; attrsOf anything;
|
type = with types; attrsOf anything;
|
||||||
default = { };
|
description = ''
|
||||||
description = "Manually register the description of mappings.";
|
This option is deprecated, use `settings.spec` instead.
|
||||||
example = {
|
|
||||||
"<leader>p" = "Find git files with telescope";
|
Note: the keymap format has changed in v3 of which-key.
|
||||||
};
|
'';
|
||||||
|
visible = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
settings.spec = helpers.defaultNullOpts.mkListOf' {
|
||||||
|
type = with types; attrsOf anything;
|
||||||
|
pluginDefault = [ ];
|
||||||
|
description = ''
|
||||||
|
WhichKey automatically gets the descriptions of your keymaps from the desc attribute of the keymap.
|
||||||
|
So for most use-cases, you don't need to do anything else.
|
||||||
|
|
||||||
|
However, the mapping spec is still useful to configure group descriptions and mappings that don't really exist as a regular keymap.
|
||||||
|
|
||||||
|
Please refer to the plugin's [documentation](https://github.com/folke/which-key.nvim?tab=readme-ov-file#%EF%B8%8F-mappings).
|
||||||
|
'';
|
||||||
|
example = [
|
||||||
|
{
|
||||||
|
__unkeyed-1 = "<leader>w";
|
||||||
|
desc = "Window actions";
|
||||||
|
}
|
||||||
|
{
|
||||||
|
__unkeyed-1 = "<leader>b";
|
||||||
|
desc = "Buffer actions";
|
||||||
|
}
|
||||||
|
{
|
||||||
|
__unkeyed-1 = "<leader>p";
|
||||||
|
desc = "Find git files with telescope";
|
||||||
|
}
|
||||||
|
{
|
||||||
|
__unkeyed-1 = "<leader>p";
|
||||||
|
__unkeyed-2.__raw = "function() print('Optional action') end";
|
||||||
|
desc = "Print \"optional action\"";
|
||||||
|
}
|
||||||
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
plugins = {
|
plugins = {
|
||||||
|
@ -203,6 +237,7 @@ with lib;
|
||||||
config =
|
config =
|
||||||
let
|
let
|
||||||
cfg = config.plugins.which-key;
|
cfg = config.plugins.which-key;
|
||||||
|
opt = options.plugins.which-key;
|
||||||
setupOptions = {
|
setupOptions = {
|
||||||
plugins = {
|
plugins = {
|
||||||
inherit (cfg.plugins) marks registers spelling;
|
inherit (cfg.plugins) marks registers spelling;
|
||||||
|
@ -246,6 +281,7 @@ with lib;
|
||||||
inherit (cfg) hidden;
|
inherit (cfg) hidden;
|
||||||
show_help = cfg.showHelp;
|
show_help = cfg.showHelp;
|
||||||
show_keys = cfg.showKeys;
|
show_keys = cfg.showKeys;
|
||||||
|
inherit (cfg.settings) spec;
|
||||||
inherit (cfg) triggers;
|
inherit (cfg) triggers;
|
||||||
triggers_nowait = cfg.triggersNoWait;
|
triggers_nowait = cfg.triggersNoWait;
|
||||||
triggers_blacklist = cfg.triggersBlackList;
|
triggers_blacklist = cfg.triggersBlackList;
|
||||||
|
@ -255,11 +291,20 @@ with lib;
|
||||||
mkIf cfg.enable {
|
mkIf cfg.enable {
|
||||||
extraPlugins = [ cfg.package ];
|
extraPlugins = [ cfg.package ];
|
||||||
|
|
||||||
|
warnings = optional opt.registrations.isDefined ''
|
||||||
|
nixvim (plugins.which-key):
|
||||||
|
The option definition `plugins.which-key.registrations' in ${showFiles opt.registrations.files} has been deprecated in which-key v3; please remove it.
|
||||||
|
You should use `plugins.which-key.settings.spec' instead.
|
||||||
|
|
||||||
|
Note: the spec format has changed in which-key v3
|
||||||
|
See: https://github.com/folke/which-key.nvim?tab=readme-ov-file#%EF%B8%8F-mappings
|
||||||
|
'';
|
||||||
|
|
||||||
extraConfigLua =
|
extraConfigLua =
|
||||||
''
|
''
|
||||||
require("which-key").setup(${helpers.toLuaObject setupOptions})
|
require("which-key").setup(${helpers.toLuaObject setupOptions})
|
||||||
''
|
''
|
||||||
+ (optionalString (cfg.registrations != { }) ''
|
+ (optionalString (opt.registrations.isDefined && cfg.registrations != { }) ''
|
||||||
require("which-key").register(${helpers.toLuaObject cfg.registrations})
|
require("which-key").register(${helpers.toLuaObject cfg.registrations})
|
||||||
'');
|
'');
|
||||||
};
|
};
|
||||||
|
|
|
@ -8,46 +8,57 @@
|
||||||
enable = true;
|
enable = true;
|
||||||
|
|
||||||
# Testing for registrations
|
# Testing for registrations
|
||||||
registrations."f" = {
|
settings.spec =
|
||||||
prefix = "<leader>";
|
let
|
||||||
mode = [
|
mode = [
|
||||||
"n"
|
"n"
|
||||||
"v"
|
"v"
|
||||||
"i"
|
"i"
|
||||||
"t"
|
"t"
|
||||||
"c"
|
"c"
|
||||||
"x"
|
"x"
|
||||||
"s"
|
"s"
|
||||||
"o"
|
"o"
|
||||||
];
|
];
|
||||||
name = "Group Test";
|
in
|
||||||
f = "Label Test";
|
[
|
||||||
"1" = [
|
|
||||||
{
|
{
|
||||||
__raw = ''
|
__unkeyed-1 = "<leader>f";
|
||||||
|
group = "Group Test";
|
||||||
|
inherit mode;
|
||||||
|
}
|
||||||
|
{
|
||||||
|
__unkeyed-1 = "<leader>ff";
|
||||||
|
desc = "Label Test";
|
||||||
|
inherit mode;
|
||||||
|
}
|
||||||
|
{
|
||||||
|
__unkeyed-1 = "<leader>f1";
|
||||||
|
__unkeyed-2.__raw = ''
|
||||||
function()
|
function()
|
||||||
print("Raw Lua Code and List KeyMapping Test")
|
print("Raw Lua KeyMapping Test")
|
||||||
end
|
end
|
||||||
'';
|
'';
|
||||||
|
desc = "Raw Lua KeyMapping Test";
|
||||||
|
inherit mode;
|
||||||
|
}
|
||||||
|
{
|
||||||
|
__unkeyed-1 = "<leader>foo";
|
||||||
|
desc = "Label Test 2";
|
||||||
|
inherit mode;
|
||||||
|
}
|
||||||
|
{
|
||||||
|
__unkeyed-1 = "<leader>f<tab>";
|
||||||
|
group = "Group in Group Test";
|
||||||
|
inherit mode;
|
||||||
|
}
|
||||||
|
{
|
||||||
|
__unkeyed-1 = "<leader>f<tab>f";
|
||||||
|
__unkeyed-2 = "<cmd>echo 'Vim cmd KeyMapping Test'<cr>";
|
||||||
|
desc = "Vim cmd KeyMapping Test";
|
||||||
|
inherit mode;
|
||||||
}
|
}
|
||||||
"Raw Lua Code and List KeyMapping Test"
|
|
||||||
];
|
];
|
||||||
"oo" = "Label Test 2";
|
|
||||||
"<tab>" = {
|
|
||||||
name = "Group in Group Test";
|
|
||||||
f = [
|
|
||||||
{
|
|
||||||
__raw = ''
|
|
||||||
function()
|
|
||||||
vim.cmd("echo 'Raw Lua Code and List KeyMapping Test 2'")
|
|
||||||
end
|
|
||||||
'';
|
|
||||||
}
|
|
||||||
|
|
||||||
"Raw Lua Code and List KeyMapping Test 2"
|
|
||||||
];
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
plugins = {
|
plugins = {
|
||||||
marks = true;
|
marks = true;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue