-
Notifications
You must be signed in to change notification settings - Fork 789
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
Parens: tweak sensitive indentation handling #16248
Parens: tweak sensitive indentation handling #16248
Conversation
* There are certain scenarios where we must consider both the context outside of a pair of parentheses as well as the inside in order to reintegrate the inner construct into the outer context after removing the parentheses.
…uter-sensitive-indentation
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.
Cool, thanks!
Hmm, I think I see one bug... Let me fix that. |
Tricky, tricky: fsharp/src/FSharp.Core/eventmodule.fs Lines 74 to 79 in 9a0b9bf
|
Expect some more PRs after this one, unfortunately—running fix-all on FSharp.Core is surfacing some other oddities I hadn't thought of, like the fact that parens aren't needed after type T (x, y) =
new (x) = T (x, 3) // Can remove parens: `new x = T (x, 3)`. or in this: type T (x, y) =
new (x, y, z) = T (x, y)
new (x) = T (x, 3) // Can remove parens: `new x = T (x, 3)`. but they are required if there's another constructor and it comes after: type T (x, y) =
new (x) = T (x, 3) // Cannot remove; removing the parens causes parse errors below.
new (x, y, _z) = T (x, y) Or the fact that this is fine: type C = abstract M : unit -> unit
let _ = { new C with override _.M () = () } // I.e., `override _.M (())` can be simplified to `override _.M ()` but this requires type C<'T> = abstract M : 'T -> unit
let _ = { new C<unit> with override _.M (()) = () } Real example: fsharp/src/FSharp.Core/printf.fs Lines 1074 to 1078 in 9a0b9bf
|
We are totally ready for the followups :) |
@brianrourkeboll this LGTM - is there anything else you plan to add here? |
@psfinaki Nope, this one should be all set. |
It seems this test case started to fail at some point: fsharp/vsintegration/tests/FSharp.Editor.Tests/CodeFixes/RemoveUnnecessaryParenthesesTests.fs Lines 784 to 790 in 9e357ca
Apparently because it's not being caught by the diagnostics. |
Another followup to #16079.
There are certain cases where we must consider both the context outside of a pair of parentheses as well as the inside in order to reintegrate the inner construct into the outer context after removing the parentheses. That is, sometimes we cannot simply remove the parentheses in place, but we must instead shift the entire parenthesized multiline expression left by one space.
For example:
must become
not
Or here's a real-world example from FSharp.Core:
fsharp/src/Compiler/Utilities/sformat.fs
Lines 891 to 901 in 9e7ec64