diff --git a/src/core/CodeActionProvider.ts b/src/core/CodeActionProvider.ts index d3b980a..3d50d02 100644 --- a/src/core/CodeActionProvider.ts +++ b/src/core/CodeActionProvider.ts @@ -1,15 +1,18 @@ import * as vscode from "vscode" import * as path from "path" +import { ClineProvider } from "./webview/ClineProvider" export const ACTION_NAMES = { EXPLAIN: "Roo Code: Explain Code", FIX: "Roo Code: Fix Code", + FIX_IN_CURRENT_TASK: "Roo Code: Fix Code in Current Task", IMPROVE: "Roo Code: Improve Code", } as const const COMMAND_IDS = { EXPLAIN: "roo-cline.explainCode", FIX: "roo-cline.fixCode", + FIX_IN_CURRENT_TASK: "roo-cline.fixCodeInCurrentTask", IMPROVE: "roo-cline.improveCode", } as const @@ -159,6 +162,13 @@ export class CodeActionProvider implements vscode.CodeActionProvider { effectiveRange.text, diagnosticMessages, ]), + + this.createAction( + ACTION_NAMES.FIX_IN_CURRENT_TASK, + vscode.CodeActionKind.QuickFix, + COMMAND_IDS.FIX_IN_CURRENT_TASK, + [filePath, effectiveRange.text, diagnosticMessages], + ), ) } } diff --git a/src/core/__tests__/CodeActionProvider.test.ts b/src/core/__tests__/CodeActionProvider.test.ts index d0bfc8e..0af3991 100644 --- a/src/core/__tests__/CodeActionProvider.test.ts +++ b/src/core/__tests__/CodeActionProvider.test.ts @@ -125,7 +125,7 @@ describe("CodeActionProvider", () => { const actions = provider.provideCodeActions(mockDocument, mockRange, mockContext) - expect(actions).toHaveLength(3) + expect(actions).toHaveLength(4) expect((actions as any).some((a: any) => a.title === "Roo Code: Fix Code")).toBe(true) }) diff --git a/src/core/webview/ClineProvider.ts b/src/core/webview/ClineProvider.ts index 45368e0..b656ab0 100644 --- a/src/core/webview/ClineProvider.ts +++ b/src/core/webview/ClineProvider.ts @@ -188,10 +188,7 @@ export class ClineProvider implements vscode.WebviewViewProvider { return findLast(Array.from(this.activeInstances), (instance) => instance.view?.visible === true) } - public static async handleCodeAction( - promptType: keyof typeof ACTION_NAMES, - params: Record, - ): Promise { + public static async getInstance(): Promise { let visibleProvider = ClineProvider.getVisibleInstance() // If no visible provider, try to show the sidebar view @@ -207,10 +204,46 @@ export class ClineProvider implements vscode.WebviewViewProvider { return } + return visibleProvider + } + + public static async isActiveTask(): Promise { + const visibleProvider = await ClineProvider.getInstance() + if (!visibleProvider) { + return false + } + + if (visibleProvider.cline) { + return true + } + + return false + } + + public static async handleCodeAction( + command: string, + promptType: keyof typeof ACTION_NAMES, + params: Record, + ): Promise { + const visibleProvider = await ClineProvider.getInstance() + if (!visibleProvider) { + return + } + const { customSupportPrompts } = await visibleProvider.getState() const prompt = supportPrompt.create(promptType, params, customSupportPrompts) + if (visibleProvider.cline && ["roo-cline.fixCodeInCurrentTask"].indexOf(command) !== -1) { + await visibleProvider.postMessageToWebview({ + type: "invoke", + invoke: "sendMessage", + text: prompt, + }) + + return + } + await visibleProvider.initClineWithTask(prompt) } diff --git a/src/extension.ts b/src/extension.ts index 5e0dbb0..20b122c 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -194,7 +194,7 @@ export function activate(context: vscode.ExtensionContext) { ...(userInput ? { userInput } : {}), } - await ClineProvider.handleCodeAction(promptType, params) + await ClineProvider.handleCodeAction(command, promptType, params) }, ), ) @@ -217,6 +217,14 @@ export function activate(context: vscode.ExtensionContext) { "E.g. Maintain backward compatibility", ) + registerCodeAction( + context, + "roo-cline.fixCodeInCurrentTask", + "FIX", // keep this for use the same prompt with FIX command + "What would you like Roo to fix?", + "E.g. Maintain backward compatibility", + ) + registerCodeAction( context, "roo-cline.improveCode",