Repository: microsoft/vscode (TypeScript)
Date: 2023-03-15 14:01:02+00:00
Task type: Bug Fix

Issue:
File links in intergrated terminal no longer respect line numbers, if the path is preceded by `>`
<!-- ⚠️⚠️ Do Not Delete This! bug_report_template ⚠️⚠️ -->
<!-- Please read our Rules of Conduct: https://opensource.microsoft.com/codeofconduct/ -->
<!-- 🕮 Read our guide about submitting issues: https://github.com/microsoft/vscode/wiki/Submitting-Bugs-and-Suggestions -->
<!-- 🔎 Search existing issues to avoid creating duplicates. -->
<!-- 🧪 Test using the latest Insiders build to see if your issue has already been fixed: https://code.visualstudio.com/insiders/ -->
<!-- 💡 Instead of creating your report here, use 'Report Issue' from the 'Help' menu in VS Code to pre-fill useful information. -->
<!-- 🔧 Launch with `code --disable-extensions` to check. -->
Does this issue occur when all extensions are disabled?: Yes

<!-- 🪓 If you answered No above, use 'Help: Start Extension Bisect' from Command Palette to try to identify the cause. -->
<!-- 📣 Issues caused by an extension need to be reported directly to the extension publisher. The 'Help > Report Issue' dialog can assist with this. -->
- VS Code Version: 1.76.0 (and 1.76.1)
- OS Version: Windows_NT x64 10.0.19045

Clicking a file path in the terminal, followed by a line number, no longer scrolls to the specified line. This only happens if the path is preceded by `>`.

This is a regression, it used to work in recent versions (1.75.x I believe).

Steps to Reproduce:

1. In integrated terminal: `echo '1>C:\path\to\some\file.cpp(3,1): error C2059: syntax error: ...'` (use a path to existing non-empty file)
2. Alt+click the path
3. The file is opened, but not at the specified line number (3 in this case)

This only happens if the path is preceded by `>`. Since MSVC C++ compiler outputs paths in this format, this is a common use case.

This seems to affect all line number formats: `(row,col):`, `(row):`, `:row:col:`, `:row:`.



Issue discussion:
Thanks for creating this issue! It looks like you may be using an old version of VS Code, the latest stable release is 1.76.1. Please try upgrading to the latest version and checking whether this issue remains.

Happy Coding!
Still reproduces on 1.76.1.

Solution patch:
diff --git a/src/vs/workbench/contrib/terminalContrib/links/browser/terminalLinkParsing.ts b/src/vs/workbench/contrib/terminalContrib/links/browser/terminalLinkParsing.ts
--- a/src/vs/workbench/contrib/terminalContrib/links/browser/terminalLinkParsing.ts
+++ b/src/vs/workbench/contrib/terminalContrib/links/browser/terminalLinkParsing.ts
@@ -204,8 +204,11 @@ export function toLinkSuffix(match: RegExpExecArray | null): ILinkSuffix | null
 	};
 }
 
