diff --git a/plugins/completion/codeium-vim.nix b/plugins/completion/codeium-vim.nix index fa170b7e..f2716543 100644 --- a/plugins/completion/codeium-vim.nix +++ b/plugins/completion/codeium-vim.nix @@ -5,174 +5,153 @@ pkgs, ... }: -with lib; let - cfg = config.plugins.codeium-vim; -in { - meta.maintainers = [maintainers.GaetanLepage]; +with lib; + helpers.vim-plugin.mkVimPlugin config { + name = "codeium-vim"; + originalName = "codeium.vim"; + defaultPackage = pkgs.vimPlugins.codeium-vim; + globalPrefix = "codeium_"; - options.plugins.codeium-vim = { - enable = mkEnableOption "codeium.vim"; + maintainers = [maintainers.GaetanLepage]; - 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 { - type = with types; nullOr str; - default = "${pkgs.codeium}/bin/codeium_language_server"; - description = "The path to the codeium language server executable."; - }; + settingsOptions = { + bin = mkOption { + type = with types; nullOr str; + default = "${pkgs.codeium}/bin/codeium_language_server"; + description = "The path to the codeium language server executable."; + }; - keymaps = { - clear = helpers.defaultNullOpts.mkStr "" '' - Keymap for clearing current suggestion. - Command: `codeium#Clear()` - ''; - - next = helpers.defaultNullOpts.mkStr "" '' - Keymap for cycling to the next suggestion. - Command: `codeium#CycleCompletions(1)` - ''; - - prev = helpers.defaultNullOpts.mkStr "" '' - Keymap for cycling to the previous suggestion. - Command: `codeium#CycleCompletions(-1)` - ''; - - accept = helpers.defaultNullOpts.mkStr "" '' - Keymap for inserting the proposed suggestion. - Command: `codeium#Accept()` - ''; - - complete = helpers.defaultNullOpts.mkStr "" '' - 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 `` 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: "\" 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; + filetypes = + helpers.defaultNullOpts.mkAttrsOf types.bool + '' { - enabled = true; - inherit - filetypes - manual - bin - ; - no_map_tab = noMapTab; - idle_delay = idleDelay; - inherit render; - tab_fallback = tabFallback; - disable_bindings = disableBindings; + help = false; + gitcommit = false; + gitrebase = false; + "." = false; } - // 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; - helpers.keymaps.mkKeymaps - { - mode = "i"; - options = { - silent = true; - expr = true; - }; - } - ( - flatten - [ - (optional - (clear != null) - { - key = clear; - action = "call codeium#Clear()"; - }) - (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()"; - }) - ] - ); - }; -} + manual = helpers.defaultNullOpts.mkBool false '' + If true, codeium completions will never automatically trigger. + ''; + + no_map_tab = helpers.defaultNullOpts.mkBool false '' + Whether to disable the `` 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: "\" when a popup menu is visible, else "\t". + ''; + + disable_bindings = helpers.defaultNullOpts.mkBool false '' + Whether to disable default keybindings. + ''; + }; + + extraOptions = { + keymaps = { + clear = helpers.defaultNullOpts.mkStr "" '' + Keymap for clearing current suggestion. + Command: `codeium#Clear()` + ''; + + next = helpers.defaultNullOpts.mkStr "" '' + Keymap for cycling to the next suggestion. + Command: `codeium#CycleCompletions(1)` + ''; + + prev = helpers.defaultNullOpts.mkStr "" '' + Keymap for cycling to the previous suggestion. + Command: `codeium#CycleCompletions(-1)` + ''; + + accept = helpers.defaultNullOpts.mkStr "" '' + Keymap for inserting the proposed suggestion. + Command: `codeium#Accept()` + ''; + + complete = helpers.defaultNullOpts.mkStr "" '' + 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 = "call codeium#Clear()"; + }) + (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()"; + }) + ] + ); + }; + } diff --git a/tests/test-sources/plugins/completion/codeium-vim.nix b/tests/test-sources/plugins/completion/codeium-vim.nix index ebd151a6..5da19e03 100644 --- a/tests/test-sources/plugins/completion/codeium-vim.nix +++ b/tests/test-sources/plugins/completion/codeium-vim.nix @@ -14,18 +14,21 @@ accept = ""; complete = ""; }; - filetypes = { - help = false; - gitcommit = false; - gitrebase = false; - "." = false; + + settings = { + filetypes = { + help = 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; }; }; }