Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Opening file with same name but different folder appends a suffix to the filename #143414

Closed
alyssajotice opened this issue Feb 18, 2022 · 14 comments
Assignees
Labels
author-verification-requested Issues potentially verifiable by issue author bug Issue identified by VS Code Team member as probable bug file-io File I/O insiders-released Patch has been released in VS Code Insiders verified Verification succeeded vscode.dev Issues related to vscode.dev web Issues related to running VSCode in the web
Milestone

Comments

@alyssajotice
Copy link

Does this issue occur when all extensions are disabled?: Yes

Version: 1.64.2
Commit: f80445a
Date: 2022-02-09T22:00:24.333Z
Browser: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.80 Safari/537.36 Edg/98.0.1108.50

Steps to Reproduce:

  1. Open vscode.dev
  2. Go to File->Open File and open the file
  3. Click the x in the file bar to close the file
  4. Open the same file again

Expected: The same file opens: test-file.txt
Actual: The same file opens with the suffix -2: test-file.txt-2. This breaks language services for the file.

close-file-error

@bpasero
Copy link
Member

bpasero commented Feb 19, 2022

This maybe impossible for us to fix given #136486

@bpasero bpasero added this to the February 2022 milestone Feb 19, 2022
@bpasero bpasero added vscode.dev Issues related to vscode.dev web Issues related to running VSCode in the web labels Feb 19, 2022
@bpasero
Copy link
Member

bpasero commented Feb 19, 2022

Unfortunately, a handle we get from the local file system API does not carry the full absolute path and as such we do not know whether the same file is opened or a different file with the same name. We store the handle in memory for the duration of the usage and need to come up with a URI to associate the handle with. As such, when a handle with the same name shows up, we just append a number to produce a unique handle identifier. We used to encode this information in the authority part of the URI but that was causing other issues.

I fear it will not be so easy for us to move away from this model.

@bpasero bpasero modified the milestones: February 2022, Backlog Feb 19, 2022
@bpasero bpasero changed the title vscode.dev does not close files outside of workspace properly Opening same file appends a suffix to the fil ename Feb 19, 2022
@bpasero bpasero changed the title Opening same file appends a suffix to the fil ename Opening same file appends a suffix to the filename Feb 19, 2022
@alyssajotice
Copy link
Author

Would it be possible to not store the handle in memory or delete it when closing the file? Then subsequent opens would be treated the same as first opens.

@bpasero
Copy link
Member

bpasero commented Feb 22, 2022

Would it be possible to not store the handle in memory

No, one limitation of the file system handle API is that you can only get a handle by asking the user for a file or folder from a dialog, there is no other way. You cannot just get a handle without the dialog (or maybe drag and drop, but that is equally a user action).

or delete it when closing the file

That is something I would like to avoid actually. Because the layer at where the file system handle comes into the system is really low level and editors are high level. There is no ref-counting of file handles between these 2 components because file handles typically do not have a lifecycle for normal operations. I would not want to add this kind of tangle only to workaround a limitation in the file system API.

@bpasero bpasero added under-discussion Issue is under discussion for relevance, priority, approach file-io File I/O bug Issue identified by VS Code Team member as probable bug and removed under-discussion Issue is under discussion for relevance, priority, approach labels Feb 22, 2022
@bpasero bpasero modified the milestones: Backlog, February 2022 Feb 25, 2022
@bpasero
Copy link
Member

bpasero commented Feb 25, 2022

Wow, I just found out FileSystemHandle.isSameEntry which can be used to compare an existing handle to a new one. With this we can avoid appending numbers to files and even folders that have been opened.

To verify:

  • opening the same file multiple times does not append suffix
  • opening the same folder multiple times does not append suffix
  • ensure you can still open files with same names but different paths

@roblourens roblourens added verified Verification succeeded and removed verified Verification succeeded labels Feb 25, 2022
@alyssajotice
Copy link
Author

This is great. Thanks @bpasero!

@meganrogge meganrogge added verified Verification succeeded verification-found Issue verification failed and removed verified Verification succeeded labels Feb 28, 2022
@meganrogge
Copy link
Contributor

meganrogge commented Feb 28, 2022

I can still reproduce the issue in insiders.vscode.dev

@meganrogge meganrogge reopened this Feb 28, 2022
@meganrogge
Copy link
Contributor

Recording 2022-02-28 at 15 46 11

@bpasero
Copy link
Member

bpasero commented Mar 1, 2022

Same here until I reloaded the page, seems like a caching issue, filed microsoft/vscode-dev#533

@bpasero bpasero closed this as completed Mar 1, 2022
@bpasero bpasero added author-verification-requested Issues potentially verifiable by issue author and removed verification-found Issue verification failed labels Mar 1, 2022
@rzhao271
Copy link
Contributor

rzhao271 commented Mar 1, 2022

I can reopen the same folders and files just fine now, but I see something off after opening two different package.json files:
Screenshot showing second package.json file fail to pick up syntax highlighting

The editor is probably confused at what .json-2 is.

@bpasero
Copy link
Member

bpasero commented Mar 1, 2022

Oh yeah, nice catch. Instead of adding the suffix at the end, we really need to put it before the extension. I can fix that for March!

@bpasero bpasero reopened this Mar 1, 2022
@bpasero
Copy link
Member

bpasero commented Mar 1, 2022

Oh and this was actually the original issue reported too, lets reopen and move to March then, since this is only fixed partially.

@bpasero bpasero modified the milestones: February 2022, March 2022 Mar 1, 2022
@bpasero bpasero removed the author-verification-requested Issues potentially verifiable by issue author label Mar 1, 2022
@bpasero bpasero changed the title Opening same file appends a suffix to the filename Opening file with same name but different folder appends a suffix to the filename Mar 1, 2022
@bpasero bpasero closed this as completed in 6f906f3 Mar 2, 2022
@bpasero
Copy link
Member

bpasero commented Mar 2, 2022

The increment is now put after the file name but before the extension:

image

I cannot really address this for language contributions that match on the full file name, such as .gitignore though, but I think that is tolerable for now until we figure out a better solution.

@bpasero bpasero added the author-verification-requested Issues potentially verifiable by issue author label Mar 8, 2022
@aeschli aeschli added the verified Verification succeeded label Mar 24, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Apr 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
author-verification-requested Issues potentially verifiable by issue author bug Issue identified by VS Code Team member as probable bug file-io File I/O insiders-released Patch has been released in VS Code Insiders verified Verification succeeded vscode.dev Issues related to vscode.dev web Issues related to running VSCode in the web
Projects
None yet
Development

No branches or pull requests

7 participants
@roblourens @bpasero @aeschli @rzhao271 @alyssajotice @meganrogge and others