microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
164.49k stars 29.37k forks source link

Quick open has duplicate "recently opened" entries #232426

Closed amunger closed 1 week ago

amunger commented 2 weeks ago

Steps to Reproduce:

I have been opening the same file quite a lot recently, and now the quick open menu has several duplicate entries for it:

Image

TylerLeonhardt commented 2 weeks ago

@bpasero I don't think we do anything special to display this. Why would history return duplicate files?

benibenj commented 2 weeks ago

I reported it here initially: https://github.com/microsoft/vscode/issues/229938 See how on windows there both the / and \ separators.

Also, I saw this for global symbol search

bpasero commented 2 weeks ago

@amunger @benibenj when this happens, can you "Log Storage Contents" from F1 and find the history.entries value in workspace storage and diagnose the contents around the duplicates. It is very likely these are actually NOT the same paths when you look at the full absolute resource.

Image

I do not think this issue is related to https://github.com/microsoft/vscode/issues/229938

amunger commented 2 weeks ago

The paths all seem to match

Image

bpasero commented 2 weeks ago

I have a repro when you have the same editor opened multiple times in the editor grid.

vs-code-engineering[bot] commented 1 week ago

This bug has been fixed in the latest release of VS Code Insiders!

@amunger, you can help us out by commenting /verified if things are now working as expected.

If things still don't seem right, please ensure you're on version f87f8a56f3a30238076bee3db39c245bd69be264 of Insiders (today's or later - you can use Help: About in the command palette to check), and leave a comment letting us know what isn't working as expected.

Happy Coding!

amunger commented 1 week ago

I now have these two entries in history.entries, but plenty of duplicates still in there:

"resource": "file:///c%3A/src/vscode-jupyter/src/interactive-window/interactiveWindow.ts#LNaN", "resource": "file:///c%3A/src/vscode-jupyter/src/interactive-window/interactiveWindow.ts",

Image

amunger commented 1 week ago

I'm pretty sure these were populated while I was trying to figure out links in our mermaid chat extension. I did quite a bit of troubleshooting to get the file to open correctly, so this might not be reproable anymore, aside from the entries that I have right now

bpasero commented 1 week ago

@amunger but in the case of file:///c%3A/src/vscode-jupyter/src/interactive-window/interactiveWindow.ts, I see that the resources are not equal, the one has a suffix of #LNaN. Since this is a URI, we probably still succeed opening that resource because its the fragment portion and does not impact the path.

There seems to be code somewhere that actively opens such as URI into VS Code, which is not really supported, but we also do not really prevent this from happening.

Our duplication detection in the history service is purely based on URI.toString(), not taking fragments or query into account.

So we need to figure out how these URIs get into the system, any steps?

amunger commented 1 week ago

the LNaN URI happens from the mermaid extension not properly validating the result of a parseInt call and using the result in vscode.commands.executeCommand('vscode.open', uri);.

There are a bunch of other duplicates in that list in the screenshot that aren't within the history.entries though. Any concern with those?

bpasero commented 1 week ago

@amunger and they are not having this fragment part and are 100% same string?

amunger commented 1 week ago

I don't know how to check if they are the same string - there are only two entries in history.entries, and 7 occurrences of interactiveWindow.ts

bpasero commented 1 week ago

@amunger thats explained in https://github.com/microsoft/vscode/issues/232426#issuecomment-2443291129, the "recently opened" are stored in workspace storage. I would have not assumed that after a restart you would still see them with my fix.

We hash the editor with a key based on this logic:

https://github.com/microsoft/vscode/blob/52b944e89d4a1b313cb8efb1378f652fb72f17f0/src/vs/workbench/services/history/browser/historyService.ts#L1050

The override parameter would mean that the resource is to open with a different editor than the default.

bpasero commented 1 week ago

Maybe you can share the workspace state DB with me.

amunger commented 1 week ago

is that just the contents from "log Storage database contents"? storageDatabaseContents.json

bpasero commented 1 week ago

yes, thanks.