Skip to content

Commit 61fb096

Browse files
committed
Add new/existing task for all three actions
1 parent 85c49d8 commit 61fb096

File tree

4 files changed

+51
-33
lines changed

4 files changed

+51
-33
lines changed

src/core/CodeActionProvider.ts

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,12 @@ import { ClineProvider } from "./webview/ClineProvider"
55
export const ACTION_NAMES = {
66
EXPLAIN: "Roo Code: Explain Code",
77
FIX: "Roo Code: Fix Code",
8-
FIX_IN_CURRENT_TASK: "Roo Code: Fix Code in Current Task",
98
IMPROVE: "Roo Code: Improve Code",
109
} as const
1110

1211
const COMMAND_IDS = {
1312
EXPLAIN: "roo-cline.explainCode",
1413
FIX: "roo-cline.fixCode",
15-
FIX_IN_CURRENT_TASK: "roo-cline.fixCodeInCurrentTask",
1614
IMPROVE: "roo-cline.improveCode",
1715
} as const
1816

@@ -116,6 +114,18 @@ export class CodeActionProvider implements vscode.CodeActionProvider {
116114
return action
117115
}
118116

117+
private createActionPair(
118+
baseTitle: string,
119+
kind: vscode.CodeActionKind,
120+
baseCommand: string,
121+
args: any[],
122+
): vscode.CodeAction[] {
123+
return [
124+
this.createAction(`${baseTitle} in New Task`, kind, baseCommand, args),
125+
this.createAction(`${baseTitle} in Current Task`, kind, `${baseCommand}InCurrentTask`, args),
126+
]
127+
}
128+
119129
private hasIntersectingRange(range1: vscode.Range, range2: vscode.Range): boolean {
120130
// Optimize range intersection check
121131
return !(
@@ -141,8 +151,9 @@ export class CodeActionProvider implements vscode.CodeActionProvider {
141151
const actions: vscode.CodeAction[] = []
142152

143153
// Create actions using helper method
154+
// Add explain actions
144155
actions.push(
145-
this.createAction(ACTION_NAMES.EXPLAIN, vscode.CodeActionKind.QuickFix, COMMAND_IDS.EXPLAIN, [
156+
...this.createActionPair(ACTION_NAMES.EXPLAIN, vscode.CodeActionKind.QuickFix, COMMAND_IDS.EXPLAIN, [
146157
filePath,
147158
effectiveRange.text,
148159
]),
@@ -157,27 +168,23 @@ export class CodeActionProvider implements vscode.CodeActionProvider {
157168
if (relevantDiagnostics.length > 0) {
158169
const diagnosticMessages = relevantDiagnostics.map(this.createDiagnosticData)
159170
actions.push(
160-
this.createAction(ACTION_NAMES.FIX, vscode.CodeActionKind.QuickFix, COMMAND_IDS.FIX, [
171+
...this.createActionPair(ACTION_NAMES.FIX, vscode.CodeActionKind.QuickFix, COMMAND_IDS.FIX, [
161172
filePath,
162173
effectiveRange.text,
163174
diagnosticMessages,
164175
]),
165-
166-
this.createAction(
167-
ACTION_NAMES.FIX_IN_CURRENT_TASK,
168-
vscode.CodeActionKind.QuickFix,
169-
COMMAND_IDS.FIX_IN_CURRENT_TASK,
170-
[filePath, effectiveRange.text, diagnosticMessages],
171-
),
172176
)
173177
}
174178
}
175179

180+
// Add improve actions
176181
actions.push(
177-
this.createAction(ACTION_NAMES.IMPROVE, vscode.CodeActionKind.RefactorRewrite, COMMAND_IDS.IMPROVE, [
178-
filePath,
179-
effectiveRange.text,
180-
]),
182+
...this.createActionPair(
183+
ACTION_NAMES.IMPROVE,
184+
vscode.CodeActionKind.RefactorRewrite,
185+
COMMAND_IDS.IMPROVE,
186+
[filePath, effectiveRange.text],
187+
),
181188
)
182189

183190
return actions

src/core/__tests__/CodeActionProvider.test.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as vscode from "vscode"
2-
import { CodeActionProvider } from "../CodeActionProvider"
2+
import { CodeActionProvider, ACTION_NAMES } from "../CodeActionProvider"
33

44
// Mock VSCode API
55
jest.mock("vscode", () => ({
@@ -109,9 +109,11 @@ describe("CodeActionProvider", () => {
109109
it("should provide explain and improve actions by default", () => {
110110
const actions = provider.provideCodeActions(mockDocument, mockRange, mockContext)
111111

112-
expect(actions).toHaveLength(2)
113-
expect((actions as any)[0].title).toBe("Roo Code: Explain Code")
114-
expect((actions as any)[1].title).toBe("Roo Code: Improve Code")
112+
expect(actions).toHaveLength(4)
113+
expect((actions as any)[0].title).toBe(`${ACTION_NAMES.EXPLAIN} in New Task`)
114+
expect((actions as any)[1].title).toBe(`${ACTION_NAMES.EXPLAIN} in Current Task`)
115+
expect((actions as any)[2].title).toBe(`${ACTION_NAMES.IMPROVE} in New Task`)
116+
expect((actions as any)[3].title).toBe(`${ACTION_NAMES.IMPROVE} in Current Task`)
115117
})
116118

117119
it("should provide fix action when diagnostics exist", () => {
@@ -125,8 +127,9 @@ describe("CodeActionProvider", () => {
125127

126128
const actions = provider.provideCodeActions(mockDocument, mockRange, mockContext)
127129

128-
expect(actions).toHaveLength(4)
129-
expect((actions as any).some((a: any) => a.title === "Roo Code: Fix Code")).toBe(true)
130+
expect(actions).toHaveLength(6)
131+
expect((actions as any).some((a: any) => a.title === `${ACTION_NAMES.FIX} in New Task`)).toBe(true)
132+
expect((actions as any).some((a: any) => a.title === `${ACTION_NAMES.FIX} in Current Task`)).toBe(true)
130133
})
131134

132135
it("should handle errors gracefully", () => {

src/core/webview/ClineProvider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ export class ClineProvider implements vscode.WebviewViewProvider {
234234

235235
const prompt = supportPrompt.create(promptType, params, customSupportPrompts)
236236

237-
if (visibleProvider.cline && ["roo-cline.fixCodeInCurrentTask"].indexOf(command) !== -1) {
237+
if (visibleProvider.cline && command.endsWith("InCurrentTask")) {
238238
await visibleProvider.postMessageToWebview({
239239
type: "invoke",
240240
invoke: "sendMessage",

src/extension.ts

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ export function activate(context: vscode.ExtensionContext) {
171171
context: vscode.ExtensionContext,
172172
command: string,
173173
promptType: keyof typeof ACTION_NAMES,
174+
inNewTask: boolean,
174175
inputPrompt?: string,
175176
inputPlaceholder?: string,
176177
) => {
@@ -200,32 +201,39 @@ export function activate(context: vscode.ExtensionContext) {
200201
)
201202
}
202203

204+
// Helper function to register both versions of a code action
205+
const registerCodeActionPair = (
206+
context: vscode.ExtensionContext,
207+
baseCommand: string,
208+
promptType: keyof typeof ACTION_NAMES,
209+
inputPrompt?: string,
210+
inputPlaceholder?: string,
211+
) => {
212+
// Register new task version
213+
registerCodeAction(context, baseCommand, promptType, true, inputPrompt, inputPlaceholder)
214+
215+
// Register current task version
216+
registerCodeAction(context, `${baseCommand}InCurrentTask`, promptType, false, inputPrompt, inputPlaceholder)
217+
}
218+
203219
// Register code action commands
204-
registerCodeAction(
220+
registerCodeActionPair(
205221
context,
206222
"roo-cline.explainCode",
207223
"EXPLAIN",
208224
"What would you like Roo to explain?",
209225
"E.g. How does the error handling work?",
210226
)
211227

212-
registerCodeAction(
228+
registerCodeActionPair(
213229
context,
214230
"roo-cline.fixCode",
215231
"FIX",
216232
"What would you like Roo to fix?",
217233
"E.g. Maintain backward compatibility",
218234
)
219235

220-
registerCodeAction(
221-
context,
222-
"roo-cline.fixCodeInCurrentTask",
223-
"FIX", // keep this for use the same prompt with FIX command
224-
"What would you like Roo to fix?",
225-
"E.g. Maintain backward compatibility",
226-
)
227-
228-
registerCodeAction(
236+
registerCodeActionPair(
229237
context,
230238
"roo-cline.improveCode",
231239
"IMPROVE",

0 commit comments

Comments
 (0)