Closed brandonchinn178 closed 2 years ago
I agree that sth like this would be useful, and it should not be too difficult as we already have diffing functionality in Ormolu.
So far, I often used the "Show internal parse result" option of Ormolu Live to debug differing ASTs. It seems like this is only really useful for someone intending to contribute to Ormolu/Fourmolu, so maybe we can expect that they know how to look at the GHC AST in some way (e.g. -ddump-parsed-ast
)?
There is also no mention of using --unsafe to bypass it temporarily.
I agree, seems reasonable to mention it as a stopgap measure.
This is a great idea.
Just for clarification: @brandonchinn178 writes above:
Show a diff between the original version and formatting with --unsafe on the particular lines / show some representation of the AST that differs
In #878, we only display the diff of the source code, but not of the AST. Depending on the context/type of bug, both can be useful. Any thoughts @mrkkrp?
Hmm, good point. I somehow missed the AST bit. I am not sure what is the best way handle this. Perhaps we could pretty-print ASTs before/after as text and then use our existing diffing functions to present the result? Do you have other ideas?
Perhaps we could pretty-print ASTs before/after as text and then use our existing diffing functions to present the result? Do you have other ideas?
Yeah, pretty-printing with showAstData
like in Ormolu Live and then diffing would already be pretty useful I think.
Other than that, my only idea is to extract a Tree
via the Data
instance and then diff it via sth like treeDiff
for more precision, but that would require significantly more work for unclear benefit.
To be clear, I think anything would be better than the current situation. I don't have too strong a preference what to diff, but just to show something to make the error less opaque.
@brandonchinn178 Can you try #878 and let me know what you think? Do you deem it "good enough"?
@amesgen I have to admit, I am hesitant to add AST diffing because
pipes
demonstrate) can be a lot of output. If we add AST diff to it, it would be two different kinds of diffs per an error, which may be too much for what it is (a quick error message for users, first and foremost).Yeah, having only the textual diff is also completely reasonable IMO :+1:
Great, thanks!
Is your feature request related to a problem? Please describe. The current error shown when Ormolu formats things in a way that changes the AST is very opaque. It's perhaps intentionally so, as the error always indicates a bug on Ormolu's side, but it does cause a block in the immediate work waiting on a response after opening an issue. There is also no mention of using --unsafe to bypass it temporarily.
Describe the solution you'd like The error message already shows the lines affected. It would be great to:
Describe alternatives you've considered
Additional context