Skip to content
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

fix: allow opening files without workspace root #1054

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

hannesrudolph
Copy link
Collaborator

@hannesrudolph hannesrudolph commented Feb 18, 2025

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

This solves #1053

Description

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Checklist:

  • My code follows the patterns of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation

Additional context

Related Issues

Reviewers


Important

Modified openFile in open-file.ts to handle absolute paths without requiring a workspace root, fixing issue #1053.

  • Behavior:
    • Modified openFile in open-file.ts to handle absolute paths when no workspace is open.
    • Removed requirement for workspace root in openFile.
    • Added fallback for relative paths when no workspace is present.
  • Error Handling:
    • Previously, opening files without a workspace root resulted in an error. Now, it handles both workspace-relative and absolute paths.

This description was created by Ellipsis for 90365c4. It will automatically update as commits are pushed.

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
Copy link

changeset-bot bot commented Feb 18, 2025

⚠️ No Changeset found

Latest commit: 90365c4

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

// 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, treat it as an absolute path
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about treating it as an absolute path. Maybe we should throw an error still if no workspace root, but only for relative paths?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants