Skip to content

Commit f274a15

Browse files
authored
Get package publisher and name from package.json + command type safety (#3766)
1 parent ff837d5 commit f274a15

39 files changed

+379
-253
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ mock/
1313

1414
# Builds
1515
bin/
16-
roo-cline-*.vsix
16+
*.vsix
1717

1818
# Local prompts and rules
1919
/local-prompts

e2e/package-lock.json

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

e2e/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
"build": "rimraf out && tsc -p tsconfig.json",
1111
"vscode-test": "cd .. && npm run vscode-test"
1212
},
13-
"dependencies": {},
1413
"devDependencies": {
14+
"@roo-code/types": "^1.12.0",
1515
"@types/mocha": "^10.0.10",
1616
"@vscode/test-cli": "^0.0.10",
1717
"@vscode/test-electron": "^2.4.0",

e2e/src/suite/extension.test.ts

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,47 @@
11
import * as assert from "assert"
22
import * as vscode from "vscode"
33

4+
import { Package } from "@roo-code/types"
5+
46
suite("Roo Code Extension", () => {
57
test("Commands should be registered", async () => {
68
const expectedCommands = [
7-
"roo-cline.plusButtonClicked",
8-
"roo-cline.mcpButtonClicked",
9-
"roo-cline.historyButtonClicked",
10-
"roo-cline.popoutButtonClicked",
11-
"roo-cline.settingsButtonClicked",
12-
"roo-cline.openInNewTab",
13-
"roo-cline.explainCode",
14-
"roo-cline.fixCode",
15-
"roo-cline.improveCode",
9+
"SidebarProvider.open",
10+
"SidebarProvider.focus",
11+
"SidebarProvider.resetViewLocation",
12+
"SidebarProvider.toggleVisibility",
13+
"SidebarProvider.removeView",
14+
"activationCompleted",
15+
"plusButtonClicked",
16+
"mcpButtonClicked",
17+
"promptsButtonClicked",
18+
"popoutButtonClicked",
19+
"openInNewTab",
20+
"settingsButtonClicked",
21+
"historyButtonClicked",
22+
"showHumanRelayDialog",
23+
"registerHumanRelayCallback",
24+
"unregisterHumanRelayCallback",
25+
"handleHumanRelayResponse",
26+
"newTask",
27+
"setCustomStoragePath",
28+
"focusInput",
29+
"acceptInput",
30+
"explainCode",
31+
"fixCode",
32+
"improveCode",
33+
"addToContext",
34+
"terminalAddToContext",
35+
"terminalFixCommand",
36+
"terminalExplainCommand",
1637
]
1738

18-
const commands = await vscode.commands.getCommands(true)
39+
const commands = new Set(
40+
(await vscode.commands.getCommands(true)).filter((cmd) => cmd.startsWith(Package.name)),
41+
)
1942

20-
for (const cmd of expectedCommands) {
21-
assert.ok(commands.includes(cmd), `Command ${cmd} should be registered`)
43+
for (const command of expectedCommands) {
44+
assert.ok(commands.has(`${Package.name}.${command}`), `Command ${command} should be registered`)
2245
}
2346
})
2447
})

e2e/src/suite/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import Mocha from "mocha"
33
import { glob } from "glob"
44
import * as vscode from "vscode"
55

6-
import type { RooCodeAPI } from "../../../src/exports/roo-code"
6+
import { type RooCodeAPI, Package } from "@roo-code/types"
77

88
import { waitFor } from "./utils"
99

@@ -12,7 +12,7 @@ declare global {
1212
}
1313

1414
export async function run() {
15-
const extension = vscode.extensions.getExtension<RooCodeAPI>("RooVeterinaryInc.roo-cline")
15+
const extension = vscode.extensions.getExtension<RooCodeAPI>(`${Package.publisher}.${Package.name}`)
1616

1717
if (!extension) {
1818
throw new Error("Extension not found")
@@ -26,7 +26,7 @@ export async function run() {
2626
openRouterModelId: "google/gemini-2.0-flash-001",
2727
})
2828

29-
await vscode.commands.executeCommand("roo-cline.SidebarProvider.focus")
29+
await vscode.commands.executeCommand(`${Package.name}.SidebarProvider.focus`)
3030
await waitFor(() => api.isReady())
3131

3232
// Expose the API to the tests.

e2e/src/suite/modes.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as assert from "assert"
22

3-
import type { ClineMessage } from "../../../src/exports/roo-code"
3+
import type { ClineMessage } from "@roo-code/types"
44

55
import { waitUntilCompleted } from "./utils"
66

e2e/src/suite/subtasks.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as assert from "assert"
22

3-
import type { ClineMessage } from "../../../src/exports/roo-code"
3+
import type { ClineMessage } from "@roo-code/types"
44

55
import { sleep, waitFor, waitUntilCompleted } from "./utils"
66

e2e/src/suite/task.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as assert from "assert"
22

3-
import type { ClineMessage } from "../../../src/exports/roo-code"
3+
import type { ClineMessage } from "@roo-code/types"
44

55
import { waitUntilCompleted } from "./utils"
66

e2e/src/suite/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { RooCodeAPI } from "../../../src/exports/roo-code"
1+
import type { RooCodeAPI } from "@roo-code/types"
22

33
type WaitForOptions = {
44
timeout?: number

src/activate/CodeActionProvider.ts

Lines changed: 13 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,17 @@
11
import * as vscode from "vscode"
22

3+
import { CodeActionName, CodeActionId } from "../schemas"
4+
import { getCodeActionCommand } from "../utils/commands"
35
import { EditorUtils } from "../integrations/editor/EditorUtils"
46

5-
export type CodeActionName = "EXPLAIN" | "FIX" | "IMPROVE" | "ADD_TO_CONTEXT" | "NEW_TASK"
6-
7-
export type CodeActionId =
8-
| "roo-cline.explainCode"
9-
| "roo-cline.fixCode"
10-
| "roo-cline.improveCode"
11-
| "roo-cline.addToContext"
12-
| "roo-cline.newTask"
13-
14-
export const ACTION_TITLES: Record<CodeActionName, string> = {
7+
export const TITLES: Record<CodeActionName, string> = {
158
EXPLAIN: "Explain with Roo Code",
169
FIX: "Fix with Roo Code",
1710
IMPROVE: "Improve with Roo Code",
1811
ADD_TO_CONTEXT: "Add to Roo Code",
1912
NEW_TASK: "New Roo Code Task",
2013
} as const
2114

22-
export const COMMAND_IDS: Record<CodeActionName, CodeActionId> = {
23-
EXPLAIN: "roo-cline.explainCode",
24-
FIX: "roo-cline.fixCode",
25-
IMPROVE: "roo-cline.improveCode",
26-
ADD_TO_CONTEXT: "roo-cline.addToContext",
27-
NEW_TASK: "roo-cline.newTask",
28-
} as const
29-
3015
export class CodeActionProvider implements vscode.CodeActionProvider {
3116
public static readonly providedCodeActionKinds = [
3217
vscode.CodeActionKind.QuickFix,
@@ -40,7 +25,7 @@ export class CodeActionProvider implements vscode.CodeActionProvider {
4025
args: any[],
4126
): vscode.CodeAction {
4227
const action = new vscode.CodeAction(title, kind)
43-
action.command = { command, title, arguments: args }
28+
action.command = { command: getCodeActionCommand(command), title, arguments: args }
4429
return action
4530
}
4631

@@ -60,17 +45,12 @@ export class CodeActionProvider implements vscode.CodeActionProvider {
6045
const actions: vscode.CodeAction[] = []
6146

6247
actions.push(
63-
this.createAction(
64-
ACTION_TITLES.ADD_TO_CONTEXT,
65-
vscode.CodeActionKind.QuickFix,
66-
COMMAND_IDS.ADD_TO_CONTEXT,
67-
[
68-
filePath,
69-
effectiveRange.text,
70-
effectiveRange.range.start.line + 1,
71-
effectiveRange.range.end.line + 1,
72-
],
73-
),
48+
this.createAction(TITLES.ADD_TO_CONTEXT, vscode.CodeActionKind.QuickFix, "addToContext", [
49+
filePath,
50+
effectiveRange.text,
51+
effectiveRange.range.start.line + 1,
52+
effectiveRange.range.end.line + 1,
53+
]),
7454
)
7555

7656
if (context.diagnostics.length > 0) {
@@ -80,7 +60,7 @@ export class CodeActionProvider implements vscode.CodeActionProvider {
8060

8161
if (relevantDiagnostics.length > 0) {
8262
actions.push(
83-
this.createAction(ACTION_TITLES.FIX, vscode.CodeActionKind.QuickFix, COMMAND_IDS.FIX, [
63+
this.createAction(TITLES.FIX, vscode.CodeActionKind.QuickFix, "fixCode", [
8464
filePath,
8565
effectiveRange.text,
8666
effectiveRange.range.start.line + 1,
@@ -91,7 +71,7 @@ export class CodeActionProvider implements vscode.CodeActionProvider {
9171
}
9272
} else {
9373
actions.push(
94-
this.createAction(ACTION_TITLES.EXPLAIN, vscode.CodeActionKind.QuickFix, COMMAND_IDS.EXPLAIN, [
74+
this.createAction(TITLES.EXPLAIN, vscode.CodeActionKind.QuickFix, "explainCode", [
9575
filePath,
9676
effectiveRange.text,
9777
effectiveRange.range.start.line + 1,
@@ -100,7 +80,7 @@ export class CodeActionProvider implements vscode.CodeActionProvider {
10080
)
10181

10282
actions.push(
103-
this.createAction(ACTION_TITLES.IMPROVE, vscode.CodeActionKind.QuickFix, COMMAND_IDS.IMPROVE, [
83+
this.createAction(TITLES.IMPROVE, vscode.CodeActionKind.QuickFix, "improveCode", [
10484
filePath,
10585
effectiveRange.text,
10686
effectiveRange.range.start.line + 1,

0 commit comments

Comments
 (0)