diff --git a/configuration.nix b/configuration.nix index 7e55050..a3b1846 100644 --- a/configuration.nix +++ b/configuration.nix @@ -222,6 +222,7 @@ inputs: let }; assistant = { + chatgpt.enable = isMaximal; copilot = { enable = isMaximal; cmp.enable = isMaximal; diff --git a/flake.nix b/flake.nix index 78c3447..eed650e 100644 --- a/flake.nix +++ b/flake.nix @@ -550,6 +550,11 @@ }; # Assistant + plugin-chatgpt = { + url = "github:jackMort/ChatGPT.nvim"; + flake = false; + }; + plugin-copilot-lua = { url = "github:zbirenbaum/copilot.lua"; flake = false; diff --git a/modules/plugins/assistant/chatgpt/chatgpt.nix b/modules/plugins/assistant/chatgpt/chatgpt.nix new file mode 100644 index 0000000..95dde39 --- /dev/null +++ b/modules/plugins/assistant/chatgpt/chatgpt.nix @@ -0,0 +1,25 @@ +{lib, ...}: let + inherit (lib.options) mkEnableOption; + inherit (lib.nvim.binds) mkMappingOption; + inherit (lib.nvim.types) mkPluginSetupOption; +in { + options.vim.assistant.chatgpt = { + enable = mkEnableOption "ChatGPT AI assistant. Requires the environment variable OPENAI_API_KEY to be set"; + setupOpts = mkPluginSetupOption "chatgpt" {}; + mappings = { + chatGpt = mkMappingOption "ChatGPT" "ac"; + editWithInstructions = mkMappingOption "[ChatGPT] Edit with instructions" "ae"; + grammarCorrection = mkMappingOption "[ChatGPT] Grammar correction" "ag"; + translate = mkMappingOption "[ChatGPT] Translate" "at"; + keyword = mkMappingOption "[ChatGPT] Keywords" "ak"; + docstring = mkMappingOption "[ChatGPT] Docstring" "ad"; + addTests = mkMappingOption "[ChatGPT] Add tests" "aa"; + optimize = mkMappingOption "[ChatGPT] Optimize code" "ao"; + summarize = mkMappingOption "[ChatGPT] Summarize" "as"; + fixBugs = mkMappingOption "[ChatGPT] Fix bugs" "af"; + explain = mkMappingOption "[ChatGPT] Explain code" "ax"; + roxygenEdit = mkMappingOption "[ChatGPT] Roxygen edit" "ar"; + readabilityanalysis = mkMappingOption "[ChatGPT] Code reability analysis" "al"; + }; + }; +} diff --git a/modules/plugins/assistant/chatgpt/config.nix b/modules/plugins/assistant/chatgpt/config.nix new file mode 100644 index 0000000..79db0d9 --- /dev/null +++ b/modules/plugins/assistant/chatgpt/config.nix @@ -0,0 +1,46 @@ +{ + config, + lib, + ... +}: let + inherit (lib.modules) mkIf mkMerge; + inherit (lib.nvim.dag) entryAnywhere; + inherit (lib.nvim.binds) addDescriptionsToMappings mkSetBinding; + inherit (lib.nvim.lua) toLuaObject; + + cfg = config.vim.assistant.chatgpt; + + self = import ./chatgpt.nix {inherit lib;}; + mappingDefinitions = self.options.vim.assistant.chatgpt.mappings; + mappings = addDescriptionsToMappings cfg.mappings mappingDefinitions; + maps = mkMerge [ + (mkSetBinding mappings.editWithInstructions "ChatGPTEditWithInstruction") + (mkSetBinding mappings.grammarCorrection "ChatGPTRun grammar_correction") + (mkSetBinding mappings.translate "ChatGPTRun translate") + (mkSetBinding mappings.keyword "ChatGPTRun keywords") + (mkSetBinding mappings.docstring "ChatGPTRun docstring") + (mkSetBinding mappings.addTests "ChatGPTRun add_tests") + (mkSetBinding mappings.optimize "ChatGPTRun optimize_code") + (mkSetBinding mappings.summarize "ChatGPTRun summarize") + (mkSetBinding mappings.fixBugs "ChatGPTRun fix_bugs") + (mkSetBinding mappings.explain "ChatGPTRun explain_code") + (mkSetBinding mappings.roxygenEdit "ChatGPTRun roxygen_edit") + (mkSetBinding mappings.readabilityanalysis "ChatGPTRun code_readability_analysis") + ]; +in { + config = mkIf cfg.enable { + vim = { + startPlugins = [ + "chatgpt" + ]; + luaConfigRC.chagpt = entryAnywhere '' + require("chatgpt").setup(${toLuaObject cfg.setupOpts}) + ''; + maps.normal = mkMerge [ + (mkSetBinding mappings.chatGpt "ChatGPT") + maps + ]; + maps.visual = maps; + }; + }; +} diff --git a/modules/plugins/assistant/chatgpt/default.nix b/modules/plugins/assistant/chatgpt/default.nix new file mode 100644 index 0000000..0f23771 --- /dev/null +++ b/modules/plugins/assistant/chatgpt/default.nix @@ -0,0 +1,6 @@ +{ + imports = [ + ./chatgpt.nix + ./config.nix + ]; +} diff --git a/modules/plugins/assistant/default.nix b/modules/plugins/assistant/default.nix index 3521c52..5b5cf32 100644 --- a/modules/plugins/assistant/default.nix +++ b/modules/plugins/assistant/default.nix @@ -1,5 +1,6 @@ { imports = [ + ./chatgpt ./copilot ]; }