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

Context-aware ExactPrint grafting for HsExpr #1489

Merged
merged 8 commits into from Mar 5, 2021

Conversation

isovector
Copy link
Collaborator

In #1486, it's pointed out that always inserting a leading space when grafting trees will break layout (and thus the parse) if you're grafting into a do block. Yikes.

This PR adds a function graftExpr which tracks the tree context of the graft's destination. If the immediate parent of the destination is a function application, or a few other things, we need to insert that space.

And hey, while we're looking at context, let's use it to determine if we need parentheses!

Fixes #1486

@isovector isovector requested a review from konn March 4, 2021 04:45
@isovector isovector requested a review from alanz March 4, 2021 05:01
Copy link
Member

@jneira jneira left a comment

Choose a reason for hiding this comment

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

lgtm

needsParensSpace ExplicitList{} = (All False, All False)
needsParensSpace RecordCon{} = (All False, All False)
needsParensSpace RecordUpd{} = mempty
needsParensSpace _ = mempty
Copy link
Member

Choose a reason for hiding this comment

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

Do we have a case that "Needs paren" and "Needs space"" are different?

Copy link
Collaborator Author

@isovector isovector Mar 4, 2021

Choose a reason for hiding this comment

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

Today, no, but in general they are not the same. For example, if you are grafting into a + _, you need the space but you only need parens if you contain an operator with associativity < 5. I plan to implement this in the future, and want to leave the path open, but #1486 is a high-priority bug to fix.

Copy link
Member

Choose a reason for hiding this comment

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

Love the new plugin name 😄

@isovector
Copy link
Collaborator Author

I'm planning on merging this by end of day if nobody disagrees!

Copy link
Collaborator

@konn konn left a comment

Choose a reason for hiding this comment

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

LGTM 👍 Thank you for nice change, and sorry for late reply!

@isovector isovector added the merge me Label to trigger pull request merge label Mar 5, 2021
@mergify mergify bot merged commit 15cc5d1 into haskell:master Mar 5, 2021
@isovector isovector deleted the fix-bind-layout branch April 5, 2021 11:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merge me Label to trigger pull request merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Wingman inserts layout-breaking spaces when case-splitting in do block
4 participants