-
Notifications
You must be signed in to change notification settings - Fork 32
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
deltaposition anchor inconsistency #62
Comments
The model is used because the AST elements follow a definite structure, and must be able to nest, indent, etc. The comments can appear anywhere, and simply take up what would otherwise be whitespace. There is a substantial amount of complexity/subtlety to get the thing to actually work, so I am not confident that the requested change can be done easily. I would welcome a PR to do it, so long as all the tests still pass with it. |
I don't see how my encoding would not be able to nest, indent, etc. But you certainly have a better picture of the many special cases around this stuff. But regardless, does the current model not break for refactoring operation such as, lets say, "transform a:[b,c] into [a,b,c]"? Because the DP of the comma between But I can completely understand that redesigning this would be an enormous amount of work. So I'd like to ask a different question: Would you be opposed to adding redundant information to the exactprint/annotation API, where this additional data is not used for exactprinting but available for downstreams like brittany? The "DP relative to the last non-whitespace character" would be such data that would enable brittany to support retaining empty lines inside literals (tuples, lists, etc.) Of course that usecase is not terribly important, but I have encountered situations where such feature would be nice-to-have. Either way, thanks for considering. |
I wrestled with this today too. All I wanted was to get {-# LANGUAGE Foo #-}
{-# LANGUAGE Bar #} The DP of both of those is {-# LANGUAGE Foo #-}
{-# LANGUAGE Bar #}
foo = 12 Then suddenly the DP of the second pragma has |
Considering the elements of annsDP, and the anchor of DPs for the contained elements:
(AnnComment _, _someDP)
the DP is relative to the "current cursor position", i.e. relative to the end of the last thing inserted when pretty-printing;(G _, _someDP)
the DP is relative to the node's position (the "cursor position" before pretty-printing anything for the relevant node.Consider this example:
That is, node-relative DPs change when using a different layout for some random child node. If at all possible, an encoding that does not change for such a re-format should be used instead. This would make it much easier for
brittany
to respect/retain such additional newlines.(And imho the status quo is just inconsistent and surprising, and it requires additional statefulness when processing annotations.)
The text was updated successfully, but these errors were encountered: