From c2bb0181b8cb58dbbd6fe6a145b46b6f86feecbe Mon Sep 17 00:00:00 2001 From: neutrinoA4 Date: Sat, 16 Mar 2024 14:52:14 +0900 Subject: [PATCH 1/3] Language settings for copilot answers --- lua/CopilotChat/config.lua | 2 ++ lua/CopilotChat/init.lua | 13 +++++++++++++ lua/CopilotChat/prompts.lua | 6 ++++++ 3 files changed, 21 insertions(+) diff --git a/lua/CopilotChat/config.lua b/lua/CopilotChat/config.lua index 842bb4db..702972db 100644 --- a/lua/CopilotChat/config.lua +++ b/lua/CopilotChat/config.lua @@ -50,6 +50,7 @@ local select = require('CopilotChat.select') ---@field proxy string? ---@field allow_insecure boolean? ---@field debug boolean? +---@field language string? ---@field show_user_selection boolean? ---@field show_system_prompt boolean? ---@field show_folds boolean? @@ -76,6 +77,7 @@ return { auto_follow_cursor = true, -- Auto-follow cursor in chat name = 'CopilotChat', -- Name to use in chat separator = '---', -- Separator to use in chat + language = nil, -- Copilot answer language settings when using default prompts. Default language is English. -- default prompts prompts = { Explain = { diff --git a/lua/CopilotChat/init.lua b/lua/CopilotChat/init.lua index f993c023..186bae12 100644 --- a/lua/CopilotChat/init.lua +++ b/lua/CopilotChat/init.lua @@ -396,10 +396,23 @@ function M.debug(debug) log.logfile = logfile end +--- Set up the language for default prompts +---@param config CopilotChat.config|nil +function M.setup_copilot_language(config) + if not config or not config.language then + return + end + + for _, prompt in pairs(config.prompts) do + prompt.prompt = prompt.prompt .. " " .. prompts.PROMPT_ANSWER_LANGUAGE_TEMPLATE(config.language) + end +end + --- Set up the plugin ---@param config CopilotChat.config|nil function M.setup(config) M.config = vim.tbl_deep_extend('force', default_config, config or {}) + M.setup_copilot_language(M.config) state.copilot = Copilot(M.config.proxy, M.config.allow_insecure) state.diff = Diff( diff --git a/lua/CopilotChat/prompts.lua b/lua/CopilotChat/prompts.lua index bc2737a3..1e374571 100644 --- a/lua/CopilotChat/prompts.lua +++ b/lua/CopilotChat/prompts.lua @@ -175,4 +175,10 @@ M.SHOW_CONTEXT = [[ At the beginning of your response show code outline from all the provided files coming from Context and Active Selection. ]] +---Prompt for the user to provide a language +--- @param language string +function M.PROMPT_ANSWER_LANGUAGE_TEMPLATE(language) + return string.format([[Please answer in %s.]], language) +end + return M From 6c2a055c9abe14d82bad3f3ae16236a036a669c6 Mon Sep 17 00:00:00 2001 From: neutrinoA4 Date: Sat, 16 Mar 2024 15:07:10 +0900 Subject: [PATCH 2/3] Add language settings to README --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 79de9011..e2ef0849 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,7 @@ return { }, opts = { debug = true, -- Enable debugging + -- language = "English" -- Copilot answer language settings when using default prompts. Default language is English. -- See Configuration section for rest }, -- See Commands section for default commands if you want to lazy load on them From 5966d8c1d8b94126c7581494f9809a86cbf2ab3a Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 16 Mar 2024 06:13:23 +0000 Subject: [PATCH 3/3] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- lua/CopilotChat/init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/CopilotChat/init.lua b/lua/CopilotChat/init.lua index 186bae12..42a51831 100644 --- a/lua/CopilotChat/init.lua +++ b/lua/CopilotChat/init.lua @@ -404,7 +404,7 @@ function M.setup_copilot_language(config) end for _, prompt in pairs(config.prompts) do - prompt.prompt = prompt.prompt .. " " .. prompts.PROMPT_ANSWER_LANGUAGE_TEMPLATE(config.language) + prompt.prompt = prompt.prompt .. ' ' .. prompts.PROMPT_ANSWER_LANGUAGE_TEMPLATE(config.language) end end