-
Notifications
You must be signed in to change notification settings - Fork 2.6k
fix: slash commands stored in correct workspace folder in multi-root workspaces #6701
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,6 +1,7 @@ | ||||||||||||||||||||||||||
| import * as path from "path" | ||||||||||||||||||||||||||
| import os from "os" | ||||||||||||||||||||||||||
| import * as vscode from "vscode" | ||||||||||||||||||||||||||
| import { fileExistsAtPath } from "./fs" | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| /* | ||||||||||||||||||||||||||
| The Node.js 'path' module resolves and normalizes paths differently depending on the platform: | ||||||||||||||||||||||||||
|
|
@@ -130,3 +131,33 @@ export const getWorkspacePathForContext = (contextPath?: string): string => { | |||||||||||||||||||||||||
| // Fall back to current behavior | ||||||||||||||||||||||||||
| return getWorkspacePath() | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||
| * Finds the workspace folder that contains a .roo directory. | ||||||||||||||||||||||||||
| * In multi-root workspaces, this ensures we find the correct workspace | ||||||||||||||||||||||||||
| * rather than just using the first one. | ||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||
| * @returns The workspace folder containing .roo, or undefined if none found | ||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||
| export async function findWorkspaceWithRoo(): Promise<vscode.WorkspaceFolder | undefined> { | ||||||||||||||||||||||||||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For workspaces with many folders, this function performs filesystem checks on every command creation. Have you considered caching the result and invalidating it when workspace folders change? This could improve performance in large multi-root workspaces: // At module level
let cachedWorkspaceWithRoo: vscode.WorkspaceFolder | undefined;
let cachedWorkspaceFoldersHash: string | undefined;
// In the function, check if cache is valid
const currentHash = JSON.stringify(workspaceFolders.map(f => f.uri.fsPath));
if (cachedWorkspaceFoldersHash === currentHash && cachedWorkspaceWithRoo) {
return cachedWorkspaceWithRoo;
} |
||||||||||||||||||||||||||
| const workspaceFolders = vscode.workspace.workspaceFolders | ||||||||||||||||||||||||||
| if (!workspaceFolders || workspaceFolders.length === 0) { | ||||||||||||||||||||||||||
| return undefined | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| // If there's only one workspace folder, return it | ||||||||||||||||||||||||||
| if (workspaceFolders.length === 1) { | ||||||||||||||||||||||||||
| return workspaceFolders[0] | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| // Check each workspace folder for a .roo directory | ||||||||||||||||||||||||||
| for (const folder of workspaceFolders) { | ||||||||||||||||||||||||||
| const rooPath = path.join(folder.uri.fsPath, ".roo") | ||||||||||||||||||||||||||
| if (await fileExistsAtPath(rooPath)) { | ||||||||||||||||||||||||||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function works well for the intended use case, but I noticed it doesn't handle potential errors from
Suggested change
|
||||||||||||||||||||||||||
| return folder | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| // If no .roo directory found in any workspace, return the first one as fallback | ||||||||||||||||||||||||||
| return workspaceFolders[0] | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand the vitest setup constraints mentioned in the PR description, but could we consider adding at least some basic test coverage for
findWorkspaceWithRoo()? Even if we can't test the actual filesystem operations, we could test the logic with mockedfileExistsAtPathresponses. This is a critical function that determines where commands are stored.