Skip to content
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

cue/format/printer: fix indentation for clauses #1704

Closed
wants to merge 1 commit into from

Conversation

FogDong
Copy link

@FogDong FogDong commented May 6, 2022

Signed-off-by: Fog Dong [email protected]

This PR reset the allow for clauses at the position 0.

Fixes #1544

@FogDong FogDong requested a review from cueckoo as a code owner May 6, 2022 16:12
@FogDong
Copy link
Author

FogDong commented May 7, 2022

PTAL😀 /cc @myitcv

@myitcv myitcv requested a review from rogpeppe May 9, 2022 13:54
@myitcv
Copy link
Member

myitcv commented May 9, 2022

I'll defer to @rogpeppe here :)

Copy link
Member

@mvdan mvdan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about adding a check in writeWhitespace to never allow starting a file with a whitespace character? that seems to never make sense.

an alternative is why allowed begins with blank being set when printing the first token; it seems like we should start with just ignore, the zero value.

cue/format/testdata/indentation.input Outdated Show resolved Hide resolved
@FogDong
Copy link
Author

FogDong commented May 10, 2022

what about adding a check in writeWhitespace to never allow starting a file with a whitespace character? that seems to never make sense.

an alternative is why allowed begins with blank being set when printing the first token; it seems like we should start with just ignore, the zero value.

That makes more sense, thanks for the review, I'll fix it as suggested.

This PR reset the allow for blanks at the position 0.

Fixes cue-lang#1544

Signed-off-by: Fog Dong <[email protected]>
@FogDong
Copy link
Author

FogDong commented May 16, 2022

PTAL 😄 /cc @mvdan

@mpvl mpvl added the fmt Related to formatting functionality. label May 17, 2022
@mvdan
Copy link
Member

mvdan commented May 17, 2022

@Lyoness and myself are reviewing this together :) give us a couple of days if that's okay.

@mvdan mvdan self-assigned this May 17, 2022
@mvdan
Copy link
Member

mvdan commented May 24, 2022

I had a hunch that we could instead investigate why f.allowed had blank set when we were printing the first clause token. I debugged that a bit with @Lyoness and we ended up with a different fix, which you can find at https://review.gerrithub.io/c/cue-lang/cue/+/538624.

What do you think, @FogDong?

@FogDong
Copy link
Author

FogDong commented May 25, 2022

LGTM, you guys know cue better than me after all. @mvdan

Still, I think it's better for the community if we can have some more discussion before another PR. Although it took some time to investigate this issue and made my first PR, it's time to close it.

@FogDong FogDong closed this May 25, 2022
@mvdan
Copy link
Member

mvdan commented May 25, 2022

Certainly - and the last thing I want to do is to discourage further contributions :)

I did try to nudge the discussion in another direction in an earlier comment:

an alternative is why allowed begins with blank being set when printing the first token; it seems like we should start with just ignore, the zero value.

However, it was hard for me to say whether that idea would turn out to be a good fix without trying it. It's far from ideal if I ask you to implement a solution without me knowing ahead of time whether it will work or not - I'm new to the cue/format codebase as well.

So I thought it would be best to just try and see what happens. I'm still not sure whether Paul or Marcel will say that the second solution is better - if not, perhaps we'll come back here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fmt Related to formatting functionality.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

cue/format: let/comprehension incorrectly indented when first expression in file
4 participants