From 76771f139237b70aeb091babf5c2ac922f1e1381 Mon Sep 17 00:00:00 2001 From: "bobo.yang" Date: Tue, 18 Jun 2024 15:18:05 +0800 Subject: [PATCH 1/2] fix: Add async to registerQuickFixCommand and generatePrompt - Modified registerQuickFixCommand to be an async function - Updated generatePrompt to also be async and handle active editor context - Improved error handling and context management in prompt generation --- src/contributes/commands.ts | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/contributes/commands.ts b/src/contributes/commands.ts index b11eef8..0bf656e 100644 --- a/src/contributes/commands.ts +++ b/src/contributes/commands.ts @@ -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" ? "结果输出请使用中文。" : ""} `; } \ No newline at end of file From 8433c5422059d169f13321994c738c6a100acdf2 Mon Sep 17 00:00:00 2001 From: "bobo.yang" Date: Tue, 18 Jun 2024 15:18:38 +0800 Subject: [PATCH 2/2] Refactor subproject commit in gui --- gui | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gui b/gui index d9703da..a8d20e4 160000 --- a/gui +++ b/gui @@ -1 +1 @@ -Subproject commit d9703da439055b8a503449d78acb7c9aa27966d3 +Subproject commit a8d20e4cd5fd27a7206b7fb982dad3a9f004b999