Merge pull request #501 from devchat-ai/feature/bilingual-quick-fix-support-#351

Add Bilingual Support for Quick Fix Prompts in VSCode Plugin
This commit is contained in:
boob.yang 2024-04-18 12:00:22 +08:00 committed by GitHub
commit 2ed9698d35
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -429,18 +429,26 @@ export function registerQuickFixCommand(context: vscode.ExtensionContext) {
async (diagnosticMessage: string, code: string, surroundingCode: string) => { async (diagnosticMessage: string, code: string, surroundingCode: string) => {
ensureChatPanel(context); ensureChatPanel(context);
if (!ExtensionContextHolder.provider?.view()) { if (!ExtensionContextHolder.provider?.view()) {
// wait 2 seconds await waitForPanelActivation();
await new Promise((resolve, reject) => {
setTimeout(() => {
resolve(true);
}, 2000);
});
} }
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); chatWithDevChat(ExtensionContextHolder.provider?.view()!, prompt);
} }
); );
context.subscriptions.push(disposable); 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" ? "结果输出请使用中文。" : ""} `;
} }