-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
fix #3338 Format Document on save #4012
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -308,7 +308,7 @@ export class MonacoEditorModel implements ITextEditorModel, TextEditorDocument { | |
} | ||
|
||
protected async doSave(reason: TextDocumentSaveReason, token: CancellationToken): Promise<void> { | ||
if (token.isCancellationRequested || !this.resource.saveContents || !this.dirty) { | ||
if (token.isCancellationRequested || !this.resource.saveContents) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it should be reverted? save should be aborted if a document is not dirty There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess what @lmcbout wanted to do here is "formatting the file on users hitting CTRL+S even if the file is not dirty" - vsCode does it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is exactly the reason, to allow "CTRL+S" like vscode does There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please check whether VS Code actually save changes or only try to apply formatting. In cloud case sending unchanged content is expensive and we should avoid doing it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried VSCode with the file (theia/.vscode/launch.json). The file is not dirty. By selecting "CTRL+S", it reformatted the file and saved it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I meant in our case if formatting does nothing we should not write anything to the disk. It is expensive for large files. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After the formatting, the frontend is using the monaco-editor-model.doSave() const changes = this.popContentChanges();
if (changes.length === 0) {
return;
} This is the same as testing isDirty(). In fact we could use: if (this.dirty) return; to replace those lines above and it would do the same here . So as a resume, the file remains in the frontend if there is no formatting , they are not sent to the backend when there is no changes. |
||
return; | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it should be reverted right? save should not do anything if a document is not dirty