-
Notifications
You must be signed in to change notification settings - Fork 758
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 removal of whitespace between invalid tokens in formatter #41417
Fix removal of whitespace between invalid tokens in formatter #41417
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #41417 +/- ##
=============================================
+ Coverage 0.00% 76.33% +76.33%
- Complexity 0 52488 +52488
=============================================
Files 9 2881 +2872
Lines 35 198462 +198427
Branches 0 25802 +25802
=============================================
+ Hits 0 151496 +151496
- Misses 35 38604 +38569
- Partials 0 8362 +8362 ☔ View full report in Codecov by Sentry. |
public function main() { | ||
var c = from var i in 0 ... 5 | ||
select i | ||
where i %2 != 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
where i %2 != 0; | |
where i % 2 != 0; |
Is it possible to make this space?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you suggesting that the formatter should add the space after %
in this case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is a Invalid Node and this is a syntax error the formatter is not aware of the context. Thus if the user have not specified a whitespace this does not add a whitespace
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay. I didn't see there is an syntax error there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you point a test where this formatting is working?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I updated the approach to describe what this PR does and the test added to the PR and the tests skipped here are the tests this PR fixes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO, we should keep the formatting of invalid node and its minutiae intact. As it is invalid we should not format it rather skip it from the formatter.
This PR has been open for more than 15 days with no activity. This will be closed in 3 days unless the |
public function main() { | ||
var c = from var i in 0 ... 5 | ||
select i | ||
where i %2 != 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO, we should keep the formatting of invalid node and its minutiae intact. As it is invalid we should not format it rather skip it from the formatter.
@@ -4346,7 +4346,9 @@ private MinutiaeList getTrailingMinutiae(Token token) { | |||
|
|||
// Preserve the necessary trailing minutiae coming from the original token | |||
int consecutiveNewlines = 0; | |||
for (Minutiae minutiae : token.trailingMinutiae()) { | |||
int size = token.trailingMinutiae().size(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need to handle this for leading minutiae as well. In the parser, we attach invalid nodes to both leading and trailing minutiae.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the case of leading minutiae having invalid nodes the removal of all the whitespace between tokens does not happen. In this case this code section is invoked . And in the both of the branches of the if condition it adds at least one whitespace between the tokens. The getPreservedIndentation
function also returns an integer greater than 0
This PR has been open for more than 15 days with no activity. This will be closed in 3 days unless the |
This PR has been open for more than 15 days with no activity. This will be closed in 3 days unless the |
This PR has been open for more than 15 days with no activity. This will be closed in 3 days unless the |
This PR has been open for more than 15 days with no activity. This will be closed in 3 days unless the |
This PR has been open for more than 15 days with no activity. This will be closed in 3 days unless the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's sync the PR with master
...es/formatter-core/src/main/java/org/ballerinalang/formatter/core/FormattingTreeModifier.java
Outdated
Show resolved
Hide resolved
9507c9f
to
80ef085
Compare
Purpose
Fixes #35240
Approach
In the case of invalid tokens this indents the code as necessary and preserves the formatting done by the user and stops removal of whitespaces.
Samples
Remarks
Check List