-// Paths cannot start with opening brackets
-const linkWithSuffixPathCharacters = /(?<path>[^\s\|\[\({][^\s\|]*)$/;
+// This defines valid path characters for a link with a suffix, the first `[]` of the regex includes
+// characters the path is not allowed to _start_ with, the second `[]` includes characters not
+// allowed at all in the path. If the characters show up in both regexes the link will stop at that
+// character, otherwise it will stop at a space character.
+const linkWithSuffixPathCharacters = /(?<path>[^\s\|<>\[\({][^\s\|<>]*)$/;
 
 export function detectLinks(line: string, os: OperatingSystem) {
 	// 1: Detect all links on line via suffixes first


Test patch:
diff --git a/src/vs/workbench/contrib/terminalContrib/links/test/browser/terminalLinkParsing.test.ts b/src/vs/workbench/contrib/terminalContrib/links/test/browser/terminalLinkParsing.test.ts
--- a/src/vs/workbench/contrib/terminalContrib/links/test/browser/terminalLinkParsing.test.ts
+++ b/src/vs/workbench/contrib/terminalContrib/links/test/browser/terminalLinkParsing.test.ts
@@ -329,43 +329,117 @@ suite('TerminalLinkParsing', () => {
 			);
 		});
 
-		test('should exclude pipe characters from link paths', () => {
-			deepStrictEqual(
-				detectLinks('|C:\\Github\\microsoft\\vscode|', OperatingSystem.Windows),
-				[
-					{
-						path: {
-							index: 1,
-							text: 'C:\\Github\\microsoft\\vscode'
-						},
-						prefix: undefined,
-						suffix: undefined
-					}
-				] as IParsedLink[]
-			);
+		suite('"|"', () => {
+			test('should exclude pipe characters from link paths', () => {
+				deepStrictEqual(
+					detectLinks('|C:\\Github\\microsoft\\vscode|', OperatingSystem.Windows),
+					[
+						{
+							path: {
+								index: 1,
+								text: 'C:\\Github\\microsoft\\vscode'
+							},
+							prefix: undefined,
+							suffix: undefined
+						}
+					] as IParsedLink[]
+				);
+			});
+			test('should exclude pipe characters from link paths with suffixes', () => {
+				deepStrictEqual(
+					detectLinks('|C:\\Github\\microsoft\\vscode:400|', OperatingSystem.Windows),
+					[
+						{
+							path: {
+								index: 1,
+								text: 'C:\\Github\\microsoft\\vscode'
+							},
+							prefix: undefined,
+							suffix: {
+								col: undefined,
+								row: 400,
+								suffix: {
+									index: 27,
+									text: ':400'
+								}
+							}
+						}
+					] as IParsedLink[]
+				);
+			});
 		});
 
-		test('should exclude pipe characters from link paths with suffixes', () => {
-			deepStrictEqual(
-				detectLinks('|C:\\Github\\microsoft\\vscode:400|', OperatingSystem.Windows),
-				[
-					{
-						path: {
-							index: 1,
-							text: 'C:\\Github\\microsoft\\vscode'
-						},
-						prefix: undefined,
-						suffix: {
-							col: undefined,
-							row: 400,
+		suite('"<>"', () => {
+			test('should exclude bracket characters from link paths', () => {
+				deepStrictEqual(
+					detectLinks('<C:\\Github\\microsoft\\vscode<', OperatingSystem.Windows),
+					[
+						{
+							path: {
+								index: 1,
+								text: 'C:\\Github\\microsoft\\vscode'
+							},
+							prefix: undefined,
+							suffix: undefined
+						}
+					] as IParsedLink[]
+				);
+				deepStrictEqual(
+					detectLinks('>C:\\Github\\microsoft\\vscode>', OperatingSystem.Windows),
+					[
+						{
+							path: {
+								index: 1,
+								text: 'C:\\Github\\microsoft\\vscode'
+							},
+							prefix: undefined,
+							suffix: undefined
+						}
+					] as IParsedLink[]
+				);
+			});
+			test('should exclude bracket characters from link paths with suffixes', () => {
+				deepStrictEqual(
+					detectLinks('<C:\\Github\\microsoft\\vscode:400<', OperatingSystem.Windows),
+					[
+						{
+							path: {
+								index: 1,
+								text: 'C:\\Github\\microsoft\\vscode'
+							},
+							prefix: undefined,
 							suffix: {
-								index: 27,
-								text: ':400'
+								col: undefined,
+								row: 400,
+								suffix: {
+									index: 27,
+									text: ':400'
+								}
 							}
 						}
-					}
-				] as IParsedLink[]
-			);
+					] as IParsedLink[]
+				);
+				deepStrictEqual(
+					detectLinks('>C:\\Github\\microsoft\\vscode:400>', OperatingSystem.Windows),
+					[
+						{
+							path: {
+								index: 1,
+								text: 'C:\\Github\\microsoft\\vscode'
+							},
+							prefix: undefined,
+							suffix: {
+								col: undefined,
+								row: 400,
+								suffix: {
+									index: 27,
+									text: ':400'
+								}
+							}
+						}
+					] as IParsedLink[]
+				);
+			});
 		});
 
 		suite('should detect file names in git diffs', () => {