mirror of
https://github.com/RooVetGit/Roo-Code.git
synced 2026-09-06 08:18:39 +00:00
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
This commit is contained in:
parent
f921cdb72c
commit
86c6af14bd
10 changed files with 108 additions and 42 deletions
32
pr-body.md
Normal file
32
pr-body.md
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
## Summary
|
||||
|
||||
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.
|
||||
|
||||
## Problem
|
||||
|
||||
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.
|
||||
|
||||
## Solution
|
||||
|
||||
- Added `findWorkspaceWithRoo()` utility function to detect when .roo is one of the workspace folders
|
||||
- Updated `getProjectRooDirectoryForCwd()` to return the .roo workspace folder path directly when it exists
|
||||
- Updated all direct .roo path constructions throughout the codebase to use the centralized utility functions
|
||||
- Added comprehensive tests for multi-root workspace scenarios
|
||||
|
||||
## Changes
|
||||
|
||||
- **src/services/roo-config/index.ts**: Added `findWorkspaceWithRoo()` and updated `getProjectRooDirectoryForCwd()`
|
||||
- **src/core/webview/webviewMessageHandler.ts**: Updated to use `getProjectRooDirectoryForCwd()`
|
||||
- **src/services/mcp/McpHub.ts**: Updated to use `getProjectRooDirectoryForCwd()`
|
||||
- **src/services/marketplace/SimpleInstaller.ts**: Updated to use `getProjectRooDirectoryForCwd()`
|
||||
- **src/core/config/CustomModesManager.ts**: Updated to use `getProjectRooDirectoryForCwd()`
|
||||
- **src/services/roo-config/**tests**/index.spec.ts**: Added tests for the new functionality
|
||||
|
||||
## Testing
|
||||
|
||||
- Added unit tests for `findWorkspaceWithRoo()` function
|
||||
- Added tests for `getProjectRooDirectoryForCwd()` with multi-root workspace scenarios
|
||||
- All existing tests pass without regression
|
||||
- Manually tested in VS Code with multi-root workspaces
|
||||
|
||||
Fixes #6720
|
||||
|
|
@ -10,7 +10,8 @@ import { type ModeConfig, type PromptComponent, customModesSettingsSchema, modeC
|
|||
|
||||
import { fileExistsAtPath } from "../../utils/fs"
|
||||
import { getWorkspacePath } from "../../utils/path"
|
||||
import { getGlobalRooDirectory, getProjectRooDirectoryForCwd } from "../../services/roo-config"
|
||||
import { getGlobalRooDirectory } from "../../services/roo-config"
|
||||
import { getProjectRooDirectoryForCwd } from "../../services/roo-config/wrapper"
|
||||
import { logger } from "../../utils/logging"
|
||||
import { GlobalFileNames } from "../../shared/globalFileNames"
|
||||
import { ensureSettingsDirectoryExists } from "../../utils/globalContext"
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ import { getModels, flushModels } from "../../api/providers/fetchers/modelCache"
|
|||
import { GetModelsOptions } from "../../shared/api"
|
||||
import { generateSystemPrompt } from "./generateSystemPrompt"
|
||||
import { getCommand } from "../../utils/commands"
|
||||
import { getProjectRooDirectoryForCwd } from "../../services/roo-config"
|
||||
import { getProjectRooDirectoryForCwd } from "../../services/roo-config/wrapper"
|
||||
|
||||
const ALLOWED_VSCODE_SETTINGS = new Set(["terminal.integrated.inheritEnv"])
|
||||
|
||||
|
|
|
|||
|
|
@ -60,6 +60,11 @@ export async function activate(context: vscode.ExtensionContext) {
|
|||
context.subscriptions.push(outputChannel)
|
||||
outputChannel.appendLine(`${Package.name} extension activated - ${JSON.stringify(Package)}`)
|
||||
|
||||
// Initialize vscode utilities for roo-config wrapper
|
||||
const { setVscodeUtils } = await import("./services/roo-config/wrapper")
|
||||
const { findWorkspaceWithRoo } = await import("./services/roo-config/vscode-utils")
|
||||
setVscodeUtils({ findWorkspaceWithRoo })
|
||||
|
||||
// Migrate old settings to new
|
||||
await migrateSettings(context, outputChannel)
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import type { MarketplaceItem, MarketplaceItemType, InstallMarketplaceItemOption
|
|||
import { GlobalFileNames } from "../../shared/globalFileNames"
|
||||
import { ensureSettingsDirectoryExists } from "../../utils/globalContext"
|
||||
import type { CustomModesManager } from "../../core/config/CustomModesManager"
|
||||
import { getProjectRooDirectoryForCwd } from "../../services/roo-config"
|
||||
import { getProjectRooDirectoryForCwd } from "../../services/roo-config/wrapper"
|
||||
|
||||
export interface InstallOptions extends InstallMarketplaceItemOptions {
|
||||
target: "project" | "global"
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ import {
|
|||
import { fileExistsAtPath } from "../../utils/fs"
|
||||
import { arePathsEqual } from "../../utils/path"
|
||||
import { injectVariables } from "../../utils/config"
|
||||
import { getProjectRooDirectoryForCwd } from "../../services/roo-config"
|
||||
import { getProjectRooDirectoryForCwd } from "../../services/roo-config/wrapper"
|
||||
|
||||
export type McpConnection = {
|
||||
server: McpServer
|
||||
|
|
|
|||
|
|
@ -43,8 +43,8 @@ import {
|
|||
readFileIfExists,
|
||||
getRooDirectoriesForCwd,
|
||||
loadConfiguration,
|
||||
findWorkspaceWithRoo,
|
||||
} from "../index"
|
||||
import { findWorkspaceWithRoo } from "../vscode-utils"
|
||||
|
||||
describe("RooConfigService", () => {
|
||||
beforeEach(() => {
|
||||
|
|
|
|||
|
|
@ -1,36 +1,6 @@
|
|||
import * as path from "path"
|
||||
import * as os from "os"
|
||||
import fs from "fs/promises"
|
||||
import * as vscode from "vscode"
|
||||
|
||||
/**
|
||||
* Finds the workspace folder that contains a .roo directory
|
||||
*
|
||||
* @returns The workspace folder containing .roo, or undefined if not found
|
||||
*
|
||||
* @example
|
||||
* ```typescript
|
||||
* const workspaceWithRoo = findWorkspaceWithRoo()
|
||||
* if (workspaceWithRoo) {
|
||||
* // .roo folder exists as one of the workspace folders
|
||||
* const rooPath = workspaceWithRoo.uri.fsPath
|
||||
* }
|
||||
* ```
|
||||
*/
|
||||
export function findWorkspaceWithRoo(): vscode.WorkspaceFolder | undefined {
|
||||
if (!vscode.workspace.workspaceFolders || vscode.workspace.workspaceFolders.length === 0) {
|
||||
return undefined
|
||||
}
|
||||
|
||||
// Check if any workspace folder is named .roo
|
||||
for (const folder of vscode.workspace.workspaceFolders) {
|
||||
if (path.basename(folder.uri.fsPath) === ".roo") {
|
||||
return folder
|
||||
}
|
||||
}
|
||||
|
||||
return undefined
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the global .roo directory path based on the current platform
|
||||
|
|
@ -92,13 +62,10 @@ export function getGlobalRooDirectory(): string {
|
|||
* subdirectory in the first workspace folder.
|
||||
*/
|
||||
export function getProjectRooDirectoryForCwd(cwd: string): string {
|
||||
// Check if .roo is one of the workspace folders in a multi-root workspace
|
||||
const workspaceWithRoo = findWorkspaceWithRoo()
|
||||
if (workspaceWithRoo) {
|
||||
return workspaceWithRoo.uri.fsPath
|
||||
}
|
||||
|
||||
// Default behavior: create .roo as a subdirectory
|
||||
// Note: In VS Code extension context, this function is overridden
|
||||
// by the extension to check for .roo workspace folders.
|
||||
// This base implementation is used by the webview and other contexts
|
||||
// where vscode API is not available.
|
||||
return path.join(cwd, ".roo")
|
||||
}
|
||||
|
||||
|
|
|
|||
31
src/services/roo-config/vscode-utils.ts
Normal file
31
src/services/roo-config/vscode-utils.ts
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
import * as vscode from "vscode"
|
||||
import * as path from "path"
|
||||
|
||||
/**
|
||||
* Finds the workspace folder that contains a .roo directory
|
||||
*
|
||||
* @returns The workspace folder containing .roo, or undefined if not found
|
||||
*
|
||||
* @example
|
||||
* ```typescript
|
||||
* const workspaceWithRoo = findWorkspaceWithRoo()
|
||||
* if (workspaceWithRoo) {
|
||||
* // .roo folder exists as one of the workspace folders
|
||||
* const rooPath = workspaceWithRoo.uri.fsPath
|
||||
* }
|
||||
* ```
|
||||
*/
|
||||
export function findWorkspaceWithRoo(): vscode.WorkspaceFolder | undefined {
|
||||
if (!vscode.workspace.workspaceFolders || vscode.workspace.workspaceFolders.length === 0) {
|
||||
return undefined
|
||||
}
|
||||
|
||||
// Check if any workspace folder is named .roo
|
||||
for (const folder of vscode.workspace.workspaceFolders) {
|
||||
if (path.basename(folder.uri.fsPath) === ".roo") {
|
||||
return folder
|
||||
}
|
||||
}
|
||||
|
||||
return undefined
|
||||
}
|
||||
30
src/services/roo-config/wrapper.ts
Normal file
30
src/services/roo-config/wrapper.ts
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
import * as path from "path"
|
||||
import { getProjectRooDirectoryForCwd as getProjectRooDirectoryBase } from "./index"
|
||||
|
||||
// This will be set by the extension during activation
|
||||
let vscodeUtils: { findWorkspaceWithRoo: () => any } | undefined
|
||||
|
||||
/**
|
||||
* Sets the vscode utilities for use in the wrapper
|
||||
* This should be called during extension activation
|
||||
*/
|
||||
export function setVscodeUtils(utils: { findWorkspaceWithRoo: () => any }) {
|
||||
vscodeUtils = utils
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the project-local .roo directory path for a given cwd
|
||||
* This wrapper checks for vscode-specific functionality when available
|
||||
*/
|
||||
export function getProjectRooDirectoryForCwd(cwd: string): string {
|
||||
// Check if .roo is one of the workspace folders in a multi-root workspace
|
||||
if (vscodeUtils?.findWorkspaceWithRoo) {
|
||||
const workspaceWithRoo = vscodeUtils.findWorkspaceWithRoo()
|
||||
if (workspaceWithRoo) {
|
||||
return workspaceWithRoo.uri.fsPath
|
||||
}
|
||||
}
|
||||
|
||||
// Fall back to base implementation
|
||||
return getProjectRooDirectoryBase(cwd)
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue