Skip to content

Commit f95faa9

Browse files
dawedawenojaf
andauthored
add a newline after the operator in SameInfix applications to let comment be printed (#2892)
* in the multilineExpr of SameInfix Apps, add a newline after the operator if there's ContentAfter * Slightly stricter check. * Add release notes. --------- Co-authored-by: Florian Verdonck <[email protected]>
1 parent 187cb01 commit f95faa9

File tree

3 files changed

+45
-2
lines changed

3 files changed

+45
-2
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
# Changelog
22

3-
## [Unreleased]
3+
## [6.0.4] - 2023-06-02
44

55
### Changed
66
* Update FCS to 'Prototype signature files for lex files', commit 5b74995780a0e9d24a5db025e68b31e6d910f71f
77

88
### Fixed
99
* Missing space before arrow. [#2888](https://github.com/fsprojects/fantomas/issues/2888)
1010
* Cons pattern in let bindings is converted to invalid code. [#1996](https://github.com/fsprojects/fantomas/issues/1996)
11+
* Trivia after infix operator is not restored correctly. [#2887](https://github.com/fsprojects/fantomas/issues/2887)
1112

1213
## [6.0.3] - 2023-05-14
1314

src/Fantomas.Core.Tests/CommentTests.fs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2612,3 +2612,45 @@ let (* this comment disappears after formatting *) a = []
26122612
"""
26132613
let (* this comment disappears after formatting *) a = []
26142614
"""
2615+
2616+
[<Test>]
2617+
let ``trivia after infix operator is not restored correctly, 2887`` () =
2618+
formatSourceString
2619+
false
2620+
"""
2621+
let EnableHeapTerminationOnCorruption() =
2622+
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && Environment.OSVersion.Version.Major >= 6 && // If OS is Vista or higher
2623+
Environment.Version.Major < 3) then // and CLR not 3.0 or higher
2624+
let HeapEnableTerminationOnCorruption = 1u : uint32
2625+
if not (HeapSetInformation(GetProcessHeap(), HeapEnableTerminationOnCorruption, UIntPtr.Zero, UIntPtr.Zero)) then
2626+
raise (System.Security.SecurityException(
2627+
"Unable to enable unmanaged process execution option TerminationOnCorruption. " +
2628+
"HeapSetInformation() returned FALSE; LastError = 0x" +
2629+
GetLastError().ToString("X").PadLeft(8, '0') + "."))
2630+
"""
2631+
config
2632+
|> prepend newline
2633+
|> should
2634+
equal
2635+
"""
2636+
let EnableHeapTerminationOnCorruption () =
2637+
if
2638+
(RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
2639+
&& Environment.OSVersion.Version.Major >= 6
2640+
&& // If OS is Vista or higher
2641+
Environment.Version.Major < 3)
2642+
then // and CLR not 3.0 or higher
2643+
let HeapEnableTerminationOnCorruption = 1u: uint32
2644+
2645+
if
2646+
not (HeapSetInformation(GetProcessHeap(), HeapEnableTerminationOnCorruption, UIntPtr.Zero, UIntPtr.Zero))
2647+
then
2648+
raise (
2649+
System.Security.SecurityException(
2650+
"Unable to enable unmanaged process execution option TerminationOnCorruption. "
2651+
+ "HeapSetInformation() returned FALSE; LastError = 0x"
2652+
+ GetLastError().ToString("X").PadLeft(8, '0')
2653+
+ "."
2654+
)
2655+
)
2656+
"""

src/Fantomas.Core/CodePrinter.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -772,7 +772,7 @@ let genExpr (e: Expr) =
772772
+> sepNln
773773
+> col sepNln es (fun (operator, e) ->
774774
genSingleTextNode operator
775-
+> sepSpace
775+
+> sepNlnWhenWriteBeforeNewlineNotEmptyOr sepSpace
776776
+> (fun ctx ->
777777
match e with
778778
| Expr.Lambda _ when

0 commit comments

Comments
 (0)