Skip to content

Conversation

kitbellew
Copy link
Collaborator

Also, abide by newlines.source for optional braces.

@kitbellew kitbellew requested a review from tgodzik April 11, 2021 04:50
@kitbellew kitbellew changed the title Router: handle then/else with optional braces Router: handle then/else/do/try/finally with optional braces Apr 11, 2021
Copy link
Contributor

@tgodzik tgodzik left a comment

Choose a reason for hiding this comment

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

Wow, this is getting more complex than I imagined. Great work! I left a couple of comments, but nothing blocking.

}
t.thenp match {
case x: Term.If => nestedIf(x)
case Term.Block(List(x: Term.If)) => nestedIf(x)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
case Term.Block(List(x: Term.If)) => nestedIf(x)
case Term.Block((x: Term.If) :: _) => nestedIf(x)

?

I don't think we can have an indented block with a single if currently. And would that not be covered by the next case?

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, what was the issue with nested ifs? It seems it should work normally 🤔

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this covers a block which contains only an if, not one which simply starts with an if.

if the block has multiple statements, a break is a must.

if the block only has an if, you must break, too, if it doesn't have an else but the outer one does:

if a then if b then c
else d

this else could belong to either of them since their indent is the same.

def unapply(
ftMeta: FormatToken.Meta
)(implicit style: ScalafmtConfig): Option[OptionalBraces] =
getMissingBrace(ftMeta).flatMap { nft =>
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems that we need to check getMissingBrace(ftMeta) on each of the new unapplies, which makes us do it over and over again. I wonder whether we should do it all in a single OptionalBraces object? Looks like we should be able to merge that. Or am I too worried about performance impact that does not exist there?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

good comment. i think it's time to go back to a single matcher. i will send an update in the morning.

bar
>>>
object a:
if (a) then foo
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we also test nested if (a)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

will do

Copy link
Collaborator Author

@kitbellew kitbellew left a comment

Choose a reason for hiding this comment

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

still more work to do

}
t.thenp match {
case x: Term.If => nestedIf(x)
case Term.Block(List(x: Term.If)) => nestedIf(x)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this covers a block which contains only an if, not one which simply starts with an if.

if the block has multiple statements, a break is a must.

if the block only has an if, you must break, too, if it doesn't have an else but the outer one does:

if a then if b then c
else d

this else could belong to either of them since their indent is the same.

def unapply(
ftMeta: FormatToken.Meta
)(implicit style: ScalafmtConfig): Option[OptionalBraces] =
getMissingBrace(ftMeta).flatMap { nft =>
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

good comment. i think it's time to go back to a single matcher. i will send an update in the morning.

bar
>>>
object a:
if (a) then foo
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

will do

@kitbellew kitbellew merged commit 6444990 into scalameta:master Apr 12, 2021
@kitbellew kitbellew deleted the 2415 branch April 12, 2021 21:47
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.

2 participants