-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Allow indentation to work inside parens #10969
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
Actually indentation was always enabled inside parens, but the rule which indentation width to use was too simplistic and often required an extra line. This is now fixed, so both of these work: ```scala def test1 = g(1, x => val y = x * x y * y ) def test2 = g(1, x => val y = x * x y * y ) ```
This does not work currently because we find idioms like these f[[X, Y] =>
X
|
Y
] Since we are in an indentation region after I believe the best way out would be to go further, and also allow leading infix operators that appear on their own as only token on a line. We want that anyway since it seems a pity that condition1
|| condition2 should work but condition1
||
condition2 doesn't. Let's see how much breaks when we enable this. |
Summary so far:
|
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.
Otherwise LGTM, this matches what I had in mind!
@@ -345,14 +345,15 @@ object Scanners { | |||
allowLeadingInfixOperators | |||
&& ( token == BACKQUOTED_IDENT | |||
|| token == IDENTIFIER && isOperatorPart(name(name.length - 1))) | |||
&& ch == ' ' | |||
&& ch <= ' ' |
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.
If this is trying to match all whitespace characters, then it would be better to use an isSpace
method for clarity (we can reuse the existing https://github.com/lampepfl/dotty/blob/ea65338e06142f41f0e68b23250c8e22b0ba8837/compiler/src/dotty/tools/dotc/parsing/xml/Utility.scala#L113-L119), this would also avoid matching non-space characters that precede ' '
in ASCII like \b
.
The documentation of this method also needs to be updated: it currently states "it is followed on the same line by at least one ' ' and a token that can start an expression."
476a572
to
f767c00
Compare
Actually indentation was always enabled inside parens, but the rule which indentation
width to use was too simplistic and often required an extra line.
This is now fixed, so both of these work: