Skip to content

Commit 611b994

Browse files
committed
Add back "Improve"
1 parent cbb912d commit 611b994

File tree

4 files changed

+42
-21
lines changed

4 files changed

+42
-21
lines changed

src/activate/registerCodeActions.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { ClineProvider } from "../core/webview/ClineProvider"
77
export const registerCodeActions = (context: vscode.ExtensionContext) => {
88
registerCodeAction(context, COMMAND_IDS.EXPLAIN, "EXPLAIN")
99
registerCodeAction(context, COMMAND_IDS.FIX, "FIX")
10+
registerCodeAction(context, COMMAND_IDS.IMPROVE, "IMPROVE")
1011
registerCodeAction(context, COMMAND_IDS.ADD_TO_CONTEXT, "ADD_TO_CONTEXT")
1112
}
1213

src/core/CodeActionProvider.ts

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,27 @@ import * as vscode from "vscode"
22

33
import { EditorUtils } from "./EditorUtils"
44

5-
export type CodeActionName = "EXPLAIN" | "FIX" | "ADD_TO_CONTEXT" | "NEW_TASK"
5+
export type CodeActionName = "EXPLAIN" | "FIX" | "IMPROVE" | "ADD_TO_CONTEXT" | "NEW_TASK"
66

77
export type CodeActionId =
88
| "roo-cline.explainCode"
99
| "roo-cline.fixCode"
10+
| "roo-cline.improveCode"
1011
| "roo-cline.addToContext"
1112
| "roo-cline.newTask"
1213

