-
Notifications
You must be signed in to change notification settings - Fork 218
feat(comments): support prefix comments on Record's key-value pairs. #1908
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
Conversation
|
I'm happy to see that you've started working on this! :)
Have you considered including the whitespace between the label and the value, e.g.
I haven't checked, but I think we should be able to preserve the comments here. We have a similar case with the If you need more help, please shout! :) |
I didn't consider them because as you say is an awkward place to write documentation. But I can add it with no problem :)
I haven't check out I'll read
Cool! What do you think might suffix for tests to this? A format test? I think that to make this PR not too big I'll add the record field support for |
Oh, right! I forgot why
Take a look at the tests added in #1273. Formatting idempotence is a bit tricky to get right, but we can fix it later if necessary. We can extend some property tests to help with that: #1465. |
|
BTW, you could try making the same changes for Documentation comments on record literals could also prove valuable, for example in |
You're right! After getting record types right I'll do it. Looks like I have a lot of work to do ;) Thanks for your guidance @sjakobi |
7ac2e63 to
1aee694
Compare
|
I successfully captured the prefix whitespace of a key-value pair, but the suffix is consumed by the annotation expression. Any idea about how to solve this? For example, { -- foo
a : Text
-- baz
}results in (approximate) I believe that almost all expressions consume the suffix whitespace around it Any ideas? cc: @Gabriel439 @sjakobi |
Oh yes. I forgot that this is a constraint that we also encountered with I guess we could try fiddling with the I hope @Gabriel439 has a better idea – he definitely knows more about parsing! |
|
@german1608: There isn't a good solution to this and the |
36e20f1 to
ad079d4
Compare
|
I'll post an update. I dropped I started the pretty printing of those comments, this is what I have at this moment: With this file: { -- hi there
-- testing around
a: Text,
{- foo
-}
b: Bool
}
{ -- hi there
-- testing around
a :
Text
,
{- foo
-}
b :
Bool
}for me, it's awkward that the type follows in a newline. Do you know the reason? I'm not too fluent on Also, what other test cases you think will be helpful for this? something similar to let-bindings as we had on #1273? I'll keep these answer open and debug further tomorrow. |
|
These line is what causes the line break there: dhall-haskell/dhall/src/Dhall/Pretty/Internal.hs Lines 1317 to 1319 in 71e485b
Changing these lines to: space <> prettyValue valand supplying a file like this: { -- hi there
-- testing around
a: Text,
{- foo
-}
b: Bool
}outputs a file like this: { -- hi there
-- testing around
a : Text
,
{- foo
-}
b : Bool
}What do you think of this formatting? |
|
I believe that this is ready for review. You can check out the test-cases I added. What I haven't done yet is:
I improved the formatting of key-value pairs to avoid the newline after the dhall-haskell/dhall/src/Dhall/Pretty/Internal.hs Lines 1333 to 1374 in 79c00ae
I'll work to improve the idempotent tests before marking this PR as ready for review, but you can take a look if you want to EDIT: forgot to mention that an existing test-case was amended due to new formatting. |
79c00ae to
b302f04
Compare
|
Apologies for the delay @german1608! I've started reviewing this now. Unfortunately the mass of style changes make the review much harder. I wish I had remembered to suggest that you do a complete Could you possibly still do that and then rebase this PR? |
sjakobi
left a comment
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.
Oh boy, this task looks like quite the struggle! I don't blame you, @german1608 – I wish I had anticipated these issues a bit better.
I'm wondering whether we could still split this work into more manageable chunks – for you, and for us reviewers.
In particular, I think we could do the pretty-printer update in a separate PR. It's tricky stuff, and frankly I would probably struggle with it too. We can still see who ends up doing this work.
My suggestion is:
- Backup this work on a different branch.
- Remove the work on the pretty-printing logic from this PR, as if the
recordFieldSrcdidn't exist. - I will give the remaining code a speedy review.
- Once it's merged you can focus on dhall-docs again, and for example work on using the record field comments in
dhall-docs.
Regarding my suggestion to do a complete stylish-haskell sweep over the codebase to simplify the review. I think that's still a good idea. If it causes you trouble, we can maybe do it later though.
Does this sound like a reasonable plan?
No worries!
Sure thing! Give me 30minutes do the change.
Yeah, let's do it. I'll ping you when I'm done @sjakobi |
|
@sjakobi the stylish-haskell changes you say are only on imports formatting, right? Aside that, I manually changed in some places: do eto ewhen it's valid to do so. Should I do these changes on another PR as well? |
I don't feel very strongly about Maybe just do what seems "economical" for your time and the reviewers' time. |
|
Ok, I'll revert those changes too |
|
additions/deletions before stylish-haskell changes: +1,399 −758 additions/deletion after reverting them: +460 −270 I believe that you can review now, @sjakobi |
This reverts commit efb4cfd.
ece1d10 to
cf588a0
Compare
|
@sjakobi I used Running on Running on this PR without the "left-refactoring" improvement: These are the bench results with the "left-refactoring" technique: the latest results are better! Thanks for that suggestion @sjakobi @Gabriel439 If you want to take a look at |
sjakobi
left a comment
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 it would be good if @Gabriel439 would take another look at the parser changes.
I wouldn't mind if that happens after the merge though.
Great job, @german1608! 🥇
|
Thanks @sjakobi and @Gabriel439 for your help and patience! |
This PR tries to add support to record field comments both on formatting and dhall-docs documentation extension. Specifically the following ones:
{ -- before each record field a : Text -- after each record field , ... }I updated the
Record'sExprconstructor from:to
where
RecordFieldstores the last of the expression on the right side of the:and the prefix and suffix comments. Although the prefix comment is annotating the label field, the best place to save that comment is there.However, I'm having a problem with
unsafeSubExpressions, because it can't traverse theMaybe sI put onRecordField. A quick solution for that is to change thoseRecordField'sMaybe s' toNothing, although that means we loose that information when traversing.I'll keep this PR as a draft to get your opinion in that matter.