gmlewis / flutter-stylizer

Flutter Stylizer is a VSCode extension that organizes your Flutter classes and mixins in an opinionated and consistent manner.
https://marketplace.visualstudio.com/items?itemName=gmlewis-vscode.flutter-stylizer
Apache License 2.0
23 stars 3 forks source link

Stylize on Save #2

Closed zgosalvez closed 3 years ago

zgosalvez commented 5 years ago

How can we automatically stylize on save?

{
  "editor.codeActionsOnSave": {
    "source.organizeImports": true,
  },
}
gmlewis commented 5 years ago

Thanks for the question, @zgosalvez.

Currently, the extension doesn't support stylize-on-save, but if there is enough interest, I could add that (or someone else could add that and submit a pull-request to this GitHub repo).

I was about to list reasons why it shouldn't be implemented and enabled for general usage (mainly because it would be annoying to wait the one or more seconds to stylize before saving)...

But then I realized that if you are handed a large project for which you want to stylize all the source files, it might be nice to simply visit every .dart file, add a space and save each file, and have the extension immediately stylize it before saving... thereby quickly stylizing the whole codebase quickly. (After which, you would probably turn off stylize-on-save due to the annoying delay and the fact that once stylized, source files tend to stay ordered until the next big refactor.)

So I'll leave this issue open, and if there seems to be interest, I'll look into adding that feature (again, unless someone beats me to it which I'm totally open to).

gmlewis commented 5 years ago

There hasn't been any conversation on this issue, but @sketchbuch is providing a button on the status bar that will make it super-easy to stylize any .dart file.

~I'll keep this issue open until we merge #7 but then will probably close it.~

Thank you, @zgosalvez.

zgosalvez commented 5 years ago

@gmlewis I use the command palette which is faster than clicking on a status bar button.

I took a look at the PR and it says something about "Added an activation event for stylizer: When an editor with the language type dart is opened." Does this mean we can have a setting to automatically enable styling whenever a dart file is opened?

sketchbuch commented 5 years ago

Hi, yes the statusbar button is not for everyone but I don't like the command palette and always forget shortcut keys so for me the button is quicker and easier! I guess I could add an option to enable the button for those who don't want it - but I have never added extension configuration before so I would need time to look at how to do this.

Currently the extension is activated when you try and invoke the command the first time. But in order for me to be able to show the statusbar button when the active editor's language is dart I need an activation event for that. So basically the extension - assuming my PR is accepted - would also activate if you open a dart file.

This doesn't mean it would be processed automatically upon opening, but processing as soon as the file is opened could probably be done too.

I would like mutiple dart files to be processed at once and also to build in "format on save" functionality but these should probably be a different pull request - it is out of the scope of what my PR is trying to do

gmlewis commented 3 years ago

Closing issue due to available workarounds.