Skip to content
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

Merged

Conversation

poorna2152
Copy link
Contributor

@poorna2152 poorna2152 commented Sep 20, 2023

Purpose

Describe the problems, issues, or needs driving this feature/fix and include links to related issues.

Fixes #35240

Approach

Describe how you are implementing the solutions along with the design details.

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

Provide high-level details about the samples related to this feature.

Remarks

List any other known issues, related PRs, TODO items, or any other notes related to the PR.

Check List

  • Read the Contributing Guide
  • Updated Change Log
  • Checked Tooling Support (#)
  • Added necessary tests
    • Unit Tests
    • Spec Conformance Tests
    • Integration Tests
    • Ballerina By Example Tests
  • Increased Test Coverage
  • Added necessary documentation
    • API documentation
    • Module documentation in Module.md files
    • Ballerina By Examples

@poorna2152 poorna2152 requested a review from hevayo as a code owner September 20, 2023 06:46
@codecov
Copy link

codecov bot commented Sep 20, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (b2ac9a9) 0.00% compared to head (5943864) 76.33%.
Report is 14 commits behind head on master.

❗ Current head 5943864 differs from pull request most recent head 80ef085. Consider uploading reports for the commit 80ef085 to get more accurate results

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.
📢 Have feedback on the report? Share it here.

@poorna2152 poorna2152 changed the title Fix removal of whitespace between invalid tokens Fix removal of whitespace between invalid tokens in formatter Sep 20, 2023
@poorna2152 poorna2152 added Team/CompilerFE All issues related to Language implementation and Compiler, this exclude run times. Area/Formatting labels Sep 21, 2023
@lochana-chathura lochana-chathura self-requested a review September 21, 2023 04:08
public function main() {
var c = from var i in 0 ... 5
select i
where i %2 != 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
where i %2 != 0;
where i % 2 != 0;

Is it possible to make this space?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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

Copy link
Contributor

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.

Copy link
Contributor

@LakshanWeerasinghe LakshanWeerasinghe Sep 22, 2023

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?

Copy link
Contributor Author

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

Copy link
Member

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.

@github-actions
Copy link

github-actions bot commented Oct 7, 2023

This PR has been open for more than 15 days with no activity. This will be closed in 3 days unless the stale label is removed or commented.

@github-actions github-actions bot added the Stale label Oct 7, 2023
@poorna2152 poorna2152 removed the Stale label Oct 8, 2023
public function main() {
var c = from var i in 0 ... 5
select i
where i %2 != 0;
Copy link
Member

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();
Copy link
Member

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.

Copy link
Contributor Author

@poorna2152 poorna2152 Oct 18, 2023

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

Copy link

github-actions bot commented Nov 2, 2023

This PR has been open for more than 15 days with no activity. This will be closed in 3 days unless the stale label is removed or commented.

@github-actions github-actions bot added the Stale label Nov 2, 2023
@poorna2152 poorna2152 removed the Stale label Nov 3, 2023
Copy link

This PR has been open for more than 15 days with no activity. This will be closed in 3 days unless the stale label is removed or commented.

Copy link

github-actions bot commented Dec 4, 2023

This PR has been open for more than 15 days with no activity. This will be closed in 3 days unless the stale label is removed or commented.

@github-actions github-actions bot added the Stale label Dec 4, 2023
@poorna2152 poorna2152 removed the Stale label Dec 5, 2023
Copy link

This PR has been open for more than 15 days with no activity. This will be closed in 3 days unless the stale label is removed or commented.

Copy link

github-actions bot commented Jan 5, 2024

This PR has been open for more than 15 days with no activity. This will be closed in 3 days unless the stale label is removed or commented.

@github-actions github-actions bot added the Stale label Jan 5, 2024
@poorna2152 poorna2152 removed the Stale label Jan 6, 2024
Copy link
Member

@lochana-chathura lochana-chathura left a 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

@poorna2152 poorna2152 force-pushed the ws_in_invalid_tokens branch from 9507c9f to 80ef085 Compare January 9, 2024 05:28
@lochana-chathura lochana-chathura merged commit 9e00ea7 into ballerina-platform:master Jan 9, 2024
16 checks passed
@poorna2152 poorna2152 added this to the 2201.9.0 milestone Mar 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area/Formatting Team/CompilerFE All issues related to Language implementation and Compiler, this exclude run times.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Formatter should not remove all whitespaces between invalid tokens
3 participants