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

How to implement hot exit on a custom editor? #96484

Closed
roblourens opened this issue Apr 28, 2020 · 8 comments
Closed

How to implement hot exit on a custom editor? #96484

roblourens opened this issue Apr 28, 2020 · 8 comments
Assignees
Labels
custom-editors Custom editor API (webview based editors)
Milestone

Comments

@roblourens
Copy link
Member

Testing #96315

I wanted to implement hot exit, but I am confused about how to restore the backup. VS Code called backupCustomDocument and told the extension where to store the backup. How can the extension know where the backup is after a reload? Is it expected to save the location to storage somewhere? It seems like VS Code mainly manages backups so I expected that it would call a method to restore from the backup at location X.

@mjbvz
Copy link
Collaborator

mjbvz commented Apr 28, 2020

In openCustomDocument, the context has a backupId property. This is only set when we are restoring the editor from a backup (such as on reload).

However your extension is responsible for restoring itself. Usually this just means reading the editor's initial content from the backup location instead of from the workspace

Try using backupId and let me know if you find any bugs or have suggestions on how the documentation could be improved here

@mjbvz mjbvz added the custom-editors Custom editor API (webview based editors) label Apr 28, 2020
@mjbvz mjbvz added this to the April 2020 milestone Apr 28, 2020
@roblourens
Copy link
Member Author

roblourens commented Apr 29, 2020

I didn't notice that PawDraw uses that, but backupId is not set when I go through a hotExit flow

  • Debug PawDraw
  • Disable autosave
  • Make an edit
  • Reload the window
  • backupId is undefined

Also, why is there an id instead of giving it the path? Are there cases where the backup will be saved in multiple documents and the suggested path will be ignored?

@mjbvz
Copy link
Collaborator

mjbvz commented Apr 29, 2020

Yes, the id is entirely up to the extension. I just used the path as the id for convenience. Other extensions may maintain their own mapping between id and their backup resources

@roblourens
Copy link
Member Author

Got it, but it does seem to be broken in my testing and hot exit doesn't work in PawDraw

@mjbvz mjbvz closed this as completed in cc1e59b Apr 29, 2020
@mjbvz
Copy link
Collaborator

mjbvz commented Apr 29, 2020

Pushed fixed to VS Code and to the extension sample. Should be working now but let me know if you still see issues

@caponetto
Copy link

caponetto commented Apr 30, 2020

@mjbvz
I've tested the latest updates but I'm still seeing some issues.
I'm able to reproduce them on both PawDraw and my custom editor.

Sometimes, when I reopen VSCode having unsaved changes, the editor is not properly loaded.
Also, it seems that the editor is on an invalid state because I can't close the tab. I can't even close VSCode. I had to kill the process.
backup-1

I managed to properly reopen the editor once I close VSCode with a text editor on focus.
However, I still can't save or discard the changes.
I can only move forward if I do a new edit.
backup-2

EDIT: One more thing for the scenario where I make some changes, save them and close VSCode. When I reopen VSCode, despite there are no changes, the backupId is not undefined and sometimes the editor is loaded with the dirty indicator.

Hope this helps.

@mjbvz
Copy link
Collaborator

mjbvz commented May 1, 2020

@caponetto Thanks for testing! Please try out the next VS Code insiders build with the extension sample from here: https://github.com/microsoft/vscode-extension-samples/tree/master/custom-editor-sample

There were bugs with both VS Code implementation and with the extension sample

@caponetto
Copy link

Thanks, @mjbvz! These issues I've reported above are gone.

@github-actions github-actions bot locked and limited conversation to collaborators Jun 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
custom-editors Custom editor API (webview based editors)
Projects
None yet
Development

No branches or pull requests

3 participants