Merge pull request #566 from devchat-ai/optimize_fix_it

Refactor and Fix: Async Updates and Error Handling
This commit is contained in:
boob.yang 2024-06-18 15:22:41 +08:00 committed by GitHub
commit a9695fe9b2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 18 additions and 5 deletions

2
gui

@ -1 +1 @@
Subproject commit d9703da439055b8a503449d78acb7c9aa27966d3
Subproject commit a8d20e4cd5fd27a7206b7fb982dad3a9f004b999

View File

@ -349,7 +349,7 @@ export function registerFixCommand(context: vscode.ExtensionContext) {
);
}
export function registerQuickFixCommand(context: vscode.ExtensionContext) {
export async function registerQuickFixCommand(context: vscode.ExtensionContext) {
let disposable = vscode.commands.registerCommand(
"DevChat.quickFix",
async (diagnosticMessage: string, code: string, surroundingCode: string) => {
@ -359,7 +359,7 @@ export function registerQuickFixCommand(context: vscode.ExtensionContext) {
}
const language = DevChatConfig.getInstance().get('language');
const prompt = generatePrompt(code, surroundingCode, diagnosticMessage, language);
const prompt = await generatePrompt(code, surroundingCode, diagnosticMessage, language);
chatWithDevChat(ExtensionContextHolder.provider?.view()!, prompt);
}
);
@ -375,6 +375,19 @@ async function waitForPanelActivation() {
});
}
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" ? "结果输出请使用中文。" : ""} `;
async function generatePrompt(code: string, surroundingCode: string, diagnosticMessage: string, language: string) {
const editor = vscode.window.activeTextEditor;
if (editor) {
const selectedText = editor.document.getText(editor.selection);
await sendCodeSelectMessage(
ExtensionContextHolder.provider?.view()!,
editor.document.fileName,
code,
0
);
// wait 1 second
await new Promise((resolve) => setTimeout(resolve, 1000));
return `Context code is current edit file.\n\nThere is an error in the context 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" ? "结果输出请使用中文。" : ""} `;
}
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" ? "结果输出请使用中文。" : ""} `;
}