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

Refactor auto save mechanism #13683

Merged
merged 8 commits into from
May 20, 2024
Merged

Refactor auto save mechanism #13683

merged 8 commits into from
May 20, 2024

Conversation

msujew
Copy link
Member

@msujew msujew commented May 5, 2024

What it does

Closes #12863
Closes #12844
Closes #8722

Enhances the SaveResourceService to perform all the auto save preference work. Previously, all editor classes had to do their own handling of the afterDelay auto save functionality. This has been centralized into one service. Therefore, custom editors and notebook editors now behave exactly the same as monaco text editors in regards to auto saves.

This also fixes a long standing issue, where onFocusChange and onWindowChange have been handled as if afterDelay was selected as the auto save mode. These two values are now properly handled.

Note that onWindowChange doesn't work well with custom editors. This is due to the usage of iframe and the inability to look into an iframe. It still works, but is a bit too eager with them.

How to test

Basically, confirm that the auto save functionality behaves as expected with all different values of the enum preference. This should be tested for all 3 kinds of editors (text, notebook, custom editor).

Also test that closing unsaved editors prompts (or automatically saves) the user whether or not to save those files.

Follow-ups

We might want to find a way to fix onWindowChange for custom editors as well based on mouse position event information.

Review checklist

Reminder for reviewers

@msujew msujew added editor issues related to the editor shell issues related to the core shell labels May 5, 2024
@JonasHelming JonasHelming requested a review from tsmaeder May 7, 2024 14:10
Copy link
Contributor

@tsmaeder tsmaeder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First reading of the code.

packages/core/src/browser/save-resource-service.ts Outdated Show resolved Hide resolved
packages/core/src/browser/saveable.ts Outdated Show resolved Hide resolved
packages/editor/src/browser/editor-command.ts Show resolved Hide resolved
packages/core/src/browser/save-resource-service.ts Outdated Show resolved Hide resolved
packages/core/src/browser/save-resource-service.ts Outdated Show resolved Hide resolved
packages/core/src/browser/save-resource-service.ts Outdated Show resolved Hide resolved
packages/core/src/browser/save-resource-service.ts Outdated Show resolved Hide resolved
@@ -364,7 +366,7 @@ export class MonacoEditorModel implements IResolvedTextEditorModel, TextEditorDo
}

save(options?: SaveOptions): Promise<void> {
return this.scheduleSave(TextDocumentSaveReason.Manual, undefined, undefined, options);
return this.scheduleSave(options?.saveReason ?? TextDocumentSaveReason.Manual, undefined, undefined, options);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not quite sure why we differentiate the different "save" operations by reason.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because the vscode API does.

packages/notebook/src/browser/view-model/notebook-model.ts Outdated Show resolved Hide resolved
@msujew msujew mentioned this pull request May 16, 2024
1 task
@msujew msujew requested a review from tsmaeder May 18, 2024 09:13
@tsmaeder
Copy link
Contributor

I've found a weird little bug:

  1. Turn autosave to "off".
  2. Open an editor
  3. Types something
  4. Close the editor
  5. Observe: you get a dialog asking you to save the dirty editor

Works as expected.

  1. Open the settings, set set autosave to "after delay"
  2. Open an editor
  3. Type something in the editor
  4. Observe: after a delay, the "dirty" indicator in the editor tab disappears
  5. Open the "File" menu: there is a checked menu item called "Autosave". Select the item
  6. Open the "File" menu again: observe that the "Autosave" item is unchecked
  7. Type in the editor.
  8. Observe: the "dirty" indicator never goes away.
  9. Close the editor
  10. Observe: there is no dialog asking me to save and the changes I make are saved to disk automatically. My expectation is that I am asked to save the dirty editor upon closing.

Note that I can have the settings open and observe the "autosave" setting change to "off" when I uncheck the menu item, but I only get the "save"-dialog back once I manually edit the setting in the settings editor.

@msujew
Copy link
Member Author

msujew commented May 20, 2024

@tsmaeder Thanks for the repro steps. I believe I ran into a variation of #7480 when using PreferenceChange#newValue, which was undefined after the auto save preference was updated. I'm now using the computed value instead, which seems to work well.

@tsmaeder
Copy link
Contributor

@tsmaeder Thanks for the repro steps. I believe I ran into a variation of #7480 when using PreferenceChange#newValue, which was undefined after the auto save preference was updated. I'm now using the computed value instead, which seems to work well.

From the linked issue :

It's just a matter of time until someone thinks: "I'll just use the new value" and introduces an error.

😎 🤣

@msujew msujew merged commit d9e58c3 into master May 20, 2024
14 checks passed
@msujew msujew deleted the msujew/save-refactoring branch May 20, 2024 22:52
@github-actions github-actions bot added this to the 1.50.0 milestone May 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
editor issues related to the editor shell issues related to the core shell
Projects
Archived in project
2 participants