mirror of
https://github.com/nix-community/nixvim.git
synced 2025-11-26 12:11:04 +01:00
The deprecation warning for the keymap-submocule `lua` option relied on `getSubOptions`, however this is fundamentally flawed because that function returns uses a different module eval from the one that merges submodule definitions. Since definitions are not used by `getSubOptions`, `options.lua.isDefined` will never be true. Instead, we have two choices: 1. Add a `luaIsDefined` option to the keymap submodule 2. Use the new v2 merge's `valueMeta` to access the actual module eval
150 lines
3.9 KiB
Nix
150 lines
3.9 KiB
Nix
{ lib, ... }:
|
|
{
|
|
example = {
|
|
keymaps = [
|
|
{
|
|
key = ",";
|
|
action = "<cmd>echo \"test\"<cr>";
|
|
}
|
|
{
|
|
mode = [
|
|
"n"
|
|
"s"
|
|
];
|
|
key = "<C-p>";
|
|
action = "<cmd>echo \"test\"<cr>";
|
|
}
|
|
];
|
|
};
|
|
|
|
mkKeymaps = {
|
|
keymaps =
|
|
lib.nixvim.keymaps.mkKeymaps
|
|
{
|
|
mode = "x";
|
|
options.silent = true;
|
|
}
|
|
[
|
|
{
|
|
mode = "n";
|
|
key = ",";
|
|
action = "<cmd>echo \"test\"<cr>";
|
|
}
|
|
{
|
|
# raw action using rawType
|
|
key = "<C-p>";
|
|
action.__raw = "function() print('hello') end";
|
|
}
|
|
{
|
|
key = "<C-a>";
|
|
action.__raw = "function() print('toto') end";
|
|
options.silent = false;
|
|
}
|
|
{
|
|
mode = [
|
|
"n"
|
|
"v"
|
|
];
|
|
key = "<C-z>";
|
|
action = "bar";
|
|
}
|
|
{
|
|
mode = "n";
|
|
key = "<C-h>";
|
|
action.__raw = "function() end";
|
|
options.replace_keycodes = false;
|
|
}
|
|
];
|
|
};
|
|
|
|
mkKeymapsOnEvents = {
|
|
keymapsOnEvents = {
|
|
"InsertEnter" =
|
|
lib.nixvim.keymaps.mkKeymaps
|
|
{
|
|
mode = "x";
|
|
options.silent = true;
|
|
}
|
|
[
|
|
{
|
|
mode = "n";
|
|
key = ",";
|
|
action = "<cmd>echo \"test\"<cr>";
|
|
}
|
|
{
|
|
# raw action using rawType
|
|
key = "<C-p>";
|
|
action.__raw = "function() print('hello') end";
|
|
}
|
|
{
|
|
key = "<C-a>";
|
|
action.__raw = "function() print('toto') end";
|
|
options.silent = false;
|
|
}
|
|
{
|
|
mode = [
|
|
"n"
|
|
"v"
|
|
];
|
|
key = "<C-z>";
|
|
action = "bar";
|
|
}
|
|
];
|
|
};
|
|
};
|
|
|
|
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;
|
|
};
|
|
}
|