core
core copied to clipboard
Feature Request for moonfmt
Hi, I'm not sure if this is the right place to put this request.
The tooling for MoonBit is superb... excellent work! The tooling (both quality and speed) is a major factor that dramatically distinguishes this programming language from all others, thereby quickly causing MoonBit to replace my former all-time favorite programming language as my new number one choice.
For the VSCode plugin, I have only one minor annoyance. It will move my comments up or down one or more lines instead of leaving them in the exact place that I put them. I would like the tooling to leave my comment exactly where I put it (relative to the surrounding code), because I put it there for a reason.
Thank you!
It will move my comments up or down one or more lines instead of leaving them in the exact place that I put them.
This behaviour is caused by our formatter, could you give us an example how it moves your comment?
Note that if there is an empty line (blank line) between two lines, the formatter will automatically remove the empty line. This is expected behavior but might be changed in the future.
This behaviour is caused by our formatter, could you give us an example how it moves your comment?
Yes, I just now tried to make a simple test case, but failed. The next time it happens I will update this GitHub issue with an example.
Note that if there is an empty line (blank line) between two lines, the formatter will automatically remove the empty line. This is expected behavior but might be changed in the future.
Yes, honestly I don't like this feature either. So as a workaround, I'm already in the habit of adding a blank comment line (//) between parts of a function that I want to be visually separated.
I think Go handles this case really nicely... if you add a single blank line in the middle of a function, it preserves it. However, if you add two or more blank lines in the middle of a function, it compresses all of them down into a single line. I very much like this behavior.
I have an example:
struct Angle {}
struct Point {}
struct ArcSize {}
struct ArcSweep {}
pub trait Path {
/// Adds an arc
arc_to(
Self,
Double, // rx
Double, // ry
Angle, // angle
ArcSize, // size
ArcSweep, // sweep
Point, // to
) -> Self
}
The formatter will yield:
struct Angle {}
struct Point {}
struct ArcSize {}
struct ArcSweep {}
pub trait Path {
/// Adds an arc
// rx
// ry
// angle
// size
// sweep
// to
arc_to(Self, Double, Double, Angle, ArcSize, ArcSweep, Point) -> Self
}
I have an example:
struct Angle {} struct Point {} struct ArcSize {} struct ArcSweep {} pub trait Path { /// Adds an arc arc_to( Self, Double, // rx Double, // ry Angle, // angle ArcSize, // size ArcSweep, // sweep Point, // to ) -> Self }The formatter will yield:
struct Angle {} struct Point {} struct ArcSize {} struct ArcSweep {} pub trait Path { /// Adds an arc // rx // ry // angle // size // sweep // to arc_to(Self, Double, Double, Angle, ArcSize, ArcSweep, Point) -> Self }
Thanks for your example! Making the formatter work correctly needs a lot of time. If you have more examples to show the bad behaviors of moonfmt, opening an issue is welcome.
I also like the way Go's formatter handles blank lines, we will support this in the future. @gmlewis
Closing the issue for now. If there are more bad cases, feel free to submit them here or create new issues.