Skip to content

Commit a9695fe

Browse files
authored
Merge pull request #566 from devchat-ai/optimize_fix_it
Refactor and Fix: Async Updates and Error Handling
2 parents 549528b + 8433c54 commit a9695fe

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

gui

src/contributes/commands.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ export function registerFixCommand(context: vscode.ExtensionContext) {
349349
);
350350
}
351351

352-
export function registerQuickFixCommand(context: vscode.ExtensionContext) {
352+
export async function registerQuickFixCommand(context: vscode.ExtensionContext) {
353353
let disposable = vscode.commands.registerCommand(
354354
"DevChat.quickFix",
355355
async (diagnosticMessage: string, code: string, surroundingCode: string) => {
@@ -359,7 +359,7 @@ export function registerQuickFixCommand(context: vscode.ExtensionContext) {
359359
}
360360

361361
const language = DevChatConfig.getInstance().get('language');
362-
const prompt = generatePrompt(code, surroundingCode, diagnosticMessage, language);
362+
const prompt = await generatePrompt(code, surroundingCode, diagnosticMessage, language);
363363
chatWithDevChat(ExtensionContextHolder.provider?.view()!, prompt);
364364
}
365365
);
@@ -375,6 +375,19 @@ async function waitForPanelActivation() {
375375
});
376376
}
377377

378-
function generatePrompt(code: string, surroundingCode: string, diagnosticMessage: string, language: string) {
379-
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" ? "结果输出请使用中文。" : ""} `;
378+
async function generatePrompt(code: string, surroundingCode: string, diagnosticMessage: string, language: string) {
379+
const editor = vscode.window.activeTextEditor;
380+
if (editor) {
381+
const selectedText = editor.document.getText(editor.selection);
382+
await sendCodeSelectMessage(
383+
ExtensionContextHolder.provider?.view()!,
384+
editor.document.fileName,
385+
code,
386+
0
387+
);
388+
// wait 1 second
389+
await new Promise((resolve) => setTimeout(resolve, 1000));
390+
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" ? "结果输出请使用中文。" : ""} `;
391+
}
392+
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" ? "结果输出请使用中文。" : ""} `;
380393
}

0 commit comments

Comments
 (0)