Skip to content

Commit

Permalink
plugins/copilot-cmp: move to by-name, migrate to mkNeovimPlugin
Browse files Browse the repository at this point in the history
  • Loading branch information
GaetanLepage committed Dec 18, 2024
1 parent 7aed1c4 commit 5d6e83d
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 74 deletions.
74 changes: 74 additions & 0 deletions plugins/by-name/copilot-cmp/default.nix
Original file line number Diff line number Diff line change
@@ -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;
};
}
67 changes: 0 additions & 67 deletions plugins/cmp/sources/copilot-cmp.nix

This file was deleted.

5 changes: 0 additions & 5 deletions plugins/cmp/sources/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,6 @@ let
pluginName = "cmp-zsh";
sourceName = "zsh";
}
{
pluginName = "copilot-cmp";
sourceName = "copilot";
}
{
pluginName = "crates-nvim";
sourceName = "crates";
Expand All @@ -189,7 +185,6 @@ in
{
# For extra cmp plugins
imports = [
./copilot-cmp.nix
./crates-nvim.nix
] ++ pluginModules;
}
11 changes: 11 additions & 0 deletions tests/test-sources/plugins/by-name/copilot-cmp/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
empty = {
plugins.copilot-cmp.enable = true;
};

defaults = {
plugins.copilot-cmp = {
enable = true;
};
};
}
4 changes: 2 additions & 2 deletions tests/test-sources/plugins/by-name/copilot-lua/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
suggestion.enabled = false;
};

copilot-cmp = {
copilot-cmp.settings = {
event = [
"InsertEnter"
"LspAttach"
];
fixPairs = true;
fix_pairs = true;
};

cmp = {
Expand Down

0 comments on commit 5d6e83d

Please sign in to comment.