Repository: microsoft/vscode (TypeScript)
Date: 2022-06-03 17:24:09+00:00
Task type: Bug Fix

Issue:
Copy path commands using wrong path separator on macOS
Repro:

1. Open a file in vscode, example terminalProcess.ts
2. Run copy relative path command
3. Paste `src\vs\platform\terminal\node\terminalProcess.ts` 🐛 
4. Run copy path of active file command
5. Paste `\Users\daimms\dev\Microsoft\vscode\src\vs\platform\terminal\node\terminalProcess.ts` 🐛 

We should add some unit tests for this or improve existing ones to catch this case.


Issue discussion:
Thanks for creating this issue! We figured it's missing some basic information or in some other way doesn't follow our [issue reporting guidelines](https://aka.ms/vscodeissuereporting). Please take the time to review these and update the issue.

Happy Coding!
Latest insiders, macOS, any workspaces. I use these commands many times per day and it's a huge pain to swap the separators every time.

Version: 1.68.0-insider
Commit: 4589815e4849499c67125ff68563fa102646b869
Date: 2022-06-01T05:17:25.414Z
Electron: 17.4.6
Chromium: 98.0.4758.141
Node.js: 16.13.0
V8: 9.8.177.13-electron.0
OS: Darwin x64 21.5.0
Can you try to run `code --disable-extensions --user-data-dir <directory>` where `<directory>` is an empty folder? This will ensure Code is starting with a fresh data directory, e.g. no specific settings and without any extensions running.
Still happens with `code --disable-extensions --user-data-dir <directory>`
I'm looking into it now to make sure it's not on my end
I was asking because there is a `explorer.copyRelativePathSeparator` setting, but it only applies to copying relative paths.
I tried clearing user data dir again and it worked, not sure what happened before, might not have made it into the clipboard for some reason or I made a mistake. When I repro it with extensions disabled and all settings cleared there are several `file` formatters with the wrong separator:
<img width="438" alt="Screen Shot 2022-06-01 at 9 07 40 am" src="https://user-images.githubusercontent.com/2193314/171450028-bee5b505-4fbe-4f89-b562-e759252d051e.png">

Definitely don't have `explorer.copyRelativePathSeparator` set.
The bad formatters are coming through via the momento:

https://github.com/microsoft/vscode/blob/a365dbaf5c9907b3e32ee5c9d6b8ae44c7365f51/src/vs/workbench/services/label/common/labelService.ts#L146-L147

Can extensions register these? Any ideas on how I could track down the source? I'll try adding my extensions in the clear user data dir.
`code --user-data-dir <directory>` to load all my extensions doesn't repro, I don't suppose the momento is synced across platforms?

![image](https://user-images.githubusercontent.com/2193314/171452635-34691ef1-0350-4d71-a105-e1a59768acf2.png)

Likely cause of regression: a365dbaf5c9907b3e32ee5c9d6b8ae44c7365f51 cc @connor4312 
PR out: https://github.com/microsoft/vscode/pull/150987
@sbatten this didn't end up fixing it because the synced formatters still seem to be getting pulled in. Any ideas on how we should clear out the bad cache? I was hoping this would be a quick drive by fix.
Anywhere labels are used gets impacted for multi platform users:
<img width="396" alt="Screen Shot 2022-06-03 at 4 53 07 am" src="https://user-images.githubusercontent.com/2193314/171848558-043837f3-f586-4eaf-a2cd-262e1f8e9a83.png">


I think a bandaid fix is to either revert this change entirely or change the storage key that is used.
@Tyriar I don't think anyone has a strong preference on name so updating the storage key name is sane to me.
@sbatten thanks, will do this today

Solution patch:
diff --git a/src/vs/workbench/services/label/common/labelService.ts b/src/vs/workbench/services/label/common/labelService.ts
--- a/src/vs/workbench/services/label/common/labelService.ts
+++ b/src/vs/workbench/services/label/common/labelService.ts
@@ -142,7 +142,7 @@ export class LabelService extends Disposable implements ILabelService {
 		this.os = OS;
 		this.userHome = pathService.defaultUriScheme === Schemas.file ? this.pathService.userHome({ preferLocal: true }) : undefined;
 
-		const memento = this.storedFormattersMemento = new Memento('cachedResourceFormatters', storageService);
+		const memento = this.storedFormattersMemento = new Memento('cachedResourceLabelFormatters', storageService);
 		this.storedFormatters = memento.getMemento(StorageScope.GLOBAL, StorageTarget.MACHINE);
 		this.formatters = this.storedFormatters?.formatters || [];
 


Test patch:
diff --git a/src/vs/workbench/services/label/test/browser/label.test.ts b/src/vs/workbench/services/label/test/browser/label.test.ts
--- a/src/vs/workbench/services/label/test/browser/label.test.ts
+++ b/src/vs/workbench/services/label/test/browser/label.test.ts
@@ -166,7 +166,7 @@ suite('URI Label', () => {
 
 
 	test('label caching', () => {
-		const m = new Memento('cachedResourceFormatters', storageService).getMemento(StorageScope.GLOBAL, StorageTarget.MACHINE);
+		const m = new Memento('cachedResourceLabelFormatters', storageService).getMemento(StorageScope.GLOBAL, StorageTarget.MACHINE);
 		const makeFormatter = (scheme: string): ResourceLabelFormatter => ({ formatting: { label: `\${path} (${scheme})`, separator: '/' }, scheme });
 		assert.deepStrictEqual(m, {});