|
1 | 1 | import * as vscode from "vscode" |
2 | | -import delay from "delay" |
| 2 | +import { openClineInNewTab } from "../integrations/tab/OpenTab" |
3 | 3 |
|
4 | 4 | import { ClineProvider } from "../core/webview/ClineProvider" |
5 | 5 |
|
6 | | -import { registerHumanRelayCallback, unregisterHumanRelayCallback, handleHumanRelayResponse } from "./humanRelay" |
| 6 | +import { handleHumanRelayResponse, registerHumanRelayCallback, unregisterHumanRelayCallback } from "./humanRelay" |
7 | 7 |
|
8 | 8 | // Store panel references in both modes |
9 | 9 | let sidebarPanel: vscode.WebviewView | undefined = undefined |
@@ -39,14 +39,25 @@ export type RegisterCommandOptions = { |
39 | 39 | provider: ClineProvider |
40 | 40 | } |
41 | 41 |
|
42 | | -export const registerCommands = (options: RegisterCommandOptions) => { |
| 42 | +/** |
| 43 | + * Registers all commands for the extension. |
| 44 | + * @param {RegisterCommandOptions} options The options to register commands with. |
| 45 | + * @returns {void} |
| 46 | + */ |
| 47 | +export const registerCommands = (options: RegisterCommandOptions): void => { |
43 | 48 | const { context, outputChannel } = options |
44 | 49 |
|
45 | 50 | for (const [command, callback] of Object.entries(getCommandsMap(options))) { |
46 | 51 | context.subscriptions.push(vscode.commands.registerCommand(command, callback)) |
47 | 52 | } |
48 | 53 | } |
49 | 54 |
|
| 55 | +/** |
| 56 | + * Generates a map of command names to functions that handle those commands. |
| 57 | + * |
| 58 | + * @param {RegisterCommandOptions} options The options to register commands with. |
| 59 | + * @returns {Record<string, (...args: any[]) => void>} A map of command names to functions. |
| 60 | + */ |
50 | 61 | const getCommandsMap = ({ context, outputChannel, provider }: RegisterCommandOptions) => { |
51 | 62 | return { |
52 | 63 | "roo-cline.plusButtonClicked": async () => { |
@@ -87,49 +98,3 @@ const getCommandsMap = ({ context, outputChannel, provider }: RegisterCommandOpt |
87 | 98 | "roo-cline.handleHumanRelayResponse": handleHumanRelayResponse, |
88 | 99 | } |
89 | 100 | } |
90 | | - |
91 | | -const openClineInNewTab = async ({ context, outputChannel }: Omit<RegisterCommandOptions, "provider">) => { |
92 | | - // (This example uses webviewProvider activation event which is necessary to |
93 | | - // deserialize cached webview, but since we use retainContextWhenHidden, we |
94 | | - // don't need to use that event). |
95 | | - // https://github.com/microsoft/vscode-extension-samples/blob/main/webview-sample/src/extension.ts |
96 | | - const tabProvider = new ClineProvider(context, outputChannel, "editor") |
97 | | - const lastCol = Math.max(...vscode.window.visibleTextEditors.map((editor) => editor.viewColumn || 0)) |
98 | | - |
99 | | - // Check if there are any visible text editors, otherwise open a new group |
100 | | - // to the right. |
101 | | - const hasVisibleEditors = vscode.window.visibleTextEditors.length > 0 |
102 | | - |
103 | | - if (!hasVisibleEditors) { |
104 | | - await vscode.commands.executeCommand("workbench.action.newGroupRight") |
105 | | - } |
106 | | - |
107 | | - const targetCol = hasVisibleEditors ? Math.max(lastCol + 1, 1) : vscode.ViewColumn.Two |
108 | | - |
109 | | - const newPanel = vscode.window.createWebviewPanel(ClineProvider.tabPanelId, "Roo Code", targetCol, { |
110 | | - enableScripts: true, |
111 | | - retainContextWhenHidden: true, |
112 | | - localResourceRoots: [context.extensionUri], |
113 | | - }) |
114 | | - |
115 | | - // Save as tab type panel. |
116 | | - setPanel(newPanel, "tab") |
117 | | - |
118 | | - // TODO: Use better svg icon with light and dark variants (see |
119 | | - // https://stackoverflow.com/questions/58365687/vscode-extension-iconpath). |
120 | | - newPanel.iconPath = { |
121 | | - light: vscode.Uri.joinPath(context.extensionUri, "assets", "icons", "rocket.png"), |
122 | | - dark: vscode.Uri.joinPath(context.extensionUri, "assets", "icons", "rocket.png"), |
123 | | - } |
124 | | - |
125 | | - await tabProvider.resolveWebviewView(newPanel) |
126 | | - |
127 | | - // Handle panel closing events. |
128 | | - newPanel.onDidDispose(() => { |
129 | | - setPanel(undefined, "tab") |
130 | | - }) |
131 | | - |
132 | | - // Lock the editor group so clicking on files doesn't open them over the panel. |
133 | | - await delay(100) |
134 | | - await vscode.commands.executeCommand("workbench.action.lockEditorGroup") |
135 | | -} |
0 commit comments