From 45636c39e5158b1fbe106d3abf85cd94cf857c91 Mon Sep 17 00:00:00 2001 From: Chris Hasson Date: Wed, 7 May 2025 13:35:10 -0700 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat(extension):=20add=20auto-reloa?= =?UTF-8?q?d=20for=20core=20changes=20in=20dev=20mode?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously, devs would need to restart the extension host to see core changes. Now, with this change, we monitor the files within the core directory. If any changes are detected, we trigger a reload command within the extension, effectively enabling auto-reloading within the extension Dev notes I was originally going to make this a new env var something like ENABLE_CORE_AUTO_RESTART, but instead just based it on the NODE_ENV. Let me know if you think the env var would be better! (or something else!) - enhance development experience by eliminating manual restarts - implement file system watcher for core files - automatically reload extension host on changes Test plan: Verified running the extension locally that changes to `src` reload the window in dev. --- CONTRIBUTING.md | 3 ++- src/extension.ts | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index e734d4a977c..7e92dd4e345 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -178,7 +178,8 @@ Follow these steps for coding and submitting your work. 3. **Run Webview (Dev Mode)**: `npm run dev` (for Vite/React app with HMR) 4. **Debug Extension**: Press `F5` in VS Code (or **Run** → **Start Debugging**) to open a new Extension Development Host window with Roo Code loaded. -Webview changes (in `webview-ui`) will appear immediately with Hot Module Replacement. Changes to the core extension (in `src`) will require a restart of the Extension Development Host. +Webview changes (in `webview-ui`) will appear immediately with Hot Module Replacement. +In development mode (NODE_ENV="development"), changing the core code (in `src`) will trigger a `workbench.action.reloadWindow` command, so it is no longer necessary to manually restart the Extension Development Host. Alternatively, to build and install a `.vsix` package: diff --git a/src/extension.ts b/src/extension.ts index d895bb0e1b0..d19a973fe6a 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -123,6 +123,21 @@ export async function activate(context: vscode.ExtensionContext) { // Implements the `RooCodeAPI` interface. const socketPath = process.env.ROO_CODE_IPC_SOCKET_PATH const enableLogging = typeof socketPath === "string" + + // Watch the core files and automatically reload the extension host + const enableCoreAutoReload = process.env?.NODE_ENV === "development" + if (enableCoreAutoReload) { + console.log(`♻️♻️♻️ Core auto-reloading is ENABLED!`) + const watcher = vscode.workspace.createFileSystemWatcher( + new vscode.RelativePattern(context.extensionPath, "src/**/*.ts"), + ) + watcher.onDidChange((uri) => { + console.log(`♻️ File changed: ${uri.fsPath}. Reloading host…`) + vscode.commands.executeCommand("workbench.action.reloadWindow") + }) + context.subscriptions.push(watcher) + } + return new API(outputChannel, provider, socketPath, enableLogging) }