diff --git a/package.json b/package.json index aff831b..5187cca 100644 --- a/package.json +++ b/package.json @@ -170,8 +170,13 @@ "category": "DevChat" }, { - "command": "DevChat.quickFix", - "title": "DevChat Quick Fix", + "command": "DevChat.quickFixAskDevChat", + "title": "Ask DevChat", + "category": "DevChat" + }, + { + "command": "DevChat.quickFixUsingDevChat", + "title": "Ask DevChat", "category": "DevChat" } ], @@ -224,7 +229,11 @@ "when": "false" }, { - "command": "DevChat.quickFix", + "command": "DevChat.quickFixAskDevChat", + "when": "false" + }, + { + "command": "DevChat.quickFixUsingDevChat", "when": "false" }, { diff --git a/src/contributes/commands.ts b/src/contributes/commands.ts index 23969a9..46bb95f 100644 --- a/src/contributes/commands.ts +++ b/src/contributes/commands.ts @@ -375,7 +375,7 @@ export function registerFixCommand(context: vscode.ExtensionContext) { export async function registerQuickFixCommand(context: vscode.ExtensionContext) { let disposable = vscode.commands.registerCommand( - "DevChat.quickFix", + "DevChat.quickFixAskDevChat", async (document: vscode.TextDocument, range: vscode.Range | vscode.Selection, diagnostic: vscode.Diagnostic) => { ensureChatPanel(context); if (!ExtensionContextHolder.provider?.view()) { @@ -386,11 +386,27 @@ export async function registerQuickFixCommand(context: vscode.ExtensionContext) const editor = vscode.window.activeTextEditor; editor!.selection = new vscode.Selection(range.start, range.end); - chatWithDevChat(ExtensionContextHolder.provider?.view()!, "/fix_issue "); + chatWithDevChat(ExtensionContextHolder.provider?.view()!, "/ask_issue "); } ); + let disposableFixUsingDevChat = vscode.commands.registerCommand( + "DevChat.quickFixUsingDevChat", + async (document: vscode.TextDocument, range: vscode.Range | vscode.Selection, diagnostic: vscode.Diagnostic) => { + ensureChatPanel(context); + if (!ExtensionContextHolder.provider?.view()) { + await waitForPanelActivation(); + } + + // select the code + const editor = vscode.window.activeTextEditor; + editor!.selection = new vscode.Selection(range.start, range.end); + + chatWithDevChat(ExtensionContextHolder.provider?.view()!, "/fix_issue "); + } +); context.subscriptions.push(disposable); + context.subscriptions.push(disposableFixUsingDevChat); } async function waitForPanelActivation() { diff --git a/src/contributes/quickFixProvider.ts b/src/contributes/quickFixProvider.ts index 3e24fce..dfe443e 100644 --- a/src/contributes/quickFixProvider.ts +++ b/src/contributes/quickFixProvider.ts @@ -23,10 +23,16 @@ class DevChatQuickFixProvider implements vscode.CodeActionProvider { ); quickFix.isPreferred = false; + const fixUsingDevChat = new vscode.CodeAction( + "Fix using DevChat", + vscode.CodeActionKind.QuickFix, + ); + fixUsingDevChat.isPreferred = true; + return new Promise(async (resolve) => { quickFix.command = { - command: "DevChat.quickFix", - title: "DevChat Quick Fix", + command: "DevChat.quickFixAskDevChat", + title: "Ask DevChat", arguments: [ document, range, @@ -34,7 +40,17 @@ class DevChatQuickFixProvider implements vscode.CodeActionProvider { ], }; - resolve([quickFix]); + fixUsingDevChat.command = { + command: "DevChat.quickFixUsingDevChat", + title: "Fix using DevChat", + arguments: [ + document, + range, + diagnostic, + ], + }; + + resolve([quickFix, fixUsingDevChat]); }); } } @@ -47,5 +63,4 @@ export default function registerQuickFixProvider() { providedCodeActionKinds: DevChatQuickFixProvider.providedCodeActionKinds, }, ); -} - +} \ No newline at end of file