mirror of
https://github.com/NotAShelf/nvf.git
synced 2025-02-12 20:13:19 +00:00
copilot: lazy load
This commit is contained in:
parent
7e10870363
commit
b636b22046
1 changed files with 58 additions and 57 deletions
|
@ -4,11 +4,7 @@
|
|||
...
|
||||
}: let
|
||||
inherit (builtins) toJSON;
|
||||
inherit (lib.nvim.lua) toLuaObject;
|
||||
inherit (lib.modules) mkIf mkMerge;
|
||||
inherit (lib.nvim.dag) entryAnywhere;
|
||||
inherit (lib.lists) optionals;
|
||||
inherit (lib.nvim.binds) mkLuaBinding;
|
||||
inherit (lib.modules) mkIf;
|
||||
|
||||
cfg = config.vim.assistant.copilot;
|
||||
|
||||
|
@ -23,65 +19,70 @@
|
|||
end
|
||||
end
|
||||
'';
|
||||
|
||||
mkLuaKeymap = mode: key: action: desc: opts:
|
||||
opts
|
||||
// {
|
||||
inherit mode key action desc;
|
||||
lua = true;
|
||||
};
|
||||
in {
|
||||
config = mkIf cfg.enable {
|
||||
vim.startPlugins =
|
||||
[
|
||||
"copilot-lua"
|
||||
# cfg.copilotNodePackage
|
||||
]
|
||||
++ optionals cfg.cmp.enable [
|
||||
"copilot-cmp"
|
||||
];
|
||||
vim = {
|
||||
lazy.plugins = {
|
||||
copilot-lua = {
|
||||
package = "copilot-lua";
|
||||
setupModule = "copilot";
|
||||
inherit (cfg) setupOpts;
|
||||
after = mkIf cfg.cmp.enable "require('copilot_cmp').setup()";
|
||||
|
||||
vim.autocomplete.nvim-cmp.sources = {copilot = "[Copilot]";};
|
||||
cmd = ["Copilot" "CopilotAuth" "CopilotDetach" "CopilotPanel" "CopilotStop"];
|
||||
keys = [
|
||||
(mkLuaKeymap ["n"] cfg.mappings.panel.accept (wrapPanelBinding ''require("copilot.panel").accept'' cfg.mappings.panel.accept) "[copilot] Accept suggestion" {})
|
||||
(mkLuaKeymap ["n"] cfg.mappings.panel.jumpNext (wrapPanelBinding "require(\"copilot.panel\").jump_next" cfg.mappings.panel.jumpNext) "[copilot] Accept suggestion" {})
|
||||
(mkLuaKeymap ["n"] cfg.mappings.panel.jumpPrev (wrapPanelBinding "require(\"copilot.panel\").jump_prev" cfg.mappings.panel.jumpPrev) "[copilot] Accept suggestion" {})
|
||||
(mkLuaKeymap ["n"] cfg.mappings.panel.refresh (wrapPanelBinding "require(\"copilot.panel\").refresh" cfg.mappings.panel.refresh) "[copilot] Accept suggestion" {})
|
||||
(mkLuaKeymap ["n"] cfg.mappings.panel.open (wrapPanelBinding ''
|
||||
function() require("copilot.panel").open({ position = "${cfg.setupOpts.panel.layout.position}", ratio = ${toString cfg.setupOpts.panel.layout.ratio}, }) end
|
||||
''
|
||||
cfg.mappings.panel.open) "[copilot] Accept suggestion" {})
|
||||
|
||||
vim.pluginRC.copilot = entryAnywhere ''
|
||||
require("copilot").setup(${toLuaObject cfg.setupOpts})
|
||||
(mkLuaKeymap ["i"] cfg.mappings.suggestion.accept "function() require('copilot.suggestion').accept() end" "[copilot] Accept suggestion" {})
|
||||
(mkLuaKeymap ["i"] cfg.mappings.suggestion.acceptLine "function() require('copilot.suggestion').accept_line() end" "[copilot] Accept suggestion (line)" {})
|
||||
(mkLuaKeymap ["i"] cfg.mappings.suggestion.acceptWord "function() require('copilot.suggestion').accept_word() end" "[copilot] Accept suggestion (word)" {})
|
||||
(mkLuaKeymap ["i"] cfg.mappings.suggestion.dismiss "function() require('copilot.suggestion').dismiss() end" "[copilot] dismiss suggestion" {})
|
||||
(mkLuaKeymap ["i"] cfg.mappings.suggestion.next "function() require('copilot.suggestion').next() end" "[copilot] next suggestion" {})
|
||||
(mkLuaKeymap ["i"] cfg.mappings.suggestion.prev "function() require('copilot.suggestion').prev() end" "[copilot] previous suggestion" {})
|
||||
];
|
||||
};
|
||||
|
||||
${lib.optionalString cfg.cmp.enable ''
|
||||
require("copilot_cmp").setup()
|
||||
''}
|
||||
'';
|
||||
|
||||
# Disable plugin handled keymaps.
|
||||
# Setting it here so that it doesn't show up in user docs
|
||||
vim.assistant.copilot.setupOpts = {
|
||||
panel.keymap = {
|
||||
jump_prev = lib.mkDefault false;
|
||||
jump_next = lib.mkDefault false;
|
||||
accept = lib.mkDefault false;
|
||||
refresh = lib.mkDefault false;
|
||||
open = lib.mkDefault false;
|
||||
copilot-cmp = mkIf cfg.cmp.enable {
|
||||
package = "copilot-cmp";
|
||||
lazy = true;
|
||||
};
|
||||
};
|
||||
suggestion.keymap = {
|
||||
accept = lib.mkDefault false;
|
||||
accept_word = lib.mkDefault false;
|
||||
accept_line = lib.mkDefault false;
|
||||
next = lib.mkDefault false;
|
||||
prev = lib.mkDefault false;
|
||||
dismiss = lib.mkDefault false;
|
||||
|
||||
autocomplete.nvim-cmp.sources = {copilot = "[Copilot]";};
|
||||
|
||||
# Disable plugin handled keymaps.
|
||||
# Setting it here so that it doesn't show up in user docs
|
||||
assistant.copilot.setupOpts = {
|
||||
panel.keymap = {
|
||||
jump_prev = lib.mkDefault false;
|
||||
jump_next = lib.mkDefault false;
|
||||
accept = lib.mkDefault false;
|
||||
refresh = lib.mkDefault false;
|
||||
open = lib.mkDefault false;
|
||||
};
|
||||
suggestion.keymap = {
|
||||
accept = lib.mkDefault false;
|
||||
accept_word = lib.mkDefault false;
|
||||
accept_line = lib.mkDefault false;
|
||||
next = lib.mkDefault false;
|
||||
prev = lib.mkDefault false;
|
||||
dismiss = lib.mkDefault false;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
vim.maps.normal = mkMerge [
|
||||
(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.setupOpts.panel.layout.position}", ratio = ${toString cfg.setupOpts.panel.layout.ratio}, }) end
|
||||
''
|
||||
cfg.mappings.panel.open) "[copilot] Accept suggestion")
|
||||
];
|
||||
|
||||
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")
|
||||
];
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue