Skip to content

Fix directory link handling in markdown #3690

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

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

Conversation

KJ7LNW
Copy link
Collaborator

@KJ7LNW KJ7LNW commented May 17, 2025

Context

When clicking on directory links in markdown like [some/directory/](some/directory/), the application does not know how to open the link in the explorer tree. Gemini 2.5 references directory sometimes, so this feature makes it possible to click on those links.

image

Clicking test/ takes you here:

image

Implementation

Enhanced the openFile function to better handle directory links in markdown:

  • Added support for resolving ./SimpleName paths to home directory if not found in workspace
  • Improved path resolution by checking multiple potential locations
  • Ensured directories are properly revealed in the Explorer view
  • Added attempt to expand directories after revealing them

How to Test

  1. Create a markdown link to a directory outside your workspace, e.g., [Desktop](Desktop)
  2. Click on the link
  3. Verify the directory is revealed in the Explorer view

Fixes #3686


Important

Enhance openFile in open-file.ts to handle directory links in markdown by resolving paths to home directory, checking multiple locations, and revealing directories in Explorer.

  • Behavior:
    • Enhanced openFile function in open-file.ts to handle directory links in markdown.
    • Resolves ./SimpleName paths to home directory if not found in workspace.
    • Checks multiple potential locations for path resolution.
    • Reveals directories in Explorer view and attempts to expand them.
  • Error Handling:
    • Throws error if path does not exist and creation is not allowed.
    • Logs warning if directory expansion fails.
  • Misc:
    • Keeps original file path for error messages.
    • Minor refactoring for clarity and efficiency.

This description was created by Ellipsis for db482aa. You can customize this summary. It will automatically update as commits are pushed.

Enhance the openFile function to better handle directory links in markdown:
- Add support for resolving ./SimpleName paths to home directory if not found in workspace
- Improve path resolution by checking multiple potential locations
- Ensure directories are properly revealed in the Explorer view
- Attempt to expand directories after revealing them

Fixes: cline#3686
Signed-off-by: Eric Wheeler <[email protected]>
@KJ7LNW KJ7LNW added enhancement New feature or request Issue - Unassigned / Actionable Clear and approved. Available for contributors to pick up. labels May 17, 2025
@KJ7LNW KJ7LNW marked this pull request as ready for review May 17, 2025 01:13
@KJ7LNW KJ7LNW requested review from mrubens and cte as code owners May 17, 2025 01:13
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. bug Something isn't working labels May 17, 2025
@hannesrudolph hannesrudolph moved this from New to PR [Pre Approval Review] in Roo Code Roadmap May 20, 2025
@hannesrudolph hannesrudolph moved this from PR [Needs Review] to TEMP in Roo Code Roadmap May 26, 2025
@daniel-lxs daniel-lxs moved this from TEMP to PR [Needs Review] in Roo Code Roadmap May 27, 2025
@daniel-lxs daniel-lxs added PR - Needs Preliminary Review and removed Issue - Unassigned / Actionable Clear and approved. Available for contributors to pick up. labels May 27, 2025
Copy link
Collaborator

@daniel-lxs daniel-lxs left a comment

Choose a reason for hiding this comment

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

This looks goods to me, just a minor point that might be worth paying atenttion.
It makes sense to also handle directory paths when the model links them.


const uri = vscode.Uri.file(fullPath)
if (filePath.startsWith("./")) {
const relativePart = filePath.slice(2)
Copy link
Collaborator

@daniel-lxs daniel-lxs May 28, 2025

Choose a reason for hiding this comment

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

Hey @KJ7LNW Would it be a good idea to prevent directory traversal?
Something like this could work:

if (relativePart.includes('..')) {
    throw new Error('Path contains directory traversal pattern');
}

Or maybe something more sophisticated would make sense.

I just tested your implementation and I see some weird behavior when the model outputs a path like ..

Copy link
Collaborator Author

@KJ7LNW KJ7LNW May 29, 2025

Choose a reason for hiding this comment

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

Did the directory that it referenced using ../ exist, or was it just missing?

Can you provide a specific example so I can understand better?

I think we need to expect the model will sometimes render things in a way that is not expected; worst case the link is broken, but I do not think that is a problem.

Render-output handling is always best effort: the models are pretty good, but you never know what you are going to get.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Here's how it behaves for me, it's probably a non-issue though, that's why I left this PR for review.

2025-05-29.17-17-13.mp4

Apologies for the awful quality.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

that is strange behavior. if anything, .. should mean ${workspace}/.. but you're right, non-issue no one will need to click on ".."

@daniel-lxs daniel-lxs moved this from PR [Needs Preliminary Review] to PR [Needs Review] in Roo Code Roadmap May 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request PR - Needs Review size:L This PR changes 100-499 lines, ignoring generated files.
Projects
Status: PR [Needs Review]
Development

Successfully merging this pull request may close these issues.

Fix directory link handling in markdown
2 participants