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

fix #3338 Format Document on save #3640

Closed
wants to merge 1 commit into from
Closed

fix #3338 Format Document on save #3640

wants to merge 1 commit into from

Conversation

lmcbout
Copy link
Contributor

@lmcbout lmcbout commented Nov 26, 2018

Fix #3338
Depends on issue #3617
Note: If #3617 not available, then the java file will need to be saved twice when the user wants to format the file and cleaning up the lines from empty spaces.

Format on Save is only available when the preference autoSave is "OFF"
and the preference 'editor.formatOnSave' is "true"

Signed-off-by: Jacques Bouthillier jacques.bouthillier@ericsson.com

this.formatDocument(monacoEditor)
]).then(() => {
if (edit) {
edits.push(edit);
Copy link
Contributor

Choose a reason for hiding this comment

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

this.getEditsTrimmingTrailingWhitespaces() also returns "edit" that should be pushed in to edits. I believe it is missing in the change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done, adjusted the return value

@lmcbout lmcbout force-pushed the GH-3338 branch 2 times, most recently from 5d64706 to 360b9c3 Compare November 27, 2018 13:33
@vince-fugnitto
Copy link
Member

vince-fugnitto commented Nov 27, 2018

@lmcbout why does formatOnSave only work when auto-save is off?
In vscode, if I manually Save the formatter also kicks in.

Copy link
Contributor

@elaihau elaihau left a comment

Choose a reason for hiding this comment

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

Tested. Works.

@lmcbout
Copy link
Contributor Author

lmcbout commented Nov 27, 2018

@vince-fugnitto If we allow to formatOnSave when the auto-save = "on", depending of the file type it becomes annoying to see the empty space or empty line goes away before you type new chars into the file because the file has been saved and re-formatted

@vince-fugnitto
Copy link
Member

vince-fugnitto commented Nov 27, 2018

@vince-fugnitto If we allow to formatOnSave when the auto-save = "on", depending of the file type it becomes annoying to see the empty space or empty line goes away before you type new chars into the file because the file has been saved and re-formatted

@lmcbout formatOnSave should only be triggered when we explicitly call Save either from the menu, or the keybinding. The auto-save feature does not call the formatter. That's the way vscode does it.

@lmcbout
Copy link
Contributor Author

lmcbout commented Nov 27, 2018

@akosyakov Do you have any comments before we merge it since it has already been approved.
Thanks

monacoEditor.cursor = cursor;
}, 0);
}
if (edit) { edits.push(edit); }
Copy link
Contributor

Choose a reason for hiding this comment

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

this should be broken into multiple lines :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agree, Done

@vince-fugnitto
Copy link
Member

vince-fugnitto commented Nov 27, 2018

@lmcbout I don't think we should limit ourselves to autoSave on or off.
We should call the formatter when the user explicitly calls Save.
The auto-save should not call the formatter and thus the problem you mentioned won't exist.

Format on Save is only available when the preference autoSave is "OFF"
and the preference 'editor.formatOnSave' is "true"

Signed-off-by: Jacques Bouthillier <jacques.bouthillier@ericsson.com>
@akosyakov
Copy link
Member

akosyakov commented Nov 28, 2018

Why is it related to editorconfig extension? It should work even without this extension, only with editor + monaco extensions.

@elaihau
Copy link
Contributor

elaihau commented Nov 29, 2018

@akosyakov could you please suggest which package this logic belongs to, if not put into editorconfig?
editorconfig already does things like "trim tailing whitespace" and "adding a new line", and it also has a .editorconfig that controls the things to be done depending on the file extension.

why do we not want to put all the related things in one place ?

@akosyakov
Copy link
Member

could you please suggest which package this logic belongs to, if not put into editorconfig?

Ideally, it should go to the editor extension, but since it is relays on monaco apis i would implement it in the monaco extension.

editorconfig already does things like "trim tailing whitespace" and "adding a new line", and it also has a .editorconfig that controls the things to be done depending on the file extension.

editorconfig extension is responsible for additional formatting based on .editorconfig file, not for general handling of formatting

Copy link
Member

@paul-marechal paul-marechal left a comment

Choose a reason for hiding this comment

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

As Anton said, this change shouldn't live in editorconfig.

Also, after further investigation, it would seem that onSave contributions such as edits are not correctly handled in Theia as of now. Mostly concurrency issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants