From 3d129e8a8900954a1155756f3f948f9d267b4341 Mon Sep 17 00:00:00 2001 From: Hannes Rudolph Date: Wed, 23 Apr 2025 00:35:10 -0600 Subject: [PATCH] fix: allow opening files without workspace root (#1054) * 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 * fix: update openFile function to use provided path without modification --------- Co-authored-by: Roo Code Co-authored-by: Matt Rubens --- src/integrations/misc/open-file.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/integrations/misc/open-file.ts b/src/integrations/misc/open-file.ts index 5698e919de..b3724068b6 100644 --- a/src/integrations/misc/open-file.ts +++ b/src/integrations/misc/open-file.ts @@ -29,12 +29,14 @@ export async function openFile(filePath: string, options: OpenFileOptions = {}) try { // Get workspace root const workspaceRoot = getWorkspacePath() - if (!workspaceRoot) { - throw new Error("No workspace root found") - } - // If path starts with ./, resolve it relative to workspace root - const fullPath = filePath.startsWith("./") ? path.join(workspaceRoot, filePath.slice(2)) : filePath + // If path starts with ./, resolve it relative to workspace root if available + // Otherwise, use the path as provided without modification + const fullPath = filePath.startsWith("./") + ? workspaceRoot + ? path.join(workspaceRoot, filePath.slice(2)) + : filePath + : filePath const uri = vscode.Uri.file(fullPath)