plugins/codeium-vim: switch to mkVimPlugin

This commit is contained in:
Gaetan Lepage 2024-02-14 09:06:09 +01:00 committed by Gaétan Lepage
parent b8815f04a3
commit 5fba5be696
2 changed files with 157 additions and 175 deletions

View file

@ -5,174 +5,153 @@
pkgs, pkgs,
... ...
}: }:
with lib; let with lib;
cfg = config.plugins.codeium-vim; helpers.vim-plugin.mkVimPlugin config {
in { name = "codeium-vim";
meta.maintainers = [maintainers.GaetanLepage]; originalName = "codeium.vim";
defaultPackage = pkgs.vimPlugins.codeium-vim;
globalPrefix = "codeium_";
options.plugins.codeium-vim = { maintainers = [maintainers.GaetanLepage];
enable = mkEnableOption "codeium.vim";
package = helpers.mkPackageOption "codeium-vim" pkgs.vimPlugins.codeium-vim; # TODO introduced 2024-02-19: remove 2024-03-19
deprecateExtraConfig = true;
optionsRenamedToSettings = [
"bin"
"filetypes"
"manual"
"noMapTab"
"idleDelay"
"render"
"tabFallback"
"disableBindings"
];
bin = mkOption { settingsOptions = {
type = with types; nullOr str; bin = mkOption {
default = "${pkgs.codeium}/bin/codeium_language_server"; type = with types; nullOr str;
description = "The path to the codeium language server executable."; default = "${pkgs.codeium}/bin/codeium_language_server";
}; description = "The path to the codeium language server executable.";
};
keymaps = { filetypes =
clear = helpers.defaultNullOpts.mkStr "<C-]>" '' helpers.defaultNullOpts.mkAttrsOf types.bool
Keymap for clearing current suggestion. ''
Command: `codeium#Clear()`
'';
next = helpers.defaultNullOpts.mkStr "<M-]>" ''
Keymap for cycling to the next suggestion.
Command: `codeium#CycleCompletions(1)`
'';
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()`
'';
};
filetypes =
helpers.defaultNullOpts.mkAttrsOf types.bool
''
{
help = false;
gitcommit = false;
gitrebase = false;
"." = false;
}
''
''
A dictionary mapping whether codeium should be enabled or disabled in certain filetypes.
This can be used to opt out of completions for certain filetypes.
'';
manual = helpers.defaultNullOpts.mkBool false ''
If true, codeium completions will never automatically trigger.
'';
noMapTab = helpers.defaultNullOpts.mkBool false ''
Whether to disable the `<Tab>` keybinding.
'';
idleDelay = helpers.defaultNullOpts.mkPositiveInt 75 ''
Delay in milliseconds before autocompletions are shown (limited by language server to a
minimum of 75).
'';
render = helpers.defaultNullOpts.mkBool true ''
A global boolean flag that controls whether codeium renders are enabled or disabled.
'';
tabFallback = helpers.mkNullOrOption types.str ''
The fallback key when there is no suggestion display in `codeium#Accept()`.
Default: "\<C-N>" when a popup menu is visible, else "\t".
'';
disableBindings = helpers.defaultNullOpts.mkBool false ''
Whether to disable default keybindings.
'';
extraConfig = mkOption {
type = types.attrs;
default = {};
description = ''
The configuration options for codeium-vim without the 'codeium_' prefix.
Example: To set 'codeium_foobar' to 1, write
extraConfig = {
foobar = true;
};
'';
};
};
config = mkIf cfg.enable {
extraPlugins = [cfg.package];
# Add the typst compiler to nixvim packages
extraPackages = with pkgs; [typst];
globals =
mapAttrs'
(name: nameValuePair ("codeium_" + name))
(
with cfg;
{ {
enabled = true; help = false;
inherit gitcommit = false;
filetypes gitrebase = false;
manual "." = false;
bin
;
no_map_tab = noMapTab;
idle_delay = idleDelay;
inherit render;
tab_fallback = tabFallback;
disable_bindings = disableBindings;
} }
// extraConfig ''
); ''
A dictionary mapping whether codeium should be enabled or disabled in certain filetypes.
This can be used to opt out of completions for certain filetypes.
'';
keymaps = with cfg.keymaps; manual = helpers.defaultNullOpts.mkBool false ''
helpers.keymaps.mkKeymaps If true, codeium completions will never automatically trigger.
{ '';
mode = "i";
options = { no_map_tab = helpers.defaultNullOpts.mkBool false ''
silent = true; Whether to disable the `<Tab>` keybinding.
expr = true; '';
};
} idle_delay = helpers.defaultNullOpts.mkPositiveInt 75 ''
( Delay in milliseconds before autocompletions are shown (limited by language server to a
flatten minimum of 75).
[ '';
(optional
(clear != null) render = helpers.defaultNullOpts.mkBool true ''
{ A global boolean flag that controls whether codeium renders are enabled or disabled.
key = clear; '';
action = "<Cmd>call codeium#Clear()<CR>";
}) tab_fallback = helpers.mkNullOrOption types.str ''
(optional The fallback key when there is no suggestion display in `codeium#Accept()`.
(next != null)
{ Default: "\<C-N>" when a popup menu is visible, else "\t".
key = next; '';
action = "codeium#CycleCompletions(1)";
}) disable_bindings = helpers.defaultNullOpts.mkBool false ''
(optional Whether to disable default keybindings.
(prev != null) '';
{ };
key = prev;
action = "codeium#CycleCompletions(-1)"; extraOptions = {
}) keymaps = {
(optional clear = helpers.defaultNullOpts.mkStr "<C-]>" ''
(accept != null) Keymap for clearing current suggestion.
{ Command: `codeium#Clear()`
key = accept; '';
action = "codeium#Accept()";
}) next = helpers.defaultNullOpts.mkStr "<M-]>" ''
(optional Keymap for cycling to the next suggestion.
(complete != null) Command: `codeium#CycleCompletions(1)`
{ '';
key = complete;
action = "codeium#Complete()"; 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: {
plugins.codeium-vim.settings.enabled = true;
keymaps = with cfg.keymaps;
helpers.keymaps.mkKeymaps
{
mode = "i";
options = {
silent = true;
expr = true;
};
}
(
flatten
[
(optional
(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()";
})
]
);
};
}

View file

@ -14,18 +14,21 @@
accept = "<Tab>"; accept = "<Tab>";
complete = "<M-Bslash>"; complete = "<M-Bslash>";
}; };
filetypes = {
help = false; settings = {
gitcommit = false; filetypes = {
gitrebase = false; help = false;
"." = false; gitcommit = false;
gitrebase = false;
"." = false;
};
manual = false;
no_map_tab = false;
idle_delay = 75;
render = true;
tab_fallback = "\t";
disable_bindings = true;
}; };
manual = false;
noMapTab = false;
idleDelay = 75;
render = true;
tabFallback = "\t";
disableBindings = true;
}; };
}; };
} }