Description
@Rockvole commented on Thu Feb 01 2018
Intellij provides a handy "ghost" closing tag, unfortunately it can be unhelpful when you need it most - you can get lost with your end brackets when inserting in the middle of a nest of brackets. At that time it can get confusing which end bracket goes where and dartfmt wont help you restructure because you have broken code.
My idea of Auto generated closing tags is like a simulation of XML behaviour - that you have named closing tags to use for reference. XML syntax seems to be something which some are asking for, but Im hoping for an alternative to address the perceived shortfall :
flutter/flutter#11609
What if an end "tag" is placed in the code during dartfmt ? (Not an invisible comment, but actual text ignored by the compiler). After you have finished placing your inserted code you run dartfmt to generate the end tags again.
I'm not sure what the best symbol would be, here I used -
e.g.
body: new Container(
decoration: new BoxDecoration(
image: new DecorationImage(
image: new AssetImage("assets/images/mold_close.jpg"),
fit: BoxFit.cover,
)-DecorationImage,
)-BoxDecoration
)-Container
@zoechi commented on Fri Feb 02 2018
dartfmt
s intention is to only manipulate white space. It doesn't do any other modification.
https://github.com/dart-lang/dart_style/wiki/FAQ#why-doesnt-the-formatter-add-curlies-or-otherwise-clean-up-code
I doubt many would want to have that noise in their code.
In the IDE it's easy to enable/disable if there is a need, but if it would be even committed, this wouldn't be possible.
@Rockvole commented on Sat Feb 03 2018
@munificent - any opinions ?
@munificent commented on Sat Feb 10 2018
I'm not sure what you're asking for here. You want dartfmt to insert new code after every constructor call's argument list? What happens to the inserted code after that?
@Rockvole commented on Sat Feb 10 2018
It would use very similar logic to Intellij's "ghost" closing tag comments which are dynamically added by Intellij. They have some good smarts though, like a one line function call does not have a closing tag.
By using a unique syntax it would be identified as generated code (and so not confused as a user comment), my example uses -
The "closing tags" would be generated by dart only when the user runs dartfmt.
I have edited a lot of xml in the past, and I have found when editing flutter code it can be more tricky to see what is going on with all the nested tags. The intellij "ghost" tags are only visible when code can be parsed, as soon as you start editing or paste some code fragment in, and the code becomes non-parseable, you lose the end-tag references that you previously had. So you can no longer see what was part of a list, or the end of an argument for example.
Additionally the source code which you are copying from would have its "closing tags" intact as part of the copied text and so you can see what comes from the copied code.
@munificent commented on Tue Feb 13 2018
It would use very similar logic to Intellij's "ghost" closing tag comments which are dynamically added by Intellij.
But those are not added to your code, they are just rendered on screen by IntelliJ. They don't appear on the file system, get committed in Git, etc.
dartfmt doesn't draw your code, it just writes files. If it added closing tags, those would end up in the file for your code itself. Since those aren't valid Dart syntax, now you'd have an invalid program.
Or are you proposing that we add some kind of closing tag syntax to Dart itself? If so, that's a bigger topic than just dartfmt. :)
@Rockvole commented on Wed Feb 14 2018
Yes, to add an additional comment style e.g. - _ # not intended to be added by the user.
It looks like a lot of work will be carried out for the optional new and const keywords in order for code to be cleaner (and is used as arguments against needing to add an XML syntax to flutter).
It looks like there is an active group who would like to see an xml syntax added to flutter to improve it and make it as good as JSX.
Feature request: Support JSX like syntax inside dart code.
I think that allowing dartfmt to generate a "closing tag" equivalent would likely squash the remaining advantage (that I can see) that XML has over flutter.
The "closing tag" generation could be turned off with configuration for those who dont want it.
@Rockvole commented on Wed Feb 14 2018
Other XML related questions / issues :
Native XML syntax in Dart for DOM elements
Is flutter going to support xml design?
@maryx commented on Wed Feb 14 2018
The Flutter plugin(?) for VS Code has something similar where it has a "ghost comment" that the user can't create or edit, like this:
@Rockvole commented on Wed Feb 14 2018
Yes, thats the "ghost comments" / "ghost closing tags" that Im talking about - its the same in Intellij.
The problem is once you cut and paste some code (which you intend to modify to get it working) you lose "ghost comments" from anywhere which is temporarily not parseable, so your points of reference have been removed. You can have big chunks of broken code with a clutter of closing brackets and you dont know which lines up with the old code or the newly inserted code, you cant figure out if you just need to move a comma or not.
Or even when just modifying code and you are trying to insert something, the code is temporarily broken and the "ghost comments" which you were using as a point of reference have been removed. Its frustrating because exactly when you need it, it vanishes.
I found cutting and pasting xml fragments to be easier because the closing tags are named and fixed in place, so it is easier to see where the new code should fit.
@Rockvole commented on Thu Feb 15 2018
I think this feature would be better than XML closing tags (for programmers), because :
- Could be turned on / off in preferences. If you dont like the code you are given, run dartfmt and its gone / back the way you like.
- Less typing / editing. You dont need to worry about correctness, so you dont have to cut and paste tags to make brackets match everywhere. (dartfmt takes care of that afterwards).
- Could be automated as part of company code standard during check-in. If its wanted / not-wanted as a company standard - change it automatically during code check-in. The Devs can still work how they prefer.
@Rockvole commented on Thu Feb 15 2018
With respect to dartfmt should not change code - only whitespace. I think this is a different case because its a special type of comment not intended to be edited.
e.g. if we use # for example :
# My comment
^ This is invalid code currently, and also after the new "closing tags" feature
new Text("Hello World",
softWrap: true
)#Text
^ The #Text is autogenerated and not intended for user edits, it is only valid when combined with an end bracket. I don't believe it would be confused as general code and devs would start using it themselves.
@Rockvole commented on Wed Feb 28 2018
@sethladd - what do you think of this ? Its a pretty basic idea but I think it fits with Flutter (e.g. named arguments add clarity and so does this).
The feature would be optional on/off in config. Named closing tags I have seen mentioned as an advantage that JSX has over Dart, so this would squash that argument. Even only added to close flutter Widgets I think it would be worth the effort.
@Rockvole commented on Tue Apr 24 2018
@anders-sandholm - this was an enhancement I thought of to give flutter the feature I miss from xml editing.
@izhangzhihao commented on Sat Aug 11 2018
Try intellij-rainbow-brackets, this plugin didn't generate "ghost" closing tag but rainbowify nested brackets, I think that might help.