Skip to content

Commit 90365c4

Browse files
author
Roo Code
committed
fix: allow opening files without workspace root
The openFile function in open-file.ts was requiring a workspace root to be present, which prevented opening global files (like MCP settings) when no workspace was open. Modified the function to handle absolute paths without this requirement. Previously, trying to open MCP settings in a new window without a workspace would error with "Could not open file: No workspace root found". Now the function properly handles both workspace-relative and absolute paths, allowing global settings files to be accessed in any context. Changes: - Removed workspace root requirement in openFile - Added fallback for relative paths when no workspace is present
1 parent 9df50b4 commit 90365c4

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/integrations/misc/open-file.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,14 @@ export async function openFile(filePath: string, options: OpenFileOptions = {})
2929
try {
3030
// Get workspace root
3131
const workspaceRoot = vscode.workspace.workspaceFolders?.[0]?.uri.fsPath
32-
if (!workspaceRoot) {
33-
throw new Error("No workspace root found")
34-
}
3532

36-
// If path starts with ./, resolve it relative to workspace root
37-
const fullPath = filePath.startsWith("./") ? path.join(workspaceRoot, filePath.slice(2)) : filePath
33+
// If path starts with ./, resolve it relative to workspace root if available
34+
// Otherwise, treat it as an absolute path
35+
const fullPath = filePath.startsWith("./")
36+
? workspaceRoot
37+
? path.join(workspaceRoot, filePath.slice(2))
38+
: filePath
39+
: filePath
3840

3941
const uri = vscode.Uri.file(fullPath)
4042

0 commit comments

Comments
 (0)