-
Notifications
You must be signed in to change notification settings - Fork 1
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
feat: Add pretty printer for expressions. #564
Conversation
5672178
to
56183b2
Compare
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.
The actual important Haskell code in prettyExpr
and prettyType
is great. And the output is indeed very pretty! Most of the comments above are fairly nitpicky.
I have a few more suggestions related to git. Depending on how comfortable you are with git rebasing, maybe we should save these for when we next meet in person. I'm also happy not to actually fix any of these, and just bear these points in mind as guidance for the future, as long as @dhess feels the same way.
- We try to follow the Conventional Commits spec (but we aren't particularly strict about it). The commit 10b6a70 is missing a
fix:
/feat:
/refactor:
prefix. - It's not super important, but commit messages are usually written in the imperative present tense. So, for example, change "Implemented" to "Implement".
- The commit history is slightly messy in places. For example, some of the changes in 10b6a70 seem like they'd belong better in 56183b2.
Also CI is currently failing. The reasons can be seen by clicking on one of the red crosses, but to be fair, the output isn't always easy to decipher.
- The added test is failing. You can see this by running on your local machine:
:main -p Pretty
fails now that we print types properly. Try:main -p Pretty --accept
and commit the new version. - Weeder is complaining about the fact that three of the added functions have been removed.
- We should definitely add
prettyPrintExpr
andprettyPrintType
to theignoreRoots
list inweeder.dhall
, since they fit the description in the comment there. - On the other hand,
not
should perhaps just be removed. It was a convenience for exploratory testing, but now that we have actual tests it doesn't serve much purpose. Alternatively, we could utilisenot
in a new test case inTests.Pretty
. There's something to be said for having a simpler, more legible test case in addition to testing the large (and nonsensical)comprehensive
definition.
- We should definitely add
- The Cabal file is no longer formatted as we require. This is actually my bad, as I'm the one who added the dependency with a long name (
prettyprinter-ansi-terminal
). Runcabal-fmt -i primer/primer.cabal
.- FWIW, I believe the next release of HLS will have support for
cabal-fmt
, so that we can just use format-on-save as we do for our.hs
files.
- FWIW, I believe the next release of HLS will have support for
Was there any attempt here to align the prettyprinter colors with our frontend tree color scheme? And if not, does it make sense to do so? (We could do it as a later PR — it's not particularly high priority.) |
Rebasing is a pain and tricky even for experienced developers, and probably not a great use of either your or @patrickaldis's time, so I think we can make an exception in this instance. |
One last thing — don't forget to update the first post to reflect what you want the merge commit to say, as that's what'll appear in the git logs. |
That was true with Bors, but not with GitHub's merge queues. See e.g. 5d2cd96. |
It's only Weeder failing now, so once the new tests I suggested (testing |
Actually, one final request: could we use different colours for global variables and constructors? It looks like |
13611e1
to
7598212
Compare
primer/test/Tests/Pretty.hs
Outdated
path = "test/outputs/Pretty/" ++ dname ++ "/" ++ hname | ||
bs = case d of | ||
DefPrim _ -> exitFailure | ||
DefAST e -> docToBS (fst h e) |
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.
Some minor style issues (the kind of thing HLint would pick up, if it were slightly cleverer) with this function:
- Any particular reason why it isn't written in curried form? i.e. Why isn't the type
String -> Def -> PrettyTestHandler -> TestTree
? - We bind
n
, then assign it todname
below. Why not justprettyTest (dname ...
?
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.
I think the n/dname issue was just because I was writing all the variables in the definition as single letters, and then later changed it when using it in the the where block. I'll change this
I thought in the type signature
(String, Def) -> PrettyTestHandler -> TestTree
The expression name and definition came as a pair, whereas the handler seemed separate. I can make this curried though if this is bad practice.
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.
The expression name and definition came as a pair, whereas the handler seemed separate.
Fair enough! Sometimes that distinction does make sense.
db0d123
to
28fe7fa
Compare
Need to add support for rendering types and test with primitives
This is a temporary state of affairs, in order to satisfy Fourmolu. Even though we have `GHC2022` enabled in our Cabal file, Fourmolu 0.6 doesn't search there for extensions. Note that we have updated to Fourmolu 0.7, which does, in db9d114, but this branch is currently behind `main`.
We ended up with an inconsistency in import styles due to an awkward Git history, and HLS and CLI versions of Fourmolu previously being out of sync.
28fe7fa
to
79fcea1
Compare
Rebased due to conflicts with #563. |
Need to: