eclipse-theia/theia

[editor] Format the text on saved.

lmcbout opened this issue ยท 6 comments

When editing in any editors, on saved, the data inside the file should be formatted. The text should be aligned.

Great suggestion! Having an option to do this would be nice.

This could be used for example to run Prettier on Save (but since this is opinionated, I think it should be a configuration option).

Prettier is designed to be integrated into editors to format on save. It has many existing editor integrations.

Running it automatically on save would be a big help for Shields contributors (badges/shields#2783), and similarly for any other project using Prettier.

Exciting! @paulmelnikow If I understand @lmcbout's pull request correctly, we "just" need to somehow hook the monaco.editor.action.formatDocument action up with Prettier for Shields, and set the editor.formatOnSave preference to true.

EDIT: I'll look into how this can be automated for Shields on Gitpod.

is there a way to format with prettier on save now? Was trying:

"[javascript]": {
    "editor.formatOnSave": true
}

but not working

@sojohnnysaid I think you may also want to install https://github.com/prettier/prettier-vscode in Theia, e.g. by downloading a .vsix file, and by drag-and-dropping it into Theia's extension panel on the left.

EDIT: You could download it from https://open-vsx.org/extension/esbenp/prettier-vscode