diff --git a/plugins/by-name/copilot-cmp/default.nix b/plugins/by-name/copilot-cmp/default.nix new file mode 100644 index 00000000..4ddc0472 --- /dev/null +++ b/plugins/by-name/copilot-cmp/default.nix @@ -0,0 +1,74 @@ +{ lib, config, ... }: +let + inherit (lib) types; + inherit (lib.nixvim) defaultNullOpts; +in +lib.nixvim.neovim-plugin.mkNeovimPlugin { + name = "copilot-cmp"; + moduleName = "copilot_cmp"; + + imports = [ + { cmpSourcePlugins.copilot = "copilot-cmp"; } + ]; + + maintainers = [ lib.maintainers.GaetanLepage ]; + + # TODO introduced 2024-12-19: remove after 25.05 + deprecateExtraOptions = true; + optionsRenamedToSettings = [ + "event" + "fixPairs" + ]; + + settingsOptions = { + event = + defaultNullOpts.mkListOf types.str + [ + "InsertEnter" + "LspAttach" + ] + '' + Configures when the source is registered. + + Unless you have a unique problem for your particular configuration you probably don't want to + touch this. + ''; + + fix_pairs = defaultNullOpts.mkBool true '' + Suppose you have the following code: `print('h')`. + Copilot might try to account for the `'` and `)` and complete it with this: `print('hello`. + + This is not good behavior for consistency reasons and will just end up deleting the two ending + characters. + This option fixes that. + Don't turn this off unless you are having problems with pairs and believe this might be + causing them. + ''; + }; + + settingsExample = { + event = [ + "InsertEnter" + "LspAttach" + ]; + fix_pairs = false; + }; + + extraConfig = { + warnings = + let + copilot-lua-cfg = config.plugins.copilot-lua; + isEnabled = b: (lib.isBool b && b); + in + lib.optional (isEnabled copilot-lua-cfg.suggestion.enabled) '' + It is recommended to disable copilot's `suggestion` module, as it can interfere with + completions properly appearing in copilot-cmp. + '' + ++ lib.optional (isEnabled copilot-lua-cfg.panel.enabled) '' + It is recommended to disable copilot's `panel` module, as it can interfere with completions + properly appearing in copilot-cmp. + ''; + + plugins.copilot-lua.enable = lib.mkDefault true; + }; +} diff --git a/plugins/cmp/sources/copilot-cmp.nix b/plugins/cmp/sources/copilot-cmp.nix deleted file mode 100644 index 48e0895c..00000000 --- a/plugins/cmp/sources/copilot-cmp.nix +++ /dev/null @@ -1,67 +0,0 @@ -{ - lib, - config, - ... -}: -let - inherit (lib.nixvim) defaultNullOpts; - - copilot-lua-cfg = config.plugins.copilot-lua; - cfg = config.plugins.copilot-cmp; -in -{ - options.plugins.copilot-cmp = lib.nixvim.neovim-plugin.extraOptionsOptions // { - event = - defaultNullOpts.mkListOf lib.types.str - [ - "InsertEnter" - "LspAttach" - ] - '' - Configures when the source is registered. - Unless you have a unique problem for your particular configuration you probably don't want - to touch this. - ''; - - fixPairs = defaultNullOpts.mkBool true '' - Suppose you have the following code: `print('h')`. - Copilot might try to account for the `'` and `)` and complete it with this: `print('hello`. - - This is not good behavior for consistency reasons and will just end up deleting the two ending - characters. - This option fixes that. - Don't turn this off unless you are having problems with pairs and believe this might be - causing them. - ''; - }; - - config = lib.mkIf cfg.enable { - warnings = - lib.optional - ((!lib.isBool copilot-lua-cfg.suggestion.enabled) || copilot-lua-cfg.suggestion.enabled) - '' - It is recommended to disable copilot's `suggestion` module, as it can interfere with - completions properly appearing in copilot-cmp. - '' - ++ lib.optional ((!lib.isBool copilot-lua-cfg.panel.enabled) || copilot-lua-cfg.panel.enabled) '' - It is recommended to disable copilot's `panel` module, as it can interfere with completions - properly appearing in copilot-cmp. - ''; - - plugins.copilot-lua.enable = true; - - extraConfigLua = - let - setupOptions = - with cfg; - { - inherit event; - fix_pairs = fixPairs; - } - // cfg.extraOptions; - in - '' - require('copilot_cmp').setup(${lib.nixvim.toLuaObject setupOptions}) - ''; - }; -} diff --git a/plugins/cmp/sources/default.nix b/plugins/cmp/sources/default.nix index 9b9c3b3f..5281b94c 100644 --- a/plugins/cmp/sources/default.nix +++ b/plugins/cmp/sources/default.nix @@ -173,10 +173,6 @@ let pluginName = "cmp-zsh"; sourceName = "zsh"; } - { - pluginName = "copilot-cmp"; - sourceName = "copilot"; - } { pluginName = "crates-nvim"; sourceName = "crates"; @@ -189,7 +185,6 @@ in { # For extra cmp plugins imports = [ - ./copilot-cmp.nix ./crates-nvim.nix ] ++ pluginModules; } diff --git a/tests/test-sources/plugins/by-name/copilot-cmp/default.nix b/tests/test-sources/plugins/by-name/copilot-cmp/default.nix new file mode 100644 index 00000000..8be807f8 --- /dev/null +++ b/tests/test-sources/plugins/by-name/copilot-cmp/default.nix @@ -0,0 +1,11 @@ +{ + empty = { + plugins.copilot-cmp.enable = true; + }; + + defaults = { + plugins.copilot-cmp = { + enable = true; + }; + }; +} diff --git a/tests/test-sources/plugins/by-name/copilot-lua/default.nix b/tests/test-sources/plugins/by-name/copilot-lua/default.nix index 3b6f3123..7b3281f0 100644 --- a/tests/test-sources/plugins/by-name/copilot-lua/default.nix +++ b/tests/test-sources/plugins/by-name/copilot-lua/default.nix @@ -12,12 +12,12 @@ suggestion.enabled = false; }; - copilot-cmp = { + copilot-cmp.settings = { event = [ "InsertEnter" "LspAttach" ]; - fixPairs = true; + fix_pairs = true; }; cmp = {