13-
export const ACTION_NAMES: Record<CodeActionName, string> = {
14+
export const ACTION_TITLES: Record<CodeActionName, string> = {
1415
EXPLAIN: "Explain with Roo Code",
1516
FIX: "Fix with Roo Code",
17+
IMPROVE: "Improve with Roo Code",
1618
ADD_TO_CONTEXT: "Add to Roo Code",
1719
NEW_TASK: "New Roo Code Task",
1820
} as const
1921

2022
export const COMMAND_IDS: Record<CodeActionName, CodeActionId> = {
2123
EXPLAIN: "roo-cline.explainCode",
2224
FIX: "roo-cline.fixCode",
25+
IMPROVE: "roo-cline.improveCode",
2326
ADD_TO_CONTEXT: "roo-cline.addToContext",
2427
NEW_TASK: "roo-cline.newTask",
2528
} as const
@@ -30,7 +33,12 @@ export class CodeActionProvider implements vscode.CodeActionProvider {
3033
vscode.CodeActionKind.RefactorRewrite,
3134
]
3235

33-
private createAction(title: string, kind: vscode.CodeActionKind, command: string, args: any[]): vscode.CodeAction {
36+
private createAction(
37+
title: string,
38+
kind: vscode.CodeActionKind,
39+
command: CodeActionId,
40+
args: any[],
41+
): vscode.CodeAction {
3442
const action = new vscode.CodeAction(title, kind)
3543
action.command = { command, title, arguments: args }
3644
return action
@@ -53,7 +61,7 @@ export class CodeActionProvider implements vscode.CodeActionProvider {
5361

5462
actions.push(
5563
this.createAction(
56-
ACTION_NAMES.ADD_TO_CONTEXT,
64+
ACTION_TITLES.ADD_TO_CONTEXT,
5765
vscode.CodeActionKind.QuickFix,
5866
COMMAND_IDS.ADD_TO_CONTEXT,
5967
[
@@ -65,23 +73,14 @@ export class CodeActionProvider implements vscode.CodeActionProvider {
6573
),
6674
)
6775

68-
actions.push(
69-
this.createAction(ACTION_NAMES.EXPLAIN, vscode.CodeActionKind.QuickFix, COMMAND_IDS.EXPLAIN, [
70-
filePath,
71-
effectiveRange.text,
72-
effectiveRange.range.start.line + 1,
73-
effectiveRange.range.end.line + 1,
74-
]),
75-
)
76-
7776
if (context.diagnostics.length > 0) {
7877
const relevantDiagnostics = context.diagnostics.filter((d) =>
7978
EditorUtils.hasIntersectingRange(effectiveRange.range, d.range),
8079
)
8180

8281
if (relevantDiagnostics.length > 0) {
8382
actions.push(
84-
this.createAction(ACTION_NAMES.FIX, vscode.CodeActionKind.QuickFix, COMMAND_IDS.FIX, [
83+
this.createAction(ACTION_TITLES.FIX, vscode.CodeActionKind.QuickFix, COMMAND_IDS.FIX, [
8584
filePath,
8685
effectiveRange.text,
8786
effectiveRange.range.start.line + 1,
@@ -90,6 +89,24 @@ export class CodeActionProvider implements vscode.CodeActionProvider {
9089
]),
9190
)
9291
}
92+
} else {
93+
actions.push(
94+
this.createAction(ACTION_TITLES.EXPLAIN, vscode.CodeActionKind.QuickFix, COMMAND_IDS.EXPLAIN, [
95+
filePath,
96+
effectiveRange.text,
97+
effectiveRange.range.start.line + 1,
98+
effectiveRange.range.end.line + 1,
99+
]),
100+
)
101+
102+
actions.push(
103+
this.createAction(ACTION_TITLES.IMPROVE, vscode.CodeActionKind.QuickFix, COMMAND_IDS.IMPROVE, [
104+
filePath,
105+
effectiveRange.text,
106+
effectiveRange.range.start.line + 1,
107+
effectiveRange.range.end.line + 1,
108+
]),
109+
)
93110
}
94111

95112
return actions

src/core/__tests__/CodeActionProvider.test.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import * as vscode from "vscode"
44

55
import { EditorUtils } from "../EditorUtils"
66

7-
import { CodeActionProvider, ACTION_NAMES } from "../CodeActionProvider"
7+
import { CodeActionProvider, ACTION_TITLES } from "../CodeActionProvider"
88

99
// Mock VSCode API
1010
jest.mock("vscode", () => ({
@@ -78,8 +78,10 @@ describe("CodeActionProvider", () => {
7878
it("should provide explain, improve, fix logic, and add to context actions by default", () => {
7979
const actions = provider.provideCodeActions(mockDocument, mockRange, mockContext)
8080

81-
expect(actions).toHaveLength(1)
82-
expect((actions as any)[0].title).toBe(ACTION_NAMES.ADD_TO_CONTEXT)
81+
expect(actions).toHaveLength(3)
82+
expect((actions as any)[0].title).toBe(ACTION_TITLES.ADD_TO_CONTEXT)
83+
expect((actions as any)[1].title).toBe(ACTION_TITLES.EXPLAIN)
84+
expect((actions as any)[2].title).toBe(ACTION_TITLES.IMPROVE)
8385
})
8486

8587
it("should provide fix action instead of fix logic when diagnostics exist", () => {
@@ -90,8 +92,8 @@ describe("CodeActionProvider", () => {
9092
const actions = provider.provideCodeActions(mockDocument, mockRange, mockContext)
9193

9294
expect(actions).toHaveLength(2)
93-
expect((actions as any).some((a: any) => a.title === `${ACTION_NAMES.FIX}`)).toBe(true)
94-
expect((actions as any).some((a: any) => a.title === `${ACTION_NAMES.ADD_TO_CONTEXT}`)).toBe(true)
95+
expect((actions as any).some((a: any) => a.title === `${ACTION_TITLES.FIX}`)).toBe(true)
96+
expect((actions as any).some((a: any) => a.title === `${ACTION_TITLES.ADD_TO_CONTEXT}`)).toBe(true)
9597
})
9698

9799
it("should return empty array when no effective range", () => {

src/core/webview/ClineProvider.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ import { ContextProxy } from "../config/ContextProxy"
4141
import { ProviderSettingsManager } from "../config/ProviderSettingsManager"
4242
import { CustomModesManager } from "../config/CustomModesManager"
4343
import { buildApiHandler } from "../../api"
44-
import { ACTION_NAMES } from "../CodeActionProvider"
44+
import { CodeActionName } from "../CodeActionProvider"
4545
import { Cline, ClineOptions } from "../Cline"
4646
import { getNonce } from "./getNonce"
4747
import { getUri } from "./getUri"
@@ -262,7 +262,7 @@ export class ClineProvider extends EventEmitter<ClineProviderEvents> implements
262262

263263
public static async handleCodeAction(
264264
command: string,
265-
promptType: keyof typeof ACTION_NAMES,
265+
promptType: CodeActionName,
266266
params: Record<string, string | any[]>,
267267
): Promise<void> {
268268
// Capture telemetry for code action usage
@@ -276,6 +276,7 @@ export class ClineProvider extends EventEmitter<ClineProviderEvents> implements
276276

277277
const { customSupportPrompts } = await visibleProvider.getState()
278278

279+
// TODO: Improve type safety for promptType.
279280
const prompt = supportPrompt.create(promptType, params, customSupportPrompts)
280281

281282
if (command.endsWith("addToContext")) {

0 commit comments

Comments
 (0)