From 741aa60efee9a12b1e425db19c06f57a3efbe721 Mon Sep 17 00:00:00 2001 From: "bobo.yang" Date: Thu, 18 Apr 2024 11:57:46 +0800 Subject: [PATCH] feat: Add bilingual support for Quick Fix prompts - Refactored delay in Quick Fix activation to a dedicated function - Implemented language-specific prompt generation in Quick Fixes - Added Chinese language support alongside English for Quick Fix guidance --- src/contributes/commands.ts | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/contributes/commands.ts b/src/contributes/commands.ts index bd9c983..0abd02a 100644 --- a/src/contributes/commands.ts +++ b/src/contributes/commands.ts @@ -429,18 +429,26 @@ export function registerQuickFixCommand(context: vscode.ExtensionContext) { async (diagnosticMessage: string, code: string, surroundingCode: string) => { ensureChatPanel(context); if (!ExtensionContextHolder.provider?.view()) { - // wait 2 seconds - await new Promise((resolve, reject) => { - setTimeout(() => { - resolve(true); - }, 2000); - }); + await waitForPanelActivation(); } - const prompt = `current edit file is:\n\`\`\`\n${code}\n\`\`\`\n\nThere is an error in the above code:\n\`\`\`\n${surroundingCode}\n\`\`\`\n\nHow do I fix this problem in the above code?: ${diagnosticMessage}`; + const language = DevChatConfig.getInstance().get('language'); + const prompt = generatePrompt(code, surroundingCode, diagnosticMessage, language); chatWithDevChat(ExtensionContextHolder.provider?.view()!, prompt); } ); context.subscriptions.push(disposable); +} + +async function waitForPanelActivation() { + return new Promise((resolve) => { + setTimeout(() => { + resolve(true); + }, 2000); + }); +} + +function generatePrompt(code: string, surroundingCode: string, diagnosticMessage: string, language: string) { + return `current edit file is:\n\`\`\`\n${code}\n\`\`\`\n\nThere is an error in the above code:\n\`\`\`\n${surroundingCode}\n\`\`\`\n\nHow do I fix this problem in the above code?: ${diagnosticMessage}, please output steps to fix it. ${language === "zh" ? "结果输出请使用中文。" : ""} `; } \ No newline at end of file