Просмотр исходного кода

Follow the established pattern for command registration

cte 9 месяцев назад
Родитель
Сommit
5a3c20764a
4 измененных файлов с 77 добавлено и 92 удалено
  1. 30 27
      README.md
  2. 26 0
      src/activate/humanRelay.ts
  3. 16 16
      src/activate/registerCommands.ts
  4. 5 49
      src/extension.ts

+ 30 - 27
README.md

@@ -115,37 +115,40 @@ Make Roo Code work your way with:
 ## Local Setup & Development
 ## Local Setup & Development
 
 
 1. **Clone** the repo:
 1. **Clone** the repo:
-    ```bash
-    git clone https://github.com/RooVetGit/Roo-Code.git
-    ```
+
+```sh
+git clone https://github.com/RooVetGit/Roo-Code.git
+```
+
 2. **Install dependencies**:
 2. **Install dependencies**:
-    ```bash
-    npm run install:all
-    ```
-
-if that fails, try:
-    ```bash
-    npm run install:ci
-    ```
-
-3. **Build** the extension:
-    ```bash
-    npm run build
-    ```
-    - A `.vsix` file will appear in the `bin/` directory.
-4. **Install** the `.vsix` manually if desired:
-    ```bash
-    code --install-extension bin/roo-code-4.0.0.vsix
-    ```
-5. **Start the webview (Vite/React app with HMR)**:
-    ```bash
-    npm run dev
-    ```
-6. **Debug**:
-    - Press `F5` (or **Run** → **Start Debugging**) in VSCode to open a new session with Roo Code loaded.
+
+```sh
+npm run install:all
+```
+
+3. **Start the webview (Vite/React app with HMR)**:
+
+```sh
+npm run dev
+```
+
+4. **Debug**:
+   Press `F5` (or **Run** → **Start Debugging**) in VSCode to open a new session with Roo Code loaded.
 
 
 Changes to the webview will appear immediately. Changes to the core extension will require a restart of the extension host.
 Changes to the webview will appear immediately. Changes to the core extension will require a restart of the extension host.
 
 
+Alternatively you can build a .vsix and install it directly in VSCode:
+
+```sh
+npm run build
+```
+
+A `.vsix` file will appear in the `bin/` directory which can be installed with:
+
+```sh
+code --install-extension bin/roo-cline-<version>.vsix
+```
+
 We use [changesets](https://github.com/changesets/changesets) for versioning and publishing. Check our `CHANGELOG.md` for release notes.
 We use [changesets](https://github.com/changesets/changesets) for versioning and publishing. Check our `CHANGELOG.md` for release notes.
 
 
 ---
 ---

+ 26 - 0
src/activate/humanRelay.ts

@@ -0,0 +1,26 @@
+// Callback mapping of human relay response.
+const humanRelayCallbacks = new Map<string, (response: string | undefined) => void>()
+
+/**
+ * Register a callback function for human relay response.
+ * @param requestId
+ * @param callback
+ */
+export const registerHumanRelayCallback = (requestId: string, callback: (response: string | undefined) => void) =>
+	humanRelayCallbacks.set(requestId, callback)
+
+export const unregisterHumanRelayCallback = (requestId: string) => humanRelayCallbacks.delete(requestId)
+
+export const handleHumanRelayResponse = (response: { requestId: string; text?: string; cancelled?: boolean }) => {
+	const callback = humanRelayCallbacks.get(response.requestId)
+
+	if (callback) {
+		if (response.cancelled) {
+			callback(undefined)
+		} else {
+			callback(response.text)
+		}
+
+		humanRelayCallbacks.delete(response.requestId)
+	}
+}

+ 16 - 16
src/activate/registerCommands.ts

@@ -3,6 +3,8 @@ import delay from "delay"
 
 
 import { ClineProvider } from "../core/webview/ClineProvider"
 import { ClineProvider } from "../core/webview/ClineProvider"
 
 
+import { registerHumanRelayCallback, unregisterHumanRelayCallback, handleHumanRelayResponse } from "./humanRelay"
+
 // Store panel references in both modes
 // Store panel references in both modes
 let sidebarPanel: vscode.WebviewView | undefined = undefined
 let sidebarPanel: vscode.WebviewView | undefined = undefined
 let tabPanel: vscode.WebviewPanel | undefined = undefined
 let tabPanel: vscode.WebviewPanel | undefined = undefined
@@ -43,22 +45,6 @@ export const registerCommands = (options: RegisterCommandOptions) => {
 	for (const [command, callback] of Object.entries(getCommandsMap(options))) {
 	for (const [command, callback] of Object.entries(getCommandsMap(options))) {
 		context.subscriptions.push(vscode.commands.registerCommand(command, callback))
 		context.subscriptions.push(vscode.commands.registerCommand(command, callback))
 	}
 	}
-
-	// Human Relay Dialog Command
-	context.subscriptions.push(
-		vscode.commands.registerCommand(
-			"roo-cline.showHumanRelayDialog",
-			(params: { requestId: string; promptText: string }) => {
-				if (getPanel()) {
-					getPanel()?.webview.postMessage({
-						type: "showHumanRelayDialog",
-						requestId: params.requestId,
-						promptText: params.promptText,
-					})
-				}
-			},
-		),
-	)
 }
 }
 
 
 const getCommandsMap = ({ context, outputChannel, provider }: RegisterCommandOptions) => {
 const getCommandsMap = ({ context, outputChannel, provider }: RegisterCommandOptions) => {
@@ -85,6 +71,20 @@ const getCommandsMap = ({ context, outputChannel, provider }: RegisterCommandOpt
 		"roo-cline.helpButtonClicked": () => {
 		"roo-cline.helpButtonClicked": () => {
 			vscode.env.openExternal(vscode.Uri.parse("https://docs.roocode.com"))
 			vscode.env.openExternal(vscode.Uri.parse("https://docs.roocode.com"))
 		},
 		},
+		"roo-cline.showHumanRelayDialog": (params: { requestId: string; promptText: string }) => {
+			const panel = getPanel()
+
+			if (panel) {
+				panel?.webview.postMessage({
+					type: "showHumanRelayDialog",
+					requestId: params.requestId,
+					promptText: params.promptText,
+				})
+			}
+		},
+		"roo-cline.registerHumanRelayCallback": registerHumanRelayCallback,
+		"roo-cline.unregisterHumanRelayCallback": unregisterHumanRelayCallback,
+		"roo-cline.handleHumanRelayResponse": handleHumanRelayResponse,
 	}
 	}
 }
 }
 
 

