Skip to content

Commit 86c6af1

Browse files
committed
fix: resolve vscode module import issue in webview build
- Separate vscode-dependent code into vscode-utils.ts - Create wrapper module to conditionally use vscode functionality - Update all imports to use the wrapper instead of direct imports - Initialize vscode utilities during extension activation - This prevents the webview build from failing due to vscode module not being available in browser context
1 parent f921cdb commit 86c6af1

File tree

10 files changed

+108
-42
lines changed

10 files changed

+108
-42
lines changed

pr-body.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
## Summary
2+
3+
This PR fixes issue #6720 where Roo Code incorrectly identifies the .roo folder location in multi-root workspaces. When .roo is added as one of the workspace folders, it should be recognized directly rather than being treated as a subdirectory of another workspace folder.
4+
5+
## Problem
6+
7+
In multi-root workspaces, when .roo is added as a workspace folder, Roo Code was still creating/looking for .roo as a subdirectory of the first workspace folder instead of recognizing the existing .roo workspace folder.
8+
9+
## Solution
10+
11+
- Added `findWorkspaceWithRoo()` utility function to detect when .roo is one of the workspace folders
12+
- Updated `getProjectRooDirectoryForCwd()` to return the .roo workspace folder path directly when it exists
13+
- Updated all direct .roo path constructions throughout the codebase to use the centralized utility functions
14+
- Added comprehensive tests for multi-root workspace scenarios
15+
16+
## Changes
17+
18+
- **src/services/roo-config/index.ts**: Added `findWorkspaceWithRoo()` and updated `getProjectRooDirectoryForCwd()`
19+
- **src/core/webview/webviewMessageHandler.ts**: Updated to use `getProjectRooDirectoryForCwd()`
20+
- **src/services/mcp/McpHub.ts**: Updated to use `getProjectRooDirectoryForCwd()`
21+
- **src/services/marketplace/SimpleInstaller.ts**: Updated to use `getProjectRooDirectoryForCwd()`
22+
- **src/core/config/CustomModesManager.ts**: Updated to use `getProjectRooDirectoryForCwd()`
23+
- **src/services/roo-config/**tests**/index.spec.ts**: Added tests for the new functionality
24+
25+
## Testing
26+
27+
- Added unit tests for `findWorkspaceWithRoo()` function
28+
- Added tests for `getProjectRooDirectoryForCwd()` with multi-root workspace scenarios
29+
- All existing tests pass without regression
30+
- Manually tested in VS Code with multi-root workspaces
31+
32+
Fixes #6720

