print("Hello abyss!") in the cell and press Ctrl+Enter)VSCode blissfully discards any unsaved changes.
Either (a) an "Are you sure?"-type confirmation dialog is shown on exit; or (b) the file is restored, when VSCode is relaunched, which is what's done with other file types.
_Please provide as much info as you readily know_
Nah... that ain't me
Microsoft Data Science for VS Code Engineering Team: @rchiodo, @IanMatthewHuff, @DavidKutu, @DonJayamanne, @greazer
Looking at some of the other issues, I see an overarching issue in that the Notebooks are not treated as first class citizen in VSCode.
For example, when I open a Notebook I see this funny thing play out where VSCode will open it as a plain text file first, then quickly hide it and reopen as a Notebook. :woozy_face: That doesn't always work and I end up with a blank file. If I close and reopen, second time is usually a charm. (Should probably file a separate issue for that.)
Thanks for the feedback @dimitry-ishenko , we will take a look!
Came here to complain as I've just lost another notebook and see @rchiodo is working on it. Thank you!
Validated.
Note that this problem is especially bad if VSCode crashes or is closed accidentally (i.e. I errantly typed ctrl-w to delete a word from terminal habit but closed the tab and lost __all__ my work. :facepalm:). Classic Jupyter as served in browser lets you reload the webpage and presents you with your unsaved changes. Likewise, VScode does something similiar with .py files. Please adopt the behavior from .py files:
x or o icon on the notebook viewer tab Thanks so much for this excellent extension :)
@tbenst If I understand it correctly (and @rchiodo can correct me if I am wrong) this and a host of other similar issues all depend on issue microsoft/vscode-jupyter#1326. Notebook support was added through use of some dark voodoo and so they are not treated as first-class citizen in vscode. Until that changes, issues like this will keep popping up.
Yes @dimitry-ishenko you're correct. We're working with VS code to make notebooks a first class citizen of VS code. That work was started here:
https://github.com/microsoft/vscode-python/issues/10496
However the problem with unsaved files not reopening should be fixed already. You do need to reactivate the python extension for it to work. We do have our own 'hot-save' mechanism, which is what VS code calls saving a backup copy of your work while you type.
@rchiodo thank you sir, now I have something to look forward to :smile:
@tbenst actually @rchiodo is correct this has been fixed. What I usually do is keep an empty python tab open to force the python extension reactivation, when I re-launch vscode:

You can even create an empty python tab after you've closed and re-launched vscode and bring your notebook back from the dead:

Unfortunately, this still seems to happen.
I had a notebook with unsaved changes and exited vscode. There was no warning about unsaved changes.
When I restarted vscode with the same workspace, the notebook was not automatically opened. I opened it manually, which must have triggered "reactivation", because then a second copy of the notebook was opened. Maybe that automatically opened second copy contained my unsaved changes – I don't know, because I clicked it away since it seemed redundant.
I cannot find any trace of my unsaved changes in either of .vscode, ~/.vscode , or ~/config/Code. Is there another place I can look for them?
It would be great if one would be warned about unsaved changes upon exiting, or if files.autoSave applied to notebooks.
@allefeld on a windows machine the 'hot exit' files are stored here:
C:\Users\rchiodo.REDMOND\AppData\Roaming\Code\User\globalStorage\ms-python.python
They should have a file with a hash of the original file path.
The root cause of the problem is the activation of the python extension that's required for us to reopen files.
@rchiodo, I think that's ~/config/Code/User/globalStorage/ms-python.python on Linux, thanks. Unfortunately there was nothing there.
Will this problem be solved with the undergoing redesign of custom editors in VS Code? At least a warning about unsaved changes would be extremely useful.
Yes the redesign to use the VS custom editors will eliminate this entirely because we'll suddenly be known as an editor by VS code. They'll handle the hot exit/save/save as for us.
Great, thanks!
@allefeld when I switch Jupyter backend URI, the extension prompts me to restart VScode. I’ve found that it works if I do NOT restart VScode, but that upon restarting I cannot use the backend I entered.
Perhaps this is why unsaved data is still lost for me?
@tbenst, I'm not a developer, just a user like you.
@DavidKutu and I both validated this. Validated.
Most helpful comment
Note that this problem is especially bad if VSCode crashes or is closed accidentally (i.e. I errantly typed ctrl-w to delete a word from terminal habit but closed the tab and lost __all__ my work. :facepalm:). Classic Jupyter as served in browser lets you reload the webpage and presents you with your unsaved changes. Likewise, VScode does something similiar with .py files. Please adopt the behavior from .py files:
xoroicon on the notebook viewer tabThanks so much for this excellent extension :)