Skip to content

Commit 71bdc7e

Browse files
author
aheizi
committed
feat: add command to switch mode
1 parent 1c9dcad commit 71bdc7e

File tree

7 files changed

+1112
-1022
lines changed

7 files changed

+1112
-1022
lines changed

package.json

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,11 @@
153153
"command": "roo-cline.terminalExplainCommandInCurrentTask",
154154
"title": "Roo Code: Explain This Command (Current Task)",
155155
"category": "Terminal"
156+
},
157+
{
158+
"command": "roo-cline.cycleModes",
159+
"title": "Cycle Through Modes",
160+
"category": "Roo Code"
156161
}
157162
],
158163
"menus": {
@@ -271,7 +276,17 @@
271276
"description": "Settings for VSCode Language Model API"
272277
}
273278
}
274-
}
279+
},
280+
"keybindings": [
281+
{
282+
"command": "roo-cline.cycleModes",
283+
"key": ".",
284+
"win": "ctrl+.",
285+
"linux": "ctrl+.",
286+
"mac": "cmd+.",
287+
"when": "true"
288+
}
289+
]
275290
},
276291
"scripts": {
277292
"build": "npm run build:webview && npm run vsix",

src/commands/mode-switching.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import * as vscode from "vscode"
2+
import { modes } from "../shared/modes"
3+
import { ClineProvider } from "../core/webview/ClineProvider"
4+
5+
export function registerModeSwitchingCommands(context: vscode.ExtensionContext) {
6+
let currentModeIndex = 0
7+
8+
context.subscriptions.push(
9+
vscode.commands.registerCommand("roo-cline.cycleModes", async () => {
10+
try {
11+
// Get next mode index
12+
currentModeIndex = (currentModeIndex + 1) % modes.length
13+
const nextMode = modes[currentModeIndex]
14+
15+
// Get visible instance and send message
16+
const provider = await ClineProvider.getInstance()
17+
if (provider) {
18+
await provider.postMessageToWebview({
19+
type: "mode",
20+
text: nextMode.slug,
21+
})
22+
}
23+
24+
vscode.window.showInformationMessage(`Switched to ${nextMode.name} mode`)
25+
} catch (error) {
26+
vscode.window.showErrorMessage(`Failed to switch mode: ${error}`)
27+
}
28+
}),
29+
)
30+
}

src/extension.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { CodeActionProvider } from "./core/CodeActionProvider"
77
import { DIFF_VIEW_URI_SCHEME } from "./integrations/editor/DiffViewProvider"
88
import { handleUri, registerCommands, registerCodeActions, registerTerminalActions } from "./activate"
99
import { McpServerManager } from "./services/mcp/McpServerManager"
10+
import { registerModeSwitchingCommands } from "./commands/mode-switching"
1011

1112
/**
1213
* Built using https://github.com/microsoft/vscode-webview-ui-toolkit
@@ -83,6 +84,9 @@ export function activate(context: vscode.ExtensionContext) {
8384
registerCodeActions(context)
8485
registerTerminalActions(context)
8586

87+
// Register mode switching commands
88+
registerModeSwitchingCommands(context)
89+
8690
return createClineAPI(outputChannel, sidebarProvider)
8791
}
8892

src/services/checkpoints/__tests__/ShadowCheckpointService.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ jest.mock("globby", () => ({
1313
globby: jest.fn().mockResolvedValue([]),
1414
}))
1515

16+
// Set timeout for all tests
17+
jest.setTimeout(30000)
18+
1619
describe("ShadowCheckpointService", () => {
1720
const taskId = "test-task"
1821

src/shared/ExtensionMessage.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export interface ExtensionMessage {
2020
type:
2121
| "action"
2222
| "state"
23+
| "mode"
2324
| "selectedImages"
2425
| "ollamaModels"
2526
| "lmStudioModels"

webview-ui/src/App.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const App = () => {
2727
const [showAnnouncement, setShowAnnouncement] = useState(false)
2828
const [tab, setTab] = useState<Tab>("chat")
2929
const settingsRef = useRef<SettingsViewRef>(null)
30+
const chatViewRef = useRef<any>(null)
3031

3132
const switchTab = useCallback((newTab: Tab) => {
3233
if (settingsRef.current?.checkUnsaveChanges) {
@@ -47,8 +48,18 @@ const App = () => {
4748
switchTab(newTab)
4849
}
4950
}
51+
52+
if (message.type === "mode" && message.text) {
53+
console.log("Received mode switch message:", message.text)
54+
if (tab !== "chat") {
55+
switchTab("chat")
56+
}
57+
if (chatViewRef.current?.switchMode) {
58+
chatViewRef.current.switchMode(message.text)
59+
}
60+
}
5061
},
51-
[switchTab],
62+
[switchTab, tab],
5263
)
5364

5465
useEvent("message", onMessage)
@@ -75,6 +86,7 @@ const App = () => {
7586
{tab === "mcp" && <McpView onDone={() => switchTab("chat")} />}
7687
{tab === "prompts" && <PromptsView onDone={() => switchTab("chat")} />}
7788
<ChatView
89+
ref={chatViewRef}
7890
isHidden={tab !== "chat"}
7991
showAnnouncement={showAnnouncement}
8092
hideAnnouncement={() => setShowAnnouncement(false)}

0 commit comments

Comments
 (0)