src/core/config/CustomModesManager.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import { type ModeConfig, type PromptComponent, customModesSettingsSchema, modeC
1010

1111
import { fileExistsAtPath } from "../../utils/fs"
1212
import { getWorkspacePath } from "../../utils/path"
13-
import { getGlobalRooDirectory, getProjectRooDirectoryForCwd } from "../../services/roo-config"
13+
import { getGlobalRooDirectory } from "../../services/roo-config"
14+
import { getProjectRooDirectoryForCwd } from "../../services/roo-config/wrapper"
1415
import { logger } from "../../utils/logging"
1516
import { GlobalFileNames } from "../../shared/globalFileNames"
1617
import { ensureSettingsDirectoryExists } from "../../utils/globalContext"

src/core/webview/webviewMessageHandler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ import { getModels, flushModels } from "../../api/providers/fetchers/modelCache"
5050
import { GetModelsOptions } from "../../shared/api"
5151
import { generateSystemPrompt } from "./generateSystemPrompt"
5252
import { getCommand } from "../../utils/commands"
53-
import { getProjectRooDirectoryForCwd } from "../../services/roo-config"
53+
import { getProjectRooDirectoryForCwd } from "../../services/roo-config/wrapper"
5454

5555
const ALLOWED_VSCODE_SETTINGS = new Set(["terminal.integrated.inheritEnv"])
5656

src/extension.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ export async function activate(context: vscode.ExtensionContext) {
6060
context.subscriptions.push(outputChannel)
6161
outputChannel.appendLine(`${Package.name} extension activated - ${JSON.stringify(Package)}`)
6262

63+
// Initialize vscode utilities for roo-config wrapper
64+
const { setVscodeUtils } = await import("./services/roo-config/wrapper")
65+
const { findWorkspaceWithRoo } = await import("./services/roo-config/vscode-utils")
66+
setVscodeUtils({ findWorkspaceWithRoo })
67+
6368
// Migrate old settings to new
6469
await migrateSettings(context, outputChannel)
6570

src/services/marketplace/SimpleInstaller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import type { MarketplaceItem, MarketplaceItemType, InstallMarketplaceItemOption
66
import { GlobalFileNames } from "../../shared/globalFileNames"
77
import { ensureSettingsDirectoryExists } from "../../utils/globalContext"
88
import type { CustomModesManager } from "../../core/config/CustomModesManager"
9-
import { getProjectRooDirectoryForCwd } from "../../services/roo-config"
9+
import { getProjectRooDirectoryForCwd } from "../../services/roo-config/wrapper"
1010

1111
export interface InstallOptions extends InstallMarketplaceItemOptions {
1212
target: "project" | "global"

src/services/mcp/McpHub.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import {
3232
import { fileExistsAtPath } from "../../utils/fs"
3333
import { arePathsEqual } from "../../utils/path"
3434
import { injectVariables } from "../../utils/config"
35-
import { getProjectRooDirectoryForCwd } from "../../services/roo-config"
35+
import { getProjectRooDirectoryForCwd } from "../../services/roo-config/wrapper"
3636

3737
export type McpConnection = {
3838
server: McpServer

src/services/roo-config/__tests__/index.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ import {
4343
readFileIfExists,
4444
getRooDirectoriesForCwd,
4545
loadConfiguration,
46-
findWorkspaceWithRoo,
4746
} from "../index"
47+
import { findWorkspaceWithRoo } from "../vscode-utils"
4848

4949
describe("RooConfigService", () => {
5050
beforeEach(() => {

src/services/roo-config/index.ts

Lines changed: 4 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,6 @@
11
import * as path from "path"
22
import * as os from "os"
33
import fs from "fs/promises"
4-
import * as vscode from "vscode"
5-
6-
/**
7-
* Finds the workspace folder that contains a .roo directory
8-
*
9-
* @returns The workspace folder containing .roo, or undefined if not found
10-
*
11-
* @example
12-
* ```typescript
13-
* const workspaceWithRoo = findWorkspaceWithRoo()
14-
* if (workspaceWithRoo) {
15-
* // .roo folder exists as one of the workspace folders
16-
* const rooPath = workspaceWithRoo.uri.fsPath
17-
* }
18-
* ```
19-
*/
20-
export function findWorkspaceWithRoo(): vscode.WorkspaceFolder | undefined {
21-
if (!vscode.workspace.workspaceFolders || vscode.workspace.workspaceFolders.length === 0) {
22-
return undefined
23-
}
24-
25-
// Check if any workspace folder is named .roo
26-
for (const folder of vscode.workspace.workspaceFolders) {
27-
if (path.basename(folder.uri.fsPath) === ".roo") {
28-
return folder
29-
}
30-
}
31-
32-
return undefined
33-
}
344

355
/**
366
* Gets the global .roo directory path based on the current platform
@@ -92,13 +62,10 @@ export function getGlobalRooDirectory(): string {
9262
* subdirectory in the first workspace folder.
9363
*/
9464
export function getProjectRooDirectoryForCwd(cwd: string): string {
95-
// Check if .roo is one of the workspace folders in a multi-root workspace
96-
const workspaceWithRoo = findWorkspaceWithRoo()
97-
if (workspaceWithRoo) {
98-
return workspaceWithRoo.uri.fsPath
99-
}
100-
101-
// Default behavior: create .roo as a subdirectory
65+
// Note: In VS Code extension context, this function is overridden
66+
// by the extension to check for .roo workspace folders.
67+
// This base implementation is used by the webview and other contexts
68+
// where vscode API is not available.
10269
return path.join(cwd, ".roo")
10370
}
10471

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import * as vscode from "vscode"
2+
import * as path from "path"
3+
4+
/**
5+
* Finds the workspace folder that contains a .roo directory
6+
*
7+
* @returns The workspace folder containing .roo, or undefined if not found
8+
*
9+
* @example
10+
* ```typescript
11+
* const workspaceWithRoo = findWorkspaceWithRoo()
12+
* if (workspaceWithRoo) {
13+
* // .roo folder exists as one of the workspace folders
14+
* const rooPath = workspaceWithRoo.uri.fsPath
15+
* }
16+
* ```
17+
*/
18+
export function findWorkspaceWithRoo(): vscode.WorkspaceFolder | undefined {
19+
if (!vscode.workspace.workspaceFolders || vscode.workspace.workspaceFolders.length === 0) {
20+
return undefined
21+
}
22+
23+
// Check if any workspace folder is named .roo
24+
for (const folder of vscode.workspace.workspaceFolders) {
25+
if (path.basename(folder.uri.fsPath) === ".roo") {
26+
return folder
27+
}
28+
}
29+
30+
return undefined
31+
}

src/services/roo-config/wrapper.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import * as path from "path"
2+
import { getProjectRooDirectoryForCwd as getProjectRooDirectoryBase } from "./index"
3+
4+
// This will be set by the extension during activation
5+
let vscodeUtils: { findWorkspaceWithRoo: () => any } | undefined
6+
7+
/**
8+
* Sets the vscode utilities for use in the wrapper
9+
* This should be called during extension activation
10+
*/
11+
export function setVscodeUtils(utils: { findWorkspaceWithRoo: () => any }) {
12+
vscodeUtils = utils
13+
}
14+
15+
/**
16+
* Gets the project-local .roo directory path for a given cwd
17+
* This wrapper checks for vscode-specific functionality when available
18+
*/
19+
export function getProjectRooDirectoryForCwd(cwd: string): string {
20+
// Check if .roo is one of the workspace folders in a multi-root workspace
21+
if (vscodeUtils?.findWorkspaceWithRoo) {
22+
const workspaceWithRoo = vscodeUtils.findWorkspaceWithRoo()
23+
if (workspaceWithRoo) {
24+
return workspaceWithRoo.uri.fsPath
25+
}
26+
}
27+
28+
// Fall back to base implementation
29+
return getProjectRooDirectoryBase(cwd)
30+
}

0 commit comments

Comments
 (0)