fix(vscode): make markdown file links in assistant output clickable
Related Issue
Resolve #2194
Problem
Markdown links in assistant output that point at local files are never clickable in the VS Code extension — only https:// links work. Three gaps stack up: react-markdown's URL sanitizer empties file:// / vscode://file/ hrefs, the webview renders every link as a plain <a> (which the webview only follows for external schemes), and the openFile bridge rejects absolute paths and :line suffixes anyway.
What changed
- New pure helper
parseFileLink(webviewlib/link-utils.ts): classifies an href as a local file target (plain relative/absolute path — including root-level ones likeREADME.md:5—file://,vscode://file/, native Windows path, each with an optional trailing:line(:col)suffix) or an external link. A:0suffix is kept as part of the path rather than becoming an invalid line reference. - The Markdown
arenderer routes file targets through the existingFileLink→bridge.openFilepath (external links keep the anchor), and a customurlTransformpreserves exactly the hrefsparseFileLinkaccepts — anchor hrefs only, so image/mediasrcattributes keep the default sanitizer behavior, andjavascript:URLs are still stripped. openFilegains an optional validatedlineparam, and the handler now accepts absolute paths by relativizing them against the working directory before the existing containment check. Out-of-workspace paths still returnok: false, and alineis revealed via thevscode.openselection.
Review follow-ups included: Windows vscode://file/C:/... URIs drop the bogus leading slash, authority-bearing file://server/share/... URIs map to their UNC path (with localhost meaning no authority), drive-relative C:foo inputs stay refused instead of being classified absolute, #fragments are split off the path (GitHub-style #L20 reads as a line reference), the vscode://file authority boundary is enforced (vscode://fileevil/... is not a file link), and line references must be safe integers on both the parser and the bridge validator so an oversized :line suffix degrades to a plain path link instead of a rejected request.
Scope note: bare absolute paths in plain text (outside a markdown link) remain non-clickable; text enrichment still only links workspace-relative paths. If that variant should also be linkified, it is better tracked as a separate enhancement.
Tests: file-link-parsing.test.ts covers every href variant from the issue plus the Windows/UNC/fragment/authority/oversized-line cases and external-scheme passthrough; workspace-paths.test.ts gains absolute-inside (opens), absolute-outside (refused), drive-relative (refused), and line-selection cases. All fail without the fix. No changeset, matching previous extension-only fixes.
Checklist
- [x] I have read the CONTRIBUTING document.
- [x] I have linked a related issue, or explained the problem above.
- [x] I have added tests that prove my feature works.
- [x] Ran
gen-changesetsskill, or this PR needs no changeset. - [x] Ran
gen-docsskill, or this PR needs no doc update.
⚠️ No Changeset found
Latest commit: 4b526b94c7f666960ad6010e37b6fc83335bafc4
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
@codex review — all review findings are addressed as of 4b526b94: Windows vscode-file URIs, UNC file URIs, drive-relative refusal, fragment handling with #L20 line references, the vscode://file authority boundary, and safe-integer line validation on both sides of the bridge.
Codex Review: Didn't find any major issues. Delightful!
Reviewed commit: 4b526b94c7
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".