The main scenario here is when the user switches git branches where the starting branch has a file that the branch being switched to does not. What I'm seeing is the file in question is removed from the open editor. I would like for that file to remain open, just unsaved. Similar to how Sublime handles it.
might be similar to issue #101
steps to reproduce:
expected behavior:
file remains open in editor unsaved.
actual behavior:
file is removed from the editor.
If we do this I will get the exact opposite bug that users complain a tab is not closed when a file is deleted :)
could you implement it as a setting that can be overridden at the user/workspace settings?
+1 This feature in Sublime text has saved my ass once or twice when I've accidentally deleted a file I was using.
VS Code's auto-save feature comes close to this, but doesn't deliver the same functionality as Sublime. While an auto-saved file stays open after the file has been deleted, when you change tabs the contents disappears and an error is displayed.
Adding more than a 👍, because I feel this issue deserves reconsideration, and I have a proposal to reconciliate @bpasero's point of view with our pain.
First, to synthesize:
initialbranch git branch.git checkout otherbranch (where these files don't exist) later, vscode closes all 12 tabs, and when I come back to initialbranch, the pain is on me to re-open these 12 files :-/In Sublime/Atom, the editor tab status communicates the file is dirty, but as soon as the file is back and in the same state as initially, the dirty tab flag disappears and I can keep on hacking on initialbranch. Smooth.
"Code closed 12 files that disappeared. [Okay], [Re-open]" ?What do you think?
I looked into this and I am hitting an issue that is kind of blocking. First of all, what other editors seem to do is:
foo.ts to bar.ts will show foo.ts as dirty even though it has been renamed - main reason for this is that it is hard to track file renames from external applications, they show up as DELETE and ADD)My idea was to introduce a new setting workbench.editor.closeOnExternalFileDelete that is true by default:
Controls if editors showing a file should close automatically when it is deleted or renamed by some other process. Disabling this will keep the editor open as dirty. Note that deleting from within the application will always close the editor and that dirty files will never close to preserve your data.
Now this works fine up to a certain point: imagine you have 2 tabs open foo.ts and bar.ts. You restart and the 2 tabs are still opened, but in Code, only the first tab is actually loaded into memory (because the file is displayed in the editor). The second tab is not loaded until you click on it. Now imagine you delete the second, not active tab from an external process (bar.ts). I cannot keep the tab open, nor mark it dirty because at this time I do not have the contents of the file anymore.
Interestingly ST seems to have solved this, I can only imagine that tabs which are open are loaded from disk into memory (which is ugly).
Not sure what to do for this case, it is also ugly to close tabs that are not loaded.
Btw for those people that randomly see tabs closing even though the file is still there, please see https://github.com/Microsoft/vscode/issues/13665#issuecomment-283922320 for helping me out finding the underlying issue.
I pushed a change to introduce a new setting "workbench.editor.closeOnExternalFileDelete" that is by default set to true. If you flip it to false, there is some interesting things happening:
There are some underlying implications as well in this state:
This needs some good testing, so feedback welcome (will be in tomorrows insider build).
Reopening based on some feedback from the team which I want to capture here (without opinion):
By the way, Atom 1.15 is at it too:
Tabs of deleted files are retained
By popular demand Atom will now keep open the tab of any file, modified or not, when it’s deleted outside the editor. You can turn off this behavior with a new core setting:
One of the main concerns we have to solve is if marking such a deleted file as dirty is a good decision. It may draw the wrong impression to the user because so far we only show the dirty indicator when changes have been made by the user. Happy to hear thoughts from people subscribed to this issue on that topic.
Personally, I've seen the functionality being discussed here in other IDEs and have grown accustomed to it. With that said, given such scenario, if vs code does a Save As when the user tries to save the file (because it's marked dirty), it isn't really a drawback or inconvenience in my opinion. And I can safely assume the majority of the community using vs code is rather tech savvy and would know what's going on.
After lots of feedback from the team and discussion, we settled on a solution that does NOT mark the editor as dirty but just indicate to the user that the file has been deleted on disk:

Marking the file as dirty has some consequences that we are worried about:
Imho this setting should eventually be the new default, but I want to give it some more testing and feedback.
The setting is now called: workbench.editor.closeOnFileDelete
Most helpful comment
+1 This feature in Sublime text has saved my ass once or twice when I've accidentally deleted a file I was using.
VS Code's auto-save feature comes close to this, but doesn't deliver the same functionality as Sublime. While an auto-saved file stays open after the file has been deleted, when you change tabs the contents disappears and an error is displayed.