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 <support@roo.vet>
Co-authored-by: Matt Rubens <mrubens@users.noreply.github.com>
This commit is contained in:
Hannes Rudolph 2025-04-23 00:35:10 -06:00 • committed by GitHub
parent 0f64849542
commit 3d129e8a89
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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)