Skip to content

Commit 2831337

Browse files
committed
refactor: Simplify quick fix command implementation
- Refactor quick fix command to use document, range, and diagnostic - Remove code collapsing and surrounding code extraction - Update command arguments to pass document, range, and diagnostic
1 parent 2b5412b commit 2831337

File tree

2 files changed

+9
-16
lines changed

2 files changed

+9
-16
lines changed

src/contributes/commands.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -352,15 +352,17 @@ export function registerFixCommand(context: vscode.ExtensionContext) {
352352
export async function registerQuickFixCommand(context: vscode.ExtensionContext) {
353353
let disposable = vscode.commands.registerCommand(
354354
"DevChat.quickFix",
355-
async (diagnosticMessage: string, code: string, surroundingCode: string) => {
355+
async (document: vscode.TextDocument, range: vscode.Range | vscode.Selection, diagnostic: vscode.Diagnostic) => {
356356
ensureChatPanel(context);
357357
if (!ExtensionContextHolder.provider?.view()) {
358358
await waitForPanelActivation();
359359
}
360360

361-
const language = DevChatConfig.getInstance().get('language');
362-
const prompt = await generatePrompt(code, surroundingCode, diagnosticMessage, language);
363-
chatWithDevChat(ExtensionContextHolder.provider?.view()!, prompt);
361+
// select the code
362+
const editor = vscode.window.activeTextEditor;
363+
editor!.selection = new vscode.Selection(range.start, range.end);
364+
365+
chatWithDevChat(ExtensionContextHolder.provider?.view()!, "/fix_issue ");
364366
}
365367
);
366368

src/contributes/quickFixProvider.ts

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,13 @@ class DevChatQuickFixProvider implements vscode.CodeActionProvider {
2424
quickFix.isPreferred = false;
2525

2626
return new Promise(async (resolve) => {
27-
const code = await collapseFileExculdeSelectRange(document.uri.fsPath, document.getText(), range.start.line, range.end.line);
28-
29-
const surroundingRange = new vscode.Range(
30-
Math.max(0, range.start.line - 3),
31-
0,
32-
Math.min(document.lineCount, range.end.line + 3),
33-
0,
34-
);
35-
3627
quickFix.command = {
3728
command: "DevChat.quickFix",
3829
title: "DevChat Quick Fix",
3930
arguments: [
40-
diagnostic.message,
41-
code,
42-
document.getText(surroundingRange)
31+
document,
32+
range,
33+
diagnostic,
4334
],
4435
};
4536

0 commit comments

Comments
 (0)