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 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..42a51831 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