From 85c3c250f6eab4e62da34ae0eb879f88c7df1954 Mon Sep 17 00:00:00 2001 From: n3oney Date: Wed, 5 Apr 2023 00:53:21 +0200 Subject: [PATCH] feat: add Copilot keybindings --- modules/assistant/copilot/config.nix | 23 ++++++++++ modules/assistant/copilot/copilot.nix | 62 +++++++++++++++++++++++++++ 2 files changed, 85 insertions(+) diff --git a/modules/assistant/copilot/config.nix b/modules/assistant/copilot/config.nix index 62d0251..4ecac27 100644 --- a/modules/assistant/copilot/config.nix +++ b/modules/assistant/copilot/config.nix @@ -7,6 +7,10 @@ with lib; with builtins; let cfg = config.vim.assistant.copilot; + keyOrFalse = key: + if key != null + then "'${key}'" + else "false"; in { config = mkIf cfg.enable { vim.startPlugins = [ @@ -18,6 +22,25 @@ in { require("copilot").setup({ -- available options: https://github.com/zbirenbaum/copilot.lua copilot_node_command = "${cfg.copilot_node_command}", + panel = { + keymap = { + jump_prev = ${keyOrFalse cfg.mappings.panel.jumpPrev}, + jump_next = ${keyOrFalse cfg.mappings.panel.jumpNext}, + accept = ${keyOrFalse cfg.mappings.panel.accept}, + refresh = ${keyOrFalse cfg.mappings.panel.refresh}, + open = ${keyOrFalse cfg.mappings.panel.open}, + }, + }, + suggestion = { + keymap = { + accept = ${keyOrFalse cfg.mappings.suggestion.accept}, + accept_word = ${keyOrFalse cfg.mappings.suggestion.acceptWord}, + accept_line = ${keyOrFalse cfg.mappings.suggestion.acceptLine}, + next = ${keyOrFalse cfg.mappings.suggestion.next}, + prev = ${keyOrFalse cfg.mappings.suggestion.prev}, + dismiss = ${keyOrFalse cfg.mappings.suggestion.dismiss}, + }, + }, }) ''; }; diff --git a/modules/assistant/copilot/copilot.nix b/modules/assistant/copilot/copilot.nix index ad3e622..fcf5a5d 100644 --- a/modules/assistant/copilot/copilot.nix +++ b/modules/assistant/copilot/copilot.nix @@ -9,6 +9,68 @@ with builtins; { options.vim.assistant.copilot = { enable = mkEnableOption "Enable GitHub Copilot"; + mappings = { + panel = { + jumpPrev = mkOption { + type = types.nullOr types.str; + default = "[["; + description = "Jump to previous suggestion"; + }; + jumpNext = mkOption { + type = types.nullOr types.str; + default = "]]"; + description = "Jump to next suggestion"; + }; + accept = mkOption { + type = types.nullOr types.str; + default = ""; + description = "Accept suggestion"; + }; + refresh = mkOption { + type = types.nullOr types.str; + default = "gr"; + description = "Refresh suggestions"; + }; + open = mkOption { + type = types.nullOr types.str; + default = ""; + description = "Open suggestions"; + }; + }; + suggestion = { + accept = mkOption { + type = types.nullOr types.str; + default = ""; + description = "Accept suggetion"; + }; + acceptWord = mkOption { + type = types.nullOr types.str; + default = null; + description = "Accept next word"; + }; + acceptLine = mkOption { + type = types.nullOr types.str; + default = null; + description = "Accept next line"; + }; + prev = mkOption { + type = types.nullOr types.str; + default = ""; + description = "Previous suggestion"; + }; + next = mkOption { + type = types.nullOr types.str; + default = ""; + description = "Next suggestion"; + }; + dismiss = mkOption { + type = types.nullOr types.str; + default = ""; + description = "Dismiss suggestion"; + }; + }; + }; + copilot_node_command = mkOption { type = types.str; default = "${lib.getExe pkgs.nodejs-slim-16_x}";