mirror of
https://github.com/nix-community/nixvim.git
synced 2025-06-22 08:53:28 +02:00
plugins/copilot-lua: migrate to mkNeovimPlugin
This commit is contained in:
parent
a352bb89b0
commit
73303938ee
6 changed files with 322 additions and 228 deletions
|
@ -47,7 +47,7 @@ lib.nixvim.plugins.mkNeovimPlugin {
|
||||||
extraConfig = {
|
extraConfig = {
|
||||||
warnings =
|
warnings =
|
||||||
let
|
let
|
||||||
copilot-lua-cfg = config.plugins.copilot-lua;
|
copilot-lua-cfg = config.plugins.copilot-lua.settings;
|
||||||
isEnabled = b: builtins.isBool b && b;
|
isEnabled = b: builtins.isBool b && b;
|
||||||
in
|
in
|
||||||
lib.optionals (isEnabled copilot-lua-cfg.suggestion.enabled) [
|
lib.optionals (isEnabled copilot-lua-cfg.suggestion.enabled) [
|
||||||
|
|
|
@ -57,7 +57,7 @@ lib.nixvim.plugins.mkNeovimPlugin {
|
||||||
extraConfig = {
|
extraConfig = {
|
||||||
warnings =
|
warnings =
|
||||||
let
|
let
|
||||||
copilot-lua-cfg = config.plugins.copilot-lua;
|
copilot-lua-cfg = config.plugins.copilot-lua.settings;
|
||||||
isEnabled = b: (lib.isBool b && b);
|
isEnabled = b: (lib.isBool b && b);
|
||||||
in
|
in
|
||||||
lib.optional (isEnabled copilot-lua-cfg.suggestion.enabled) ''
|
lib.optional (isEnabled copilot-lua-cfg.suggestion.enabled) ''
|
||||||
|
|
|
@ -1,93 +1,78 @@
|
||||||
{
|
{
|
||||||
lib,
|
|
||||||
helpers,
|
|
||||||
config,
|
config,
|
||||||
|
lib,
|
||||||
pkgs,
|
pkgs,
|
||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
with lib;
|
|
||||||
let
|
let
|
||||||
cfg = config.plugins.copilot-lua;
|
inherit (lib) types;
|
||||||
|
inherit (lib.nixvim) defaultNullOpts;
|
||||||
in
|
in
|
||||||
{
|
lib.nixvim.plugins.mkNeovimPlugin {
|
||||||
options = {
|
name = "copilot-lua";
|
||||||
plugins.copilot-lua =
|
moduleName = "copilot";
|
||||||
|
packPathName = "copilot.lua";
|
||||||
|
|
||||||
|
maintainers = [ lib.maintainers.HeitorAugustoLN ];
|
||||||
|
|
||||||
|
settingsOptions =
|
||||||
let
|
let
|
||||||
keymapOption = helpers.defaultNullOpts.mkNullable (with types; either (enum [ false ]) str);
|
mkKeymapOption = defaultNullOpts.mkNullableWithRaw (with types; either (enum [ false ]) str);
|
||||||
in
|
in
|
||||||
lib.nixvim.plugins.neovim.extraOptionsOptions
|
{
|
||||||
// {
|
|
||||||
enable = mkEnableOption "copilot.lua";
|
|
||||||
|
|
||||||
package = lib.mkPackageOption pkgs "copilot.lua" {
|
|
||||||
default = [
|
|
||||||
"vimPlugins"
|
|
||||||
"copilot-lua"
|
|
||||||
];
|
|
||||||
};
|
|
||||||
|
|
||||||
panel = {
|
panel = {
|
||||||
enabled = helpers.defaultNullOpts.mkBool true "Enable the panel.";
|
enabled = defaultNullOpts.mkBool true "Enable the panel.";
|
||||||
|
auto_refresh = defaultNullOpts.mkBool false "Enable auto-refresh.";
|
||||||
autoRefresh = helpers.defaultNullOpts.mkBool false "Enable auto-refresh.";
|
|
||||||
|
|
||||||
keymap = {
|
keymap = {
|
||||||
jumpPrev = keymapOption "[[" "Keymap for jumping to the previous suggestion.";
|
jump_prev = mkKeymapOption "[[" "Keymap for jumping to the previous suggestion.";
|
||||||
|
jump_next = mkKeymapOption "]]" "Keymap for jumping to the next suggestion.";
|
||||||
jumpNext = keymapOption "]]" "Keymap for jumping to the next suggestion.";
|
accept = mkKeymapOption "<CR>" "Keymap to accept the proposed suggestion.";
|
||||||
|
refresh = mkKeymapOption "gr" "Keymap to refresh the suggestions.";
|
||||||
accept = keymapOption "<CR>" "Keymap to accept the proposed suggestion.";
|
open = mkKeymapOption "<M-CR>" "Keymap to open.";
|
||||||
|
|
||||||
refresh = keymapOption "gr" "Keymap to refresh the suggestions.";
|
|
||||||
|
|
||||||
open = keymapOption "<M-CR>" "Keymap to open.";
|
|
||||||
};
|
};
|
||||||
|
|
||||||
layout = {
|
layout = {
|
||||||
position =
|
position =
|
||||||
helpers.defaultNullOpts.mkEnumFirstDefault
|
defaultNullOpts.mkEnumFirstDefault
|
||||||
[
|
[
|
||||||
"bottom"
|
"bottom"
|
||||||
"top"
|
"top"
|
||||||
"left"
|
"left"
|
||||||
"right"
|
"right"
|
||||||
|
"horizontal"
|
||||||
|
"vertical"
|
||||||
]
|
]
|
||||||
''
|
''
|
||||||
The panel position.
|
The panel position.
|
||||||
'';
|
'';
|
||||||
|
|
||||||
ratio = helpers.defaultNullOpts.mkProportion 0.4 ''
|
ratio = defaultNullOpts.mkProportion 0.4 ''
|
||||||
The panel ratio.
|
The panel ratio.
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
suggestion = {
|
suggestion = {
|
||||||
enabled = helpers.defaultNullOpts.mkBool true "Enable suggestion.";
|
enabled = defaultNullOpts.mkBool true "Enable suggestion.";
|
||||||
|
auto_trigger = defaultNullOpts.mkBool false "Enable auto-trigger.";
|
||||||
autoTrigger = helpers.defaultNullOpts.mkBool false "Enable auto-trigger.";
|
hide_during_completion = defaultNullOpts.mkBool true "Hide during completion.";
|
||||||
|
debounce = defaultNullOpts.mkInt 75 "Debounce.";
|
||||||
debounce = helpers.defaultNullOpts.mkInt 75 "Debounce.";
|
|
||||||
|
|
||||||
keymap = {
|
keymap = {
|
||||||
accept = keymapOption "<M-l>" "Keymap for accepting the suggestion.";
|
accept = mkKeymapOption "<M-l>" "Keymap for accepting the suggestion.";
|
||||||
|
accept_word = mkKeymapOption false "Keymap for accepting a word suggestion.";
|
||||||
acceptWord = keymapOption false "Keymap for accepting a word suggestion.";
|
accept_line = mkKeymapOption false "Keymap for accepting a line suggestion.";
|
||||||
|
next = mkKeymapOption "<M-]>" "Keymap for accepting the next suggestion.";
|
||||||
acceptLine = keymapOption false "Keymap for accepting a line suggestion.";
|
prev = mkKeymapOption "<M-[>" "Keymap for accepting the previous suggestion.";
|
||||||
|
dismiss = mkKeymapOption "<C-]>" "Keymap to dismiss the suggestion.";
|
||||||
next = keymapOption "<M-]>" "Keymap for accepting the next suggestion.";
|
|
||||||
|
|
||||||
prev = keymapOption "<M-[>" "Keymap for accepting the previous suggestion.";
|
|
||||||
|
|
||||||
dismiss = keymapOption "<C-]>" "Keymap to dismiss the suggestion.";
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
filetypes =
|
filetypes = defaultNullOpts.mkAttrsOf' {
|
||||||
helpers.defaultNullOpts.mkAttrsOf types.bool
|
type = types.bool;
|
||||||
{
|
pluginDefault = {
|
||||||
yaml = false;
|
yaml = true;
|
||||||
markdown = false;
|
markdown = false;
|
||||||
help = false;
|
help = false;
|
||||||
gitcommit = false;
|
gitcommit = false;
|
||||||
|
@ -96,50 +81,47 @@ in
|
||||||
svn = false;
|
svn = false;
|
||||||
cvs = false;
|
cvs = false;
|
||||||
"." = false;
|
"." = false;
|
||||||
}
|
};
|
||||||
''
|
example = lib.literalExpression ''
|
||||||
Specify filetypes for attaching copilot.
|
|
||||||
Each value can be either a boolean or a lua function that returns a boolean.
|
|
||||||
|
|
||||||
Example:
|
|
||||||
```nix
|
|
||||||
{
|
{
|
||||||
markdown = true; # overrides default
|
markdown = true; # overrides default
|
||||||
terraform = false; # disallow specific filetype
|
terraform = false; # disallow specific filetype
|
||||||
sh.__raw = \'\'
|
sh.__raw = '''
|
||||||
function ()
|
function()
|
||||||
if string.match(vim.fs.basename(vim.api.nvim_buf_get_name(0)), '^%.env.*') then
|
if string.match(vim.fs.basename(vim.api.nvim_buf_get_name(0)), '^%.env.*') then
|
||||||
-- disable for .env files
|
-- disable for .env files
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
\'\';
|
''';
|
||||||
|
javascript = true; # allow specific type
|
||||||
|
"*" = false; # disable for all other filetypes and ignore default filetypes
|
||||||
}
|
}
|
||||||
```
|
|
||||||
|
|
||||||
The key `"*"` can be used to disable the default configuration.
|
|
||||||
Example:
|
|
||||||
```nix
|
|
||||||
{
|
|
||||||
javascript = true; # allow specific filetype
|
|
||||||
typescript = true; # allow specific filetype
|
|
||||||
"*" = false; # disable for all other filetypes and ignore default `filetypes`
|
|
||||||
}
|
|
||||||
```
|
|
||||||
'';
|
'';
|
||||||
|
|
||||||
copilotNodeCommand = mkOption {
|
|
||||||
type = types.str;
|
|
||||||
default = "${pkgs.nodejs-18_x}/bin/node";
|
|
||||||
description = ''
|
description = ''
|
||||||
Use this field to provide the path to a specific node version such as one installed by
|
Specify filetypes for attaching copilot.
|
||||||
`nvm`.
|
Each value can be either a boolean or a lua function that returns a boolean.
|
||||||
Node.js version must be 16.x or newer.
|
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
serverOptsOverrides = helpers.defaultNullOpts.mkAttrsOf' {
|
copilot_node_command =
|
||||||
|
let
|
||||||
|
inherit (config.plugins.copilot-lua) nodePackage;
|
||||||
|
in
|
||||||
|
lib.nixvim.mkNullOrOption' {
|
||||||
|
type = types.str;
|
||||||
|
default = if nodePackage == null then null else lib.getExe nodePackage;
|
||||||
|
defaultText = lib.literalMD "`lib.getExe nodePackage` if `nodePackage` is not null, otherwise `null`";
|
||||||
|
pluginDefault = "node";
|
||||||
|
example = lib.literalExpression "lib.getExe pkgs.nodejs";
|
||||||
|
description = ''
|
||||||
|
Define the node command to use for copilot-lua.
|
||||||
|
Node.js version must be 18.x or newer.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
server_opts_overrides = defaultNullOpts.mkAttrsOf' {
|
||||||
type = types.anything;
|
type = types.anything;
|
||||||
pluginDefault = { };
|
pluginDefault = { };
|
||||||
description = ''
|
description = ''
|
||||||
|
@ -164,9 +146,36 @@ in
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
settingsExample = {
|
||||||
|
panel = {
|
||||||
|
enabled = true;
|
||||||
|
auto_refresh = true;
|
||||||
|
};
|
||||||
|
suggestion = {
|
||||||
|
enabled = true;
|
||||||
|
auto_trigger = false;
|
||||||
|
hide_during_completion = false;
|
||||||
|
debounce = 90;
|
||||||
|
keymap = {
|
||||||
|
accept_word = false;
|
||||||
|
accept_line = false;
|
||||||
|
};
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
config = mkIf cfg.enable {
|
extraOptions = {
|
||||||
|
nodePackage = lib.mkPackageOption pkgs "nodejs" {
|
||||||
|
default = [ "nodejs-18_x" ];
|
||||||
|
example = [ "nodejs" ];
|
||||||
|
nullable = true;
|
||||||
|
extraDescription = ''
|
||||||
|
If non-null, will provide a default for `settings.copilot_node_command`.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
extraConfig = {
|
||||||
assertions = [
|
assertions = [
|
||||||
{
|
{
|
||||||
assertion = !config.plugins.copilot-vim.enable;
|
assertion = !config.plugins.copilot-vim.enable;
|
||||||
|
@ -176,45 +185,9 @@ in
|
||||||
'';
|
'';
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
};
|
||||||
|
|
||||||
extraPlugins = [ cfg.package ];
|
# TODO: introduced 2025-01-07: remove after 25.05
|
||||||
|
deprecateExtraOptions = true;
|
||||||
extraConfigLua =
|
optionsRenamedToSettings = import ./renamed-options.nix;
|
||||||
let
|
|
||||||
setupOptions =
|
|
||||||
with cfg;
|
|
||||||
{
|
|
||||||
panel = with panel; {
|
|
||||||
inherit enabled;
|
|
||||||
auto_refresh = autoRefresh;
|
|
||||||
keymap = with keymap; {
|
|
||||||
jump_prev = jumpPrev;
|
|
||||||
jump_next = jumpNext;
|
|
||||||
inherit accept refresh open;
|
|
||||||
};
|
|
||||||
layout = with layout; {
|
|
||||||
inherit position ratio;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
suggestion = with suggestion; {
|
|
||||||
inherit enabled;
|
|
||||||
auto_trigger = autoTrigger;
|
|
||||||
inherit debounce;
|
|
||||||
keymap = with keymap; {
|
|
||||||
inherit accept;
|
|
||||||
accept_word = acceptWord;
|
|
||||||
accept_line = acceptLine;
|
|
||||||
inherit next prev dismiss;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
inherit filetypes;
|
|
||||||
copilot_node_command = copilotNodeCommand;
|
|
||||||
server_opts_overrides = serverOptsOverrides;
|
|
||||||
}
|
|
||||||
// cfg.extraOptions;
|
|
||||||
in
|
|
||||||
''
|
|
||||||
require('copilot').setup(${lib.nixvim.toLuaObject setupOptions})
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
58
plugins/by-name/copilot-lua/renamed-options.nix
Normal file
58
plugins/by-name/copilot-lua/renamed-options.nix
Normal file
|
@ -0,0 +1,58 @@
|
||||||
|
let
|
||||||
|
panelOptions = [
|
||||||
|
"enabled"
|
||||||
|
"autoRefresh"
|
||||||
|
];
|
||||||
|
panelKeymapOptions = [
|
||||||
|
"jumpPrev"
|
||||||
|
"jumpNext"
|
||||||
|
"accept"
|
||||||
|
"refresh"
|
||||||
|
"open"
|
||||||
|
];
|
||||||
|
panelLayoutOptions = [
|
||||||
|
"position"
|
||||||
|
"ratio"
|
||||||
|
];
|
||||||
|
suggestionOptions = [
|
||||||
|
"enabled"
|
||||||
|
"autoTrigger"
|
||||||
|
"debounce"
|
||||||
|
];
|
||||||
|
suggestionKeymapOptions = [
|
||||||
|
"accept"
|
||||||
|
"acceptWord"
|
||||||
|
"acceptLine"
|
||||||
|
"next"
|
||||||
|
"prev"
|
||||||
|
"dismiss"
|
||||||
|
];
|
||||||
|
in
|
||||||
|
[
|
||||||
|
"filetypes"
|
||||||
|
"copilotNodeCommand"
|
||||||
|
"serverOptsOverrides"
|
||||||
|
]
|
||||||
|
++ map (oldOption: [
|
||||||
|
"panel"
|
||||||
|
oldOption
|
||||||
|
]) panelOptions
|
||||||
|
++ map (oldOption: [
|
||||||
|
"panel"
|
||||||
|
"keymap"
|
||||||
|
oldOption
|
||||||
|
]) panelKeymapOptions
|
||||||
|
++ map (oldOption: [
|
||||||
|
"panel"
|
||||||
|
"layout"
|
||||||
|
oldOption
|
||||||
|
]) panelLayoutOptions
|
||||||
|
++ map (oldOption: [
|
||||||
|
"suggestion"
|
||||||
|
oldOption
|
||||||
|
]) suggestionOptions
|
||||||
|
++ map (oldOption: [
|
||||||
|
"suggestion"
|
||||||
|
"keymap"
|
||||||
|
oldOption
|
||||||
|
]) suggestionKeymapOptions
|
|
@ -8,9 +8,11 @@
|
||||||
copilot-lua = {
|
copilot-lua = {
|
||||||
enable = true;
|
enable = true;
|
||||||
|
|
||||||
|
settings = {
|
||||||
panel.enabled = false;
|
panel.enabled = false;
|
||||||
suggestion.enabled = false;
|
suggestion.enabled = false;
|
||||||
};
|
};
|
||||||
|
};
|
||||||
|
|
||||||
copilot-cmp.settings = {
|
copilot-cmp.settings = {
|
||||||
event = [
|
event = [
|
||||||
|
@ -31,12 +33,13 @@
|
||||||
plugins.copilot-lua = {
|
plugins.copilot-lua = {
|
||||||
enable = true;
|
enable = true;
|
||||||
|
|
||||||
|
settings = {
|
||||||
panel = {
|
panel = {
|
||||||
enabled = true;
|
enabled = true;
|
||||||
autoRefresh = false;
|
auto_refresh = false;
|
||||||
keymap = {
|
keymap = {
|
||||||
jumpPrev = "[[";
|
jump_prev = "[[";
|
||||||
jumpNext = "]]";
|
jump_next = "]]";
|
||||||
accept = "<CR>";
|
accept = "<CR>";
|
||||||
refresh = "gr";
|
refresh = "gr";
|
||||||
open = "<M-CR>";
|
open = "<M-CR>";
|
||||||
|
@ -48,31 +51,30 @@
|
||||||
};
|
};
|
||||||
suggestion = {
|
suggestion = {
|
||||||
enabled = true;
|
enabled = true;
|
||||||
autoTrigger = false;
|
auto_trigger = false;
|
||||||
|
hide_during_completion = true;
|
||||||
debounce = 75;
|
debounce = 75;
|
||||||
keymap = {
|
keymap = {
|
||||||
accept = "<M-l>";
|
accept = "<M-l>";
|
||||||
acceptWord = false;
|
accept_word = false;
|
||||||
acceptLine = false;
|
accept_line = false;
|
||||||
next = "<M-]>";
|
next = "<M-]>";
|
||||||
prev = "<M-[>";
|
prev = "<M-[>";
|
||||||
dismiss = "<C-]>";
|
dismiss = "<C-]>";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
filetypes = {
|
filetypes = {
|
||||||
markdown = true;
|
yaml = false;
|
||||||
terraform = false;
|
markdown = false;
|
||||||
sh.__raw = ''
|
help = false;
|
||||||
function ()
|
gitcommit = false;
|
||||||
if string.match(vim.fs.basename(vim.api.nvim_buf_get_name(0)), '^%.env.*') then
|
gitrebase = false;
|
||||||
-- disable for .env files
|
hgcommit = false;
|
||||||
return false
|
svn = false;
|
||||||
end
|
cvs = false;
|
||||||
return true
|
"." = false;
|
||||||
end
|
|
||||||
'';
|
|
||||||
};
|
};
|
||||||
serverOptsOverrides = {
|
server_opts_overrides = {
|
||||||
trace = "verbose";
|
trace = "verbose";
|
||||||
settings = {
|
settings = {
|
||||||
advanced = {
|
advanced = {
|
||||||
|
@ -83,4 +85,63 @@
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
examples = {
|
||||||
|
plugins.copilot-lua = {
|
||||||
|
enable = true;
|
||||||
|
|
||||||
|
settings = {
|
||||||
|
panel = {
|
||||||
|
enabled = true;
|
||||||
|
auto_refresh = true;
|
||||||
|
keymap = {
|
||||||
|
jump_prev = "[[";
|
||||||
|
jump_next = "]]";
|
||||||
|
accept = "<CR>";
|
||||||
|
refresh = "gr";
|
||||||
|
open = "<M-CR>";
|
||||||
|
};
|
||||||
|
layout = {
|
||||||
|
position = "top";
|
||||||
|
ratio = 0.5;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
suggestion = {
|
||||||
|
enabled = true;
|
||||||
|
auto_trigger = false;
|
||||||
|
hide_during_completion = false;
|
||||||
|
debounce = 90;
|
||||||
|
keymap = {
|
||||||
|
accept = "<M-l>";
|
||||||
|
accept_word = false;
|
||||||
|
accept_line = false;
|
||||||
|
next = "<M-]>";
|
||||||
|
prev = "<M-[>";
|
||||||
|
dismiss = "<C-]>";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
filetypes = {
|
||||||
|
yaml = true;
|
||||||
|
markdown = true;
|
||||||
|
help = true;
|
||||||
|
gitcommit = true;
|
||||||
|
gitrebase = true;
|
||||||
|
hgcommit = true;
|
||||||
|
svn = true;
|
||||||
|
cvs = true;
|
||||||
|
"." = true;
|
||||||
|
};
|
||||||
|
server_opts_overrides = {
|
||||||
|
trace = "verbose";
|
||||||
|
settings = {
|
||||||
|
advanced = {
|
||||||
|
listCount = 10; # number of completions for panel
|
||||||
|
inlineSuggestCount = 3; # number of completions for getCompletions
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,9 +7,11 @@
|
||||||
copilot-lua = {
|
copilot-lua = {
|
||||||
enable = true;
|
enable = true;
|
||||||
|
|
||||||
|
settings = {
|
||||||
panel.enabled = false;
|
panel.enabled = false;
|
||||||
suggestion.enabled = false;
|
suggestion.enabled = false;
|
||||||
};
|
};
|
||||||
|
};
|
||||||
|
|
||||||
cmp = {
|
cmp = {
|
||||||
enable = true;
|
enable = true;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue