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,22 +5,79 @@
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"
];
settingsOptions = {
bin = mkOption { bin = mkOption {
type = with types; nullOr str; type = with types; nullOr str;
default = "${pkgs.codeium}/bin/codeium_language_server"; default = "${pkgs.codeium}/bin/codeium_language_server";
description = "The path to the codeium language server executable."; description = "The path to the codeium language server executable.";
}; };
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.
'';
no_map_tab = helpers.defaultNullOpts.mkBool false ''
Whether to disable the `<Tab>` keybinding.
'';
idle_delay = 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.
'';
tab_fallback = 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".
'';
disable_bindings = helpers.defaultNullOpts.mkBool false ''
Whether to disable default keybindings.
'';
};
extraOptions = {
keymaps = { keymaps = {
clear = helpers.defaultNullOpts.mkStr "<C-]>" '' clear = helpers.defaultNullOpts.mkStr "<C-]>" ''
Keymap for clearing current suggestion. Keymap for clearing current suggestion.
@ -47,88 +104,10 @@ in {
Command: `codeium#Complete()` 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 { extraConfig = cfg: {
extraPlugins = [cfg.package]; plugins.codeium-vim.settings.enabled = true;
# Add the typst compiler to nixvim packages
extraPackages = with pkgs; [typst];
globals =
mapAttrs'
(name: nameValuePair ("codeium_" + name))
(
with cfg;
{
enabled = true;
inherit
filetypes
manual
bin
;
no_map_tab = noMapTab;
idle_delay = idleDelay;
inherit render;
tab_fallback = tabFallback;
disable_bindings = disableBindings;
}
// extraConfig
);
keymaps = with cfg.keymaps; keymaps = with cfg.keymaps;
helpers.keymaps.mkKeymaps helpers.keymaps.mkKeymaps
@ -175,4 +154,4 @@ in {
] ]
); );
}; };
} }

View file

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