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

Keep tuple trivia while formatting #1365

Merged
merged 8 commits into from
Jan 15, 2021
Merged

Conversation

Evangelink
Copy link
Contributor

Fix #1350

Copy link
Contributor

@nojaf nojaf left a comment

Choose a reason for hiding this comment

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

Hey @Evangelink, great start to this PR.

src/Fantomas/CodePrinter.fs Outdated Show resolved Hide resolved
src/Fantomas/SourceParser.fs Outdated Show resolved Hide resolved
src/Fantomas.Tests/TupleTests.fs Show resolved Hide resolved
@Evangelink Evangelink changed the title [WIP] Keep tuple trivia while formatting Keep tuple trivia while formatting Jan 15, 2021
@Evangelink Evangelink marked this pull request as ready for review January 15, 2021 08:57
Copy link
Contributor Author

@Evangelink Evangelink left a comment

Choose a reason for hiding this comment

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

I have left 2 open questions with potential bugs, if you confirm they are bugs let me know if you want them fix part of this PR or through another one.

Also I wanted to say a big thank you, that was a really good experience working on this project. Guidelines are clear, you have provided most of the info so that even a beginner can feel confident to jump-in. That's really appreciated and a sign of a really good "management". Keep-up this awesome spirit.

src/Fantomas.Tests/TupleTests.fs Show resolved Hide resolved

func (
// abc
0, // def
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This looks like a bug, I would have expected to have either only one space or to have also two spaces for // jkl below.

Copy link
Contributor

Choose a reason for hiding this comment

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

Good spot, this can be solved by changing long to

            let long =
                genExpr astContext e
                +> sepSpace
                +> sepOpenTFor lpr
                +> indent
                +> sepNln
                +> (col (sepCommaFixed +> sepNln) args (genExprLong astContext)
                    |> genTupleTrivia)
                +> unindent
                +> sepNln
                +> sepCloseTFor rpr

Notice that sepCommaFixed does not exist yet.
You can add it in Context (right under sepComma):

let internal sepCommaFixed = str ","

The Fixed convention means, give me the value without checking the configuration if there should be a space.

0, // def
// ghi
1 // jkl
// mno
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let me know if this isn't the expected location for this comment trivia.

Copy link
Contributor

Choose a reason for hiding this comment

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

Well, this is another bug related to the assignment of trivia to a trivia node.
In short, Fantomas detected the comment // mno and has to find an anchor to attach it.
It chose to add it before the closing parenthesis ) instead of after the SynExpr.Tuple.
I'm aware of these situations, but it is quite complex to solve to be fair.
For this PR you can leave it like that.

@@ -1899,7 +1899,7 @@ and genExpr astContext synExpr ctx =

isShortExpression ctx.Config.MaxDotGetExpressionWidth (genExpr sepNone) (genExpr sepNln) ctx

| AppTuple (e, lpr, args, rpr) when (not astContext.IsInsideDotGet) ->
| AppTuple (e, lpr, args, rangeOfTuple, rpr) when (not astContext.IsInsideDotGet) ->
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have used rangeOfTuple as suggested but I have seen you are using both rangeOfXXX and XXXRange notation in the code so let me know if you prefer the other.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, good remark. Perhaps go for tupleRange instead.
Both do appear in the code base indeed, this hasn't really been a conscious decision I think.

@Evangelink Evangelink requested a review from nojaf January 15, 2021 14:05
@nojaf nojaf merged commit 0df01f3 into fsprojects:master Jan 15, 2021
@nojaf
Copy link
Contributor

nojaf commented Jan 15, 2021

Hey @Evangelink, this looks good!
Thank you for this first contribution.
It was a pleasure working with you.

@Evangelink Evangelink deleted the comment-tuple branch January 15, 2021 14:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Comment on first constructor argument gets removed
2 participants