Repository: microsoft/vscode (TypeScript)
Task: Bug Fix (2022-05-20 19:52:46+00:00)

Issue:
Terminal cwd seems to be behind a command
At least, that's what it seems like. Testing https://github.com/microsoft/vscode/issues/141502 with Powershell 7

1. Follow the setup for `a` and `b`.
2. Open vscode in folder `a`
3. In the terminal, `cd ../b`
4. In the terminal, _type out_ `echo foo.txt` without hitting enter and ctrl+click `foo.txt`. `a/foo.txt` opens 🐛 
5. Hit enter, or run any other command. Even hitting enter on an empty prompt works.
6. Repeat step 4, but this time `b/foo.txt` opens correctly


Discussion:
Ah this is because the command doesn't get fully registered until it finishes, same root cause as https://github.com/microsoft/vscode/issues/143704
This works but the opened file has a strange breadcrumb: 
![image](https://user-images.githubusercontent.com/30305945/160063694-a049d701-f175-4409-8766-3af87f52f8f3.png)

Good URI (b/foo.txt):

![image](https://user-images.githubusercontent.com/2193314/160141140-fe5b2750-fd13-47e4-b330-ee11b94fa6b4.png)

Bad URI: (cd b; foo.txt)

![image](https://user-images.githubusercontent.com/2193314/160141304-3e59cb4e-4b85-4e17-a780-f52d37a808bd.png)

Fix will be here, maybe only happens on Windows:

https://github.com/microsoft/vscode/blob/1a93d4f70ea0e0cd5e821dbcf8b6f20d9a7187e3/src/vs/workbench/contrib/terminal/browser/links/terminalLinkHelpers.ts#L150-L175

This is too risky imo for March.

Patch:
diff --git a/src/vs/workbench/contrib/terminal/browser/links/terminalLinkOpeners.ts b/src/vs/workbench/contrib/terminal/browser/links/terminalLinkOpeners.ts
--- a/src/vs/workbench/contrib/terminal/browser/links/terminalLinkOpeners.ts
+++ b/src/vs/workbench/contrib/terminal/browser/links/terminalLinkOpeners.ts
@@ -170,7 +170,8 @@ export class TerminalSearchLinkOpener implements ITerminalLinkOpener {
 		let resourceMatch: IResourceMatch | undefined;
 		if (osPathModule(this._os).isAbsolute(sanitizedLink)) {
 			const scheme = this._workbenchEnvironmentService.remoteAuthority ? Schemas.vscodeRemote : Schemas.file;
-			const uri = URI.from({ scheme, path: sanitizedLink });
+			const slashNormalizedPath = this._os === OperatingSystem.Windows ? sanitizedLink.replace(/\\/g, '/') : sanitizedLink;
+			const uri = URI.from({ scheme, path: slashNormalizedPath });
 			try {
 				const fileStat = await this._fileService.stat(uri);
 				resourceMatch = { uri, isDirectory: fileStat.isDirectory };


Test patch:
diff --git a/src/vs/workbench/contrib/terminal/test/browser/links/terminalLinkOpeners.test.ts b/src/vs/workbench/contrib/terminal/test/browser/links/terminalLinkOpeners.test.ts
--- a/src/vs/workbench/contrib/terminal/test/browser/links/terminalLinkOpeners.test.ts
+++ b/src/vs/workbench/contrib/terminal/test/browser/links/terminalLinkOpeners.test.ts
@@ -177,7 +177,7 @@ suite('Workbench - TerminalLinkOpeners', () => {
 					type: TerminalBuiltinLinkType.Search
 				});
 				deepStrictEqual(activationResult, {
-					link: 'file:///c%3A%5CUsers%5Chome%5Cfolder%5Cfile.txt',
+					link: 'file:///c%3A/Users/home/folder/file.txt',
 					source: 'editor'
 				});