-
-
Notifications
You must be signed in to change notification settings - Fork 367
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
Conversation
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.
lgtm
needsParensSpace ExplicitList{} = (All False, All False) | ||
needsParensSpace RecordCon{} = (All False, All False) | ||
needsParensSpace RecordUpd{} = mempty | ||
needsParensSpace _ = mempty |
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.
Do we have a case that "Needs paren" and "Needs space"" are different?
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.
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.
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.
Love the new plugin name 😄
I'm planning on merging this by end of day if nobody disagrees! |
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.
LGTM 👍 Thank you for nice change, and sorry for late reply!
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