2023-02-27 14:05:43 +00:00
|
|
|
{
|
|
|
|
config,
|
|
|
|
lib,
|
|
|
|
...
|
2023-11-07 00:50:27 +00:00
|
|
|
}: let
|
2023-11-14 07:18:32 +00:00
|
|
|
inherit (builtins) toJSON;
|
2024-02-26 05:05:23 +00:00
|
|
|
inherit (lib.modules) mkIf mkMerge;
|
|
|
|
inherit (lib.nvim.dag) entryAnywhere;
|
|
|
|
inherit (lib.lists) optionals;
|
|
|
|
inherit (lib.trivial) boolToString;
|
|
|
|
inherit (lib.nvim.binds) mkLuaBinding;
|
2023-11-07 00:50:27 +00:00
|
|
|
|
2023-02-27 14:05:43 +00:00
|
|
|
cfg = config.vim.assistant.copilot;
|
2023-04-22 15:30:32 +00:00
|
|
|
|
|
|
|
wrapPanelBinding = luaFunction: key: ''
|
|
|
|
function()
|
|
|
|
local s, _ = pcall(${luaFunction})
|
|
|
|
|
|
|
|
if not s then
|
2023-11-14 07:18:32 +00:00
|
|
|
local termcode = vim.api.nvim_replace_termcodes(${toJSON key}, true, false, true)
|
2023-04-22 15:30:32 +00:00
|
|
|
|
|
|
|
vim.fn.feedkeys(termcode, 'n')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
'';
|
2023-02-27 14:05:43 +00:00
|
|
|
in {
|
|
|
|
config = mkIf cfg.enable {
|
2023-07-24 13:51:24 +00:00
|
|
|
vim.startPlugins =
|
|
|
|
[
|
|
|
|
"copilot-lua"
|
|
|
|
cfg.copilotNodePackage
|
|
|
|
]
|
2024-02-26 05:05:23 +00:00
|
|
|
++ optionals (cfg.cmp.enable) [
|
2023-07-24 13:51:24 +00:00
|
|
|
"copilot-cmp"
|
|
|
|
];
|
2023-02-27 14:05:43 +00:00
|
|
|
|
2024-02-26 05:05:23 +00:00
|
|
|
vim.luaConfigRC.copilot = entryAnywhere ''
|
2023-02-27 14:05:43 +00:00
|
|
|
require("copilot").setup({
|
|
|
|
-- available options: https://github.com/zbirenbaum/copilot.lua
|
2023-07-24 13:51:24 +00:00
|
|
|
copilot_node_command = "${cfg.copilotNodeCommand}",
|
2023-04-04 22:53:21 +00:00
|
|
|
panel = {
|
2024-02-26 05:05:23 +00:00
|
|
|
enabled = ${boolToString (!cfg.cmp.enable)},
|
2023-04-04 22:53:21 +00:00
|
|
|
keymap = {
|
2023-04-11 12:38:27 +00:00
|
|
|
jump_prev = false,
|
|
|
|
jump_next = false,
|
|
|
|
accept = false,
|
|
|
|
refresh = false,
|
|
|
|
open = false,
|
|
|
|
},
|
|
|
|
layout = {
|
|
|
|
position = "${cfg.panel.position}",
|
|
|
|
ratio = ${toString cfg.panel.ratio},
|
2023-04-04 22:53:21 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
suggestion = {
|
2024-02-26 05:05:23 +00:00
|
|
|
enabled = ${boolToString (!cfg.cmp.enable)},
|
2023-04-04 22:53:21 +00:00
|
|
|
keymap = {
|
2023-04-11 12:38:27 +00:00
|
|
|
accept = false,
|
|
|
|
accept_word = false,
|
|
|
|
accept_line = false,
|
|
|
|
next = false,
|
|
|
|
prev = false,
|
|
|
|
dismiss = false,
|
2023-04-04 22:53:21 +00:00
|
|
|
},
|
|
|
|
},
|
2023-02-27 14:05:43 +00:00
|
|
|
})
|
2023-07-24 13:51:24 +00:00
|
|
|
|
|
|
|
${lib.optionalString (cfg.cmp.enable) ''
|
|
|
|
require("copilot_cmp").setup()
|
|
|
|
''}
|
2023-02-27 14:05:43 +00:00
|
|
|
'';
|
2023-04-11 12:38:27 +00:00
|
|
|
|
|
|
|
vim.maps.normal = mkMerge [
|
2023-04-22 15:30:32 +00:00
|
|
|
(mkLuaBinding cfg.mappings.panel.jumpPrev (wrapPanelBinding "require(\"copilot.panel\").jump_prev" cfg.mappings.panel.jumpPrev) "[copilot] Accept suggestion")
|
|
|
|
(mkLuaBinding cfg.mappings.panel.jumpNext (wrapPanelBinding "require(\"copilot.panel\").jump_next" cfg.mappings.panel.jumpNext) "[copilot] Accept suggestion")
|
|
|
|
(mkLuaBinding cfg.mappings.panel.accept (wrapPanelBinding ''require("copilot.panel").accept'' cfg.mappings.panel.accept) "[copilot] Accept suggestion")
|
|
|
|
(mkLuaBinding cfg.mappings.panel.refresh (wrapPanelBinding "require(\"copilot.panel\").refresh" cfg.mappings.panel.refresh) "[copilot] Accept suggestion")
|
|
|
|
(mkLuaBinding cfg.mappings.panel.open (wrapPanelBinding ''
|
|
|
|
function() require("copilot.panel").open({ position = "${cfg.panel.position}", ratio = ${toString cfg.panel.ratio}, }) end
|
|
|
|
''
|
|
|
|
cfg.mappings.panel.open) "[copilot] Accept suggestion")
|
2023-04-11 12:38:27 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
vim.maps.insert = mkMerge [
|
|
|
|
(mkLuaBinding cfg.mappings.suggestion.accept "require(\"copilot.suggestion\").accept" "[copilot] Accept suggestion")
|
|
|
|
(mkLuaBinding cfg.mappings.suggestion.acceptLine "require(\"copilot.suggestion\").accept_line" "[copilot] Accept suggestion (line)")
|
|
|
|
(mkLuaBinding cfg.mappings.suggestion.acceptWord "require(\"copilot.suggestion\").accept_word" "[copilot] Accept suggestion (word)")
|
|
|
|
(mkLuaBinding cfg.mappings.suggestion.next "require(\"copilot.suggestion\").next" "[copilot] next suggestion")
|
|
|
|
(mkLuaBinding cfg.mappings.suggestion.prev "require(\"copilot.suggestion\").prev" "[copilot] previous suggestion")
|
|
|
|
(mkLuaBinding cfg.mappings.suggestion.dismiss "require(\"copilot.suggestion\").dismiss" "[copilot] dismiss suggestion")
|
|
|
|
];
|
2023-02-27 14:05:43 +00:00
|
|
|
};
|
|
|
|
}
|