+ 5 - 49
src/extension.ts

@@ -11,15 +11,17 @@ try {
 	console.warn("Failed to load environment variables:", e)
 	console.warn("Failed to load environment variables:", e)
 }
 }
 
 
-import { ClineProvider } from "./core/webview/ClineProvider"
-import { createClineAPI } from "./exports"
 import "./utils/path" // Necessary to have access to String.prototype.toPosix.
 import "./utils/path" // Necessary to have access to String.prototype.toPosix.
+
+import { createClineAPI } from "./exports"
+import { ClineProvider } from "./core/webview/ClineProvider"
 import { CodeActionProvider } from "./core/CodeActionProvider"
 import { CodeActionProvider } from "./core/CodeActionProvider"
 import { DIFF_VIEW_URI_SCHEME } from "./integrations/editor/DiffViewProvider"
 import { DIFF_VIEW_URI_SCHEME } from "./integrations/editor/DiffViewProvider"
-import { handleUri, registerCommands, registerCodeActions } from "./activate"
 import { McpServerManager } from "./services/mcp/McpServerManager"
 import { McpServerManager } from "./services/mcp/McpServerManager"
 import { telemetryService } from "./services/telemetry/TelemetryService"
 import { telemetryService } from "./services/telemetry/TelemetryService"
 
 
+import { handleUri, registerCommands, registerCodeActions } from "./activate"
+
 /**
 /**
  * Built using https://github.com/microsoft/vscode-webview-ui-toolkit
  * Built using https://github.com/microsoft/vscode-webview-ui-toolkit
  *
  *
@@ -31,18 +33,6 @@ import { telemetryService } from "./services/telemetry/TelemetryService"
 let outputChannel: vscode.OutputChannel
 let outputChannel: vscode.OutputChannel
 let extensionContext: vscode.ExtensionContext
 let extensionContext: vscode.ExtensionContext
 
 
-// Callback mapping of human relay response
-const humanRelayCallbacks = new Map<string, (response: string | undefined) => void>()
-
-/**
- * Register a callback function for human relay response
- * @param requestId
- * @param callback
- */
-export function registerHumanRelayCallback(requestId: string, callback: (response: string | undefined) => void): void {
-	humanRelayCallbacks.set(requestId, callback)
-}
-
 // This method is called when your extension is activated.
 // This method is called when your extension is activated.
 // Your extension is activated the very first time the command is executed.
 // Your extension is activated the very first time the command is executed.
 export function activate(context: vscode.ExtensionContext) {
 export function activate(context: vscode.ExtensionContext) {
@@ -72,40 +62,6 @@ export function activate(context: vscode.ExtensionContext) {
 
 
 	registerCommands({ context, outputChannel, provider: sidebarProvider })
 	registerCommands({ context, outputChannel, provider: sidebarProvider })
 
 
-	// Register human relay callback registration command
-	context.subscriptions.push(
-		vscode.commands.registerCommand(
-			"roo-cline.registerHumanRelayCallback",
-			(requestId: string, callback: (response: string | undefined) => void) => {
-				registerHumanRelayCallback(requestId, callback)
-			},
-		),
-	)
-
-	// Register human relay response processing command
-	context.subscriptions.push(
-		vscode.commands.registerCommand(
-			"roo-cline.handleHumanRelayResponse",
-			(response: { requestId: string; text?: string; cancelled?: boolean }) => {
-				const callback = humanRelayCallbacks.get(response.requestId)
-				if (callback) {
-					if (response.cancelled) {
-						callback(undefined)
-					} else {
-						callback(response.text)
-					}
-					humanRelayCallbacks.delete(response.requestId)
-				}
-			},
-		),
-	)
-
-	context.subscriptions.push(
-		vscode.commands.registerCommand("roo-cline.unregisterHumanRelayCallback", (requestId: string) => {
-			humanRelayCallbacks.delete(requestId)
-		}),
-	)
-
 	/**
 	/**
 	 * We use the text document content provider API to show the left side for diff
 	 * We use the text document content provider API to show the left side for diff
 	 * view by creating a virtual document for the original content. This makes it
 	 * view by creating a virtual document for the original content. This makes it