mirror of
https://github.com/nix-community/nixvim.git
synced 2025-06-21 08:35:43 +02:00
plugins/codeium-vim: refactor keymaps implementation
This commit is contained in:
parent
5fba5be696
commit
a29a6d8f92
1 changed files with 60 additions and 66 deletions
|
@ -5,7 +5,35 @@
|
||||||
pkgs,
|
pkgs,
|
||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
with lib;
|
with lib; let
|
||||||
|
keymapsDefinitions = {
|
||||||
|
clear = {
|
||||||
|
default = "<C-]>";
|
||||||
|
description = "Keymap for clearing current suggestion.";
|
||||||
|
command = "codeium#Clear()";
|
||||||
|
};
|
||||||
|
next = {
|
||||||
|
default = "<M-]>";
|
||||||
|
description = "Keymap for cycling to the next suggestion.";
|
||||||
|
command = "codeium#CycleCompletions(1)";
|
||||||
|
};
|
||||||
|
prev = {
|
||||||
|
default = "<M-[>";
|
||||||
|
description = "Keymap for cycling to the previous suggestion.";
|
||||||
|
command = "codeium#CycleCompletions(-1)";
|
||||||
|
};
|
||||||
|
accept = {
|
||||||
|
default = "<Tab>";
|
||||||
|
description = "Keymap for inserting the proposed suggestion.";
|
||||||
|
command = "codeium#Accept()";
|
||||||
|
};
|
||||||
|
complete = {
|
||||||
|
default = "<M-Bslash>";
|
||||||
|
description = "Keymap for manually triggering the suggestion.";
|
||||||
|
command = "codeium#Complete()";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
in
|
||||||
helpers.vim-plugin.mkVimPlugin config {
|
helpers.vim-plugin.mkVimPlugin config {
|
||||||
name = "codeium-vim";
|
name = "codeium-vim";
|
||||||
originalName = "codeium.vim";
|
originalName = "codeium.vim";
|
||||||
|
@ -78,80 +106,46 @@ with lib;
|
||||||
};
|
};
|
||||||
|
|
||||||
extraOptions = {
|
extraOptions = {
|
||||||
keymaps = {
|
keymaps =
|
||||||
clear = helpers.defaultNullOpts.mkStr "<C-]>" ''
|
mapAttrs
|
||||||
Keymap for clearing current suggestion.
|
(
|
||||||
Command: `codeium#Clear()`
|
optionName: v:
|
||||||
'';
|
helpers.defaultNullOpts.mkStr v.default ''
|
||||||
|
${v.description}
|
||||||
next = helpers.defaultNullOpts.mkStr "<M-]>" ''
|
Command: `${v.command}`
|
||||||
Keymap for cycling to the next suggestion.
|
''
|
||||||
Command: `codeium#CycleCompletions(1)`
|
)
|
||||||
'';
|
keymapsDefinitions;
|
||||||
|
|
||||||
prev = helpers.defaultNullOpts.mkStr "<M-[>" ''
|
|
||||||
Keymap for cycling to the previous suggestion.
|
|
||||||
Command: `codeium#CycleCompletions(-1)`
|
|
||||||
'';
|
|
||||||
|
|
||||||
accept = helpers.defaultNullOpts.mkStr "<Tab>" ''
|
|
||||||
Keymap for inserting the proposed suggestion.
|
|
||||||
Command: `codeium#Accept()`
|
|
||||||
'';
|
|
||||||
|
|
||||||
complete = helpers.defaultNullOpts.mkStr "<M-Bslash>" ''
|
|
||||||
Keymap for manually triggering the suggestion.
|
|
||||||
Command: `codeium#Complete()`
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
extraConfig = cfg: {
|
extraConfig = cfg: {
|
||||||
plugins.codeium-vim.settings.enabled = true;
|
plugins.codeium-vim.settings.enabled = true;
|
||||||
|
|
||||||
keymaps = with cfg.keymaps;
|
keymaps = let
|
||||||
helpers.keymaps.mkKeymaps
|
processKeymap = optionName: v:
|
||||||
{
|
optional
|
||||||
|
(v != null)
|
||||||
|
{
|
||||||
|
key = v;
|
||||||
|
action = let
|
||||||
|
inherit (keymapsDefinitions.${optionName}) command;
|
||||||
|
in "<Cmd>${command}<CR>";
|
||||||
|
};
|
||||||
|
|
||||||
|
keymapsList = flatten (
|
||||||
|
mapAttrsToList processKeymap cfg.keymaps
|
||||||
|
);
|
||||||
|
|
||||||
|
defaults = {
|
||||||
mode = "i";
|
mode = "i";
|
||||||
options = {
|
options = {
|
||||||
silent = true;
|
silent = true;
|
||||||
expr = true;
|
expr = true;
|
||||||
};
|
};
|
||||||
}
|
};
|
||||||
(
|
in
|
||||||
flatten
|
helpers.keymaps.mkKeymaps
|
||||||
[
|
defaults
|
||||||
(optional
|
keymapsList;
|
||||||
(clear != null)
|
|
||||||
{
|
|
||||||
key = clear;
|
|
||||||
action = "<Cmd>call codeium#Clear()<CR>";
|
|
||||||
})
|
|
||||||
(optional
|
|
||||||
(next != null)
|
|
||||||
{
|
|
||||||
key = next;
|
|
||||||
action = "codeium#CycleCompletions(1)";
|
|
||||||
})
|
|
||||||
(optional
|
|
||||||
(prev != null)
|
|
||||||
{
|
|
||||||
key = prev;
|
|
||||||
action = "codeium#CycleCompletions(-1)";
|
|
||||||
})
|
|
||||||
(optional
|
|
||||||
(accept != null)
|
|
||||||
{
|
|
||||||
key = accept;
|
|
||||||
action = "codeium#Accept()";
|
|
||||||
})
|
|
||||||
(optional
|
|
||||||
(complete != null)
|
|
||||||
{
|
|
||||||
key = complete;
|
|
||||||
action = "codeium#Complete()";
|
|
||||||
})
|
|
||||||
]
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue