Repository navigation
Conversation
- Share the layout across function calls and type annotations, including multiple, mixed, and nested type arguments. - Preserve comments, directives, required spaces, and cursor positions. How the fix works: - Measure argument openings instead of requiring the whole argument to fit on one line. Choose line breaks at each argument boundary. - Keep the closing angle attached when possible. Apply indentation only when it needs its own line, after printing leading comments and before recording its cursor position. - If an unsupported type needs multiple lines, discard the attempted layout and use the existing generic layout. Add regression tests for signatures, wrapped records, width limits, comments, directives, cursor positions, and fallback layouts. Fixes fsprojects#2860 Fixes fsprojects#3069
|
Thanks for digging into this, but I'm closing this PR: the scope is far too large for me to review. #3069 reports one thing: with Stroustrup, a single anonymous record as the only type argument should keep Some of it changes output no issue asks for. For example, the #2706 goldens with two records. How several anonymous records lay out under Stroustrup has never been discussed or decided. If you think that should change, open an issue for it. A fix PR is not the place to decide it. If you want to try again, please open a new PR with the smallest change that fixes #3069:
An occasional small PR that touches as little as possible is very welcome and easy for me to review. A large one isn't, however well it's tested. When in doubt, open a draft early and ask first, as Pull request ground rules asks. |
|
That's totally fair. I'll open a new PR with the minimal fix you described. Separately, I think these may be worth discussing:
I checked the open issues and didn't find exact duplicates. Any new issues would reference the related reports and distinguish themselves from the singleton fix in #3069 and #2860. These would stay out of the replacement PR. If you think any are worth discussing, let me know and I'll open issues for them. For the Stroustrup layout questions, would you prefer one umbrella issue or separate focused issues for each behaviour? I'd keep the cursor problem separate. |
|
Thanks for understanding and making a smaller PR for this 🚀 The four layout questions are style questions, and I have very little appetite for deciding style in this repository. As the [Style guide](https://fsprojects.github.io/fantomas/docs/end-users/StyleGuide.html) page explains, those conversations belong at [fsharp/fslang-design](https://github.com/fsharp/fslang-design#style-guide). If one of them gets settled there and lands in the style guide, Fantomas can follow it. Please don't open issues for them here. The cursor position is a real bug, I agree. But I haven't seen anyone run into it, and the worst it does is put the cursor a line or so from where it should be. You're free to open an issue for it, but I won't prioritize if there is no real user impact attached to it. |
Fixes #2860
Fixes #3069
Summary
>reported in Space inserted before final > in type parameter #2860 and the regression reported in Regression: Stroustrup bracket style in anonymous record type parameter is not respected #3069, where the record fell back to the aligned layout for a multiline anonymous record even though Stroustrup was configured (a regression from Fantomas 6.3.0).Before and after
With
fsharp_multiline_bracket_style = stroustrup, the example from #3069 currently becomes:This PR gives the requested layout:
<{|, and the closing stays together as|}>.|} >ending. On the current base, that example instead has a detached>; the fix restores the full requested layout, rather than only removing a space.Why this happened
<.<and put>on another line, without a Stroustrup-aware choice at each argument boundary.>valid F#.How the fix works
Expr.TypeAppandType.AppPrefixusegenGenericApplication, so expression and type positions follow the same rules.genTypeprinter. Record fields still follow the existing width and record-size settings.SpaceAfterComma.>from the actual output position. Keep it attached when possible, and reserve room for it when measuring a final ordinary type argument. If width or comments require a separate line, retain the indentation needed by F#'s offside rule.Scope and compatibility
v9.0because this changes Stroustrup output. Aligned and Cramped keep the existing generic-list layout; no new setting or public API change.FSharp.Collections.Immutable,FsToolkit.ErrorHandling,Lanayx/Oxpecker) found no unexpected changes: zero output differences in the first two, and in Oxpecker — which uses anonymous-record type arguments in real code (serializer.Deserialize<{| ... |}>(...)intests/Oxpecker.Tests/Json.Tests.fs) — exactly one hunk, converting the broken layout to the attached one. The fix output was idempotent anddotnet build Oxpecker.slnxpassed from the formatted tree.Fantomas.Core.Tests,Fantomas.Core.SnapshotTests,Fantomas.Tests,Fantomas.Client.TestsandFantomas.Analyzers.Tests.