mirror of
https://github.com/NotAShelf/nvf.git
synced 2025-09-06 02:11:33 +00:00
treewide: begin restructuring the module tree
This commit is contained in:
parent
e1835f6c46
commit
7c730a78e5
254 changed files with 749 additions and 664 deletions
85
modules/plugins/assistant/copilot/config.nix
Normal file
85
modules/plugins/assistant/copilot/config.nix
Normal file
|
@ -0,0 +1,85 @@
|
|||
{
|
||||
config,
|
||||
lib,
|
||||
...
|
||||
}: 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;
|
||||
|
||||
cfg = config.vim.assistant.copilot;
|
||||
|
||||
wrapPanelBinding = luaFunction: key: ''
|
||||
function()
|
||||
local s, _ = pcall(${luaFunction})
|
||||
|
||||
if not s then
|
||||
local termcode = vim.api.nvim_replace_termcodes(${toJSON key}, true, false, true)
|
||||
|
||||
vim.fn.feedkeys(termcode, 'n')
|
||||
end
|
||||
end
|
||||
'';
|
||||
in {
|
||||
config = mkIf cfg.enable {
|
||||
vim.startPlugins =
|
||||
[
|
||||
"copilot-lua"
|
||||
# cfg.copilotNodePackage
|
||||
]
|
||||
++ optionals (cfg.cmp.enable) [
|
||||
"copilot-cmp"
|
||||
];
|
||||
|
||||
vim.luaConfigRC.copilot = entryAnywhere ''
|
||||
require("copilot").setup(${toLuaObject cfg.setupOpts})
|
||||
|
||||
${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;
|
||||
};
|
||||
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")
|
||||
];
|
||||
};
|
||||
}
|
131
modules/plugins/assistant/copilot/copilot.nix
Normal file
131
modules/plugins/assistant/copilot/copilot.nix
Normal file
|
@ -0,0 +1,131 @@
|
|||
{
|
||||
config,
|
||||
pkgs,
|
||||
lib,
|
||||
...
|
||||
}: let
|
||||
inherit (lib) mkRenamedOptionModule;
|
||||
inherit (lib.options) mkEnableOption mkOption;
|
||||
inherit (lib.types) nullOr str enum float;
|
||||
inherit (lib.nvim.types) mkPluginSetupOption;
|
||||
|
||||
cfg = config.vim.assistant.copilot;
|
||||
in {
|
||||
imports = [
|
||||
(mkRenamedOptionModule ["vim" "assistant" "copilot" "panel"] ["vim" "assistant" "copilot" "setupOpts" "panel"])
|
||||
(mkRenamedOptionModule ["vim" "assistant" "copilot" "copilotNodeCommand"] ["vim" "assistant" "copilot" "setupOpts" "copilot_node_command"])
|
||||
(mkRenamedOptionModule ["vim" "assistant" "copilot" "copilotNodePackage"] ["vim" "assistant" "copilot" "setupOpts" "copilot_node_command"])
|
||||
];
|
||||
|
||||
options.vim.assistant.copilot = {
|
||||
enable = mkEnableOption "GitHub Copilot AI assistant";
|
||||
cmp.enable = mkEnableOption "nvim-cmp integration for GitHub Copilot";
|
||||
|
||||
setupOpts = mkPluginSetupOption "Copilot" {
|
||||
copilot_node_command = mkOption {
|
||||
type = str;
|
||||
default = "${lib.getExe pkgs.nodejs-slim}";
|
||||
description = ''
|
||||
The command that will be executed to initiate nodejs for GitHub Copilot.
|
||||
Recommended to leave as default.
|
||||
'';
|
||||
};
|
||||
panel = {
|
||||
enabled = mkEnableOption "Completion Panel" // {default = !cfg.cmp.enable;};
|
||||
layout = {
|
||||
position = mkOption {
|
||||
type = enum [
|
||||
"bottom"
|
||||
"top"
|
||||
"left"
|
||||
"right"
|
||||
];
|
||||
default = "bottom";
|
||||
description = "Panel position";
|
||||
};
|
||||
ratio = mkOption {
|
||||
type = float;
|
||||
default = 0.4;
|
||||
description = "Panel size";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
suggestion = {
|
||||
enabled = mkEnableOption "Suggestions" // {default = !cfg.cmp.enable;};
|
||||
# keymap = { };
|
||||
};
|
||||
};
|
||||
|
||||
mappings = {
|
||||
panel = {
|
||||
jumpPrev = mkOption {
|
||||
type = nullOr str;
|
||||
default = "[[";
|
||||
description = "Jump to previous suggestion";
|
||||
};
|
||||
|
||||
jumpNext = mkOption {
|
||||
type = nullOr str;
|
||||
default = "]]";
|
||||
description = "Jump to next suggestion";
|
||||
};
|
||||
|
||||
accept = mkOption {
|
||||
type = nullOr str;
|
||||
default = "<CR>";
|
||||
description = "Accept suggestion";
|
||||
};
|
||||
|
||||
refresh = mkOption {
|
||||
type = nullOr str;
|
||||
default = "gr";
|
||||
description = "Refresh suggestions";
|
||||
};
|
||||
|
||||
open = mkOption {
|
||||
type = nullOr str;
|
||||
default = "<M-CR>";
|
||||
description = "Open suggestions";
|
||||
};
|
||||
};
|
||||
suggestion = {
|
||||
accept = mkOption {
|
||||
type = nullOr str;
|
||||
default = "<M-l>";
|
||||
description = "Accept suggetion";
|
||||
};
|
||||
|
||||
acceptWord = mkOption {
|
||||
type = nullOr str;
|
||||
default = null;
|
||||
description = "Accept next word";
|
||||
};
|
||||
|
||||
acceptLine = mkOption {
|
||||
type = nullOr str;
|
||||
default = null;
|
||||
description = "Accept next line";
|
||||
};
|
||||
|
||||
prev = mkOption {
|
||||
type = nullOr str;
|
||||
default = "<M-[>";
|
||||
description = "Previous suggestion";
|
||||
};
|
||||
|
||||
next = mkOption {
|
||||
type = nullOr str;
|
||||
default = "<M-]>";
|
||||
description = "Next suggestion";
|
||||
};
|
||||
|
||||
dismiss = mkOption {
|
||||
type = nullOr str;
|
||||
default = "<C-]>";
|
||||
description = "Dismiss suggestion";
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
6
modules/plugins/assistant/copilot/default.nix
Normal file
6
modules/plugins/assistant/copilot/default.nix
Normal file
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
imports = [
|
||||
./copilot.nix
|
||||
./config.nix
|
||||
];
|
||||
}
|
5
modules/plugins/assistant/default.nix
Normal file
5
modules/plugins/assistant/default.nix
Normal file
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
imports = [
|
||||
./copilot
|
||||
];
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue