Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Support mnemonic prefixes in git diff parsing for terminal links#298490

Open
clintharrison wants to merge 2 commits intomicrosoft:mainfrom
clintharrison:clint/git-diff-mnemonic-prefixes-in-terminal-links
Open

Support mnemonic prefixes in git diff parsing for terminal links#298490
clintharrison wants to merge 2 commits intomicrosoft:mainfrom
clintharrison:clint/git-diff-mnemonic-prefixes-in-terminal-links

Conversation

@clintharrison
Copy link

Git supports a config option diff.mnemonicPrefix that sometimes uses characters other than a/ and b/ in diffs to distinguish where they came from. This PR updates the link parsing in the integrated terminal, so file paths are still detected when this option is enabled.

I updated the existing tests for this functionality.

Manual testing

Make some change in a git repo (e.g. echo "hello world" >>README.md).

Enable this config option and run git diff: git -c diff.mnemonicPrefix=true diff in the terminal will now be comparing the index and the working copy files:

diff --git i/README.md w/README.md
index 6f1e94e4844..0dc323dc715 100644
--- i/README.md
+++ w/README.md
@@ -76,3 +76,4 @@ This project has adopted the [Microsoft Open Source Code of Conduct](https://ope
 Copyright (c) Microsoft Corporation. All rights reserved.
 
 Licensed under the [MIT](LICENSE.txt) license.
+hello world

With this change, README.md in each location should be underlined on hover and possible to open with ⌘/ctrl+click.
Notably, cmd-click will open README.md, and not attempt to find a file named w/README.md

CleanShot 2026-02-28 at 15 31 50@2x

Copilot AI review requested due to automatic review settings February 28, 2026 20:33
@clintharrison
Copy link
Author

@microsoft-github-policy-service agree

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates VS Code’s integrated terminal local-file link parsing so filenames in git diff output are correctly detected when diff.mnemonicPrefix is enabled (eg. i/ and w/ instead of a/ and b/), preventing links from including the mnemonic prefix as part of the path.

Changes:

  • Generalize git-diff prefix stripping to support mnemonic prefixes via small regex helpers.
  • Expand existing git-diff parsing tests to cover the additional mnemonic prefixes.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
src/vs/workbench/contrib/terminalContrib/links/browser/terminalLinkParsing.ts Adds regex-based detection of git diff prefixes (a/, b/, c/, i/, o/, w/) so link ranges exclude the prefix consistently.
src/vs/workbench/contrib/terminalContrib/links/test/browser/terminalLinkParsing.test.ts Parameterizes git-diff link parsing tests to validate mnemonic-prefix handling.

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.

6 participants