Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 16 additions & 18 deletions src/activate/CodeActionProvider.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
import * as vscode from "vscode"

import { CodeActionName, CodeActionId } from "@roo-code/types"
import { CodeActionId } from "@roo-code/types"
import { Package } from "../shared/package"

import { getCodeActionCommand } from "../utils/commands"
import { EditorUtils } from "../integrations/editor/EditorUtils"

export const TITLES: Record<CodeActionName, string> = {
EXPLAIN: "Explain with Zoo Code",
FIX: "Fix with Zoo Code",
IMPROVE: "Improve with Zoo Code",
ADD_TO_CONTEXT: "Add to Zoo Code",
NEW_TASK: "New Roo Code Task",
} as const
import { t } from "../i18n"

export class CodeActionProvider implements vscode.CodeActionProvider {
public static readonly providedCodeActionKinds = [
Expand Down Expand Up @@ -51,12 +44,17 @@ export class CodeActionProvider implements vscode.CodeActionProvider {
const actions: vscode.CodeAction[] = []

actions.push(
this.createAction(TITLES.ADD_TO_CONTEXT, vscode.CodeActionKind.QuickFix, "addToContext", [
filePath,
effectiveRange.text,
effectiveRange.range.start.line + 1,
effectiveRange.range.end.line + 1,
]),
this.createAction(
t("common:codeActions.addToContext"),
vscode.CodeActionKind.QuickFix,
"addToContext",
[
filePath,
effectiveRange.text,
effectiveRange.range.start.line + 1,
effectiveRange.range.end.line + 1,
],
),
)

if (context.diagnostics.length > 0) {
Expand All @@ -66,7 +64,7 @@ export class CodeActionProvider implements vscode.CodeActionProvider {

if (relevantDiagnostics.length > 0) {
actions.push(
this.createAction(TITLES.FIX, vscode.CodeActionKind.QuickFix, "fixCode", [
this.createAction(t("common:codeActions.fix"), vscode.CodeActionKind.QuickFix, "fixCode", [
filePath,
effectiveRange.text,
effectiveRange.range.start.line + 1,
Expand All @@ -77,7 +75,7 @@ export class CodeActionProvider implements vscode.CodeActionProvider {
}
} else {
actions.push(
this.createAction(TITLES.EXPLAIN, vscode.CodeActionKind.QuickFix, "explainCode", [
this.createAction(t("common:codeActions.explain"), vscode.CodeActionKind.QuickFix, "explainCode", [
filePath,
effectiveRange.text,
effectiveRange.range.start.line + 1,
Expand All @@ -86,7 +84,7 @@ export class CodeActionProvider implements vscode.CodeActionProvider {
)

actions.push(
this.createAction(TITLES.IMPROVE, vscode.CodeActionKind.QuickFix, "improveCode", [
this.createAction(t("common:codeActions.improve"), vscode.CodeActionKind.QuickFix, "improveCode", [
filePath,
effectiveRange.text,
effectiveRange.range.start.line + 1,
Expand Down
24 changes: 18 additions & 6 deletions src/activate/__tests__/CodeActionProvider.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,19 @@ import * as vscode from "vscode"

import { EditorUtils } from "../../integrations/editor/EditorUtils"

import { CodeActionProvider, TITLES } from "../CodeActionProvider"
import { CodeActionProvider } from "../CodeActionProvider"

vi.mock("../../i18n", () => ({
t: vi.fn((key: string) => {
const translations: Record<string, string> = {
"common:codeActions.explain": "Explain with Zoo Code",
"common:codeActions.fix": "Fix with Zoo Code",
"common:codeActions.improve": "Improve with Zoo Code",
"common:codeActions.addToContext": "Add to Zoo Code",
}
return translations[key] || key
}),
}))

vi.mock("vscode", () => ({
CodeAction: vi.fn().mockImplementation((title, kind) => ({
Expand Down Expand Up @@ -74,9 +86,9 @@ describe("CodeActionProvider", () => {
const actions = provider.provideCodeActions(mockDocument, mockRange, mockContext)

expect(actions).toHaveLength(3)
expect((actions as any)[0].title).toBe(TITLES.ADD_TO_CONTEXT)
expect((actions as any)[1].title).toBe(TITLES.EXPLAIN)
expect((actions as any)[2].title).toBe(TITLES.IMPROVE)
expect((actions as any)[0].title).toBe("Add to Zoo Code")
expect((actions as any)[1].title).toBe("Explain with Zoo Code")
expect((actions as any)[2].title).toBe("Improve with Zoo Code")
})

it("should provide fix action instead of fix logic when diagnostics exist", () => {
Expand All @@ -87,8 +99,8 @@ describe("CodeActionProvider", () => {
const actions = provider.provideCodeActions(mockDocument, mockRange, mockContext)

expect(actions).toHaveLength(2)
expect((actions as any).some((a: any) => a.title === `${TITLES.FIX}`)).toBe(true)
expect((actions as any).some((a: any) => a.title === `${TITLES.ADD_TO_CONTEXT}`)).toBe(true)
expect((actions as any).some((a: any) => a.title === "Fix with Zoo Code")).toBe(true)
expect((actions as any).some((a: any) => a.title === "Add to Zoo Code")).toBe(true)
})

it("should return empty array when no effective range", () => {
Expand Down
6 changes: 6 additions & 0 deletions src/i18n/locales/ca/common.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/i18n/locales/de/common.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/i18n/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -259,5 +259,11 @@
"connected": "Zoo Code: Successfully connected! You can now use Zoo Code as your AI provider.",
"disconnected": "Zoo Code: Disconnected successfully."
}
},
"codeActions": {
"explain": "Explain with Zoo Code",
"fix": "Fix with Zoo Code",
"improve": "Improve with Zoo Code",
"addToContext": "Add to Zoo Code"
}
}
6 changes: 6 additions & 0 deletions src/i18n/locales/es/common.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/i18n/locales/fr/common.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/i18n/locales/hi/common.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/i18n/locales/id/common.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/i18n/locales/it/common.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/i18n/locales/ja/common.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/i18n/locales/ko/common.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/i18n/locales/nl/common.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/i18n/locales/pl/common.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/i18n/locales/pt-BR/common.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/i18n/locales/ru/common.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/i18n/locales/tr/common.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/i18n/locales/vi/common.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/i18n/locales/zh-CN/common.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/i18n/locales/zh-TW/common.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading