Skip to content

Commit

Permalink
add a newline after the operator in SameInfix applications to let com…
Browse files Browse the repository at this point in the history
…ment 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 <florian.verdonck@outlook.com>
  • Loading branch information
dawedawe and nojaf authored Jun 2, 2023
1 parent 187cb01 commit f95faa9
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
# Changelog

## [Unreleased]
## [6.0.4] - 2023-06-02

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

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

## [6.0.3] - 2023-05-14

Expand Down
42 changes: 42 additions & 0 deletions src/Fantomas.Core.Tests/CommentTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2612,3 +2612,45 @@ let (* this comment disappears after formatting *) a = []
"""
let (* this comment disappears after formatting *) a = []
"""

[<Test>]
let ``trivia after infix operator is not restored correctly, 2887`` () =
formatSourceString
false
"""
let EnableHeapTerminationOnCorruption() =
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && Environment.OSVersion.Version.Major >= 6 && // If OS is Vista or higher
Environment.Version.Major < 3) then // and CLR not 3.0 or higher
let HeapEnableTerminationOnCorruption = 1u : uint32
if not (HeapSetInformation(GetProcessHeap(), HeapEnableTerminationOnCorruption, UIntPtr.Zero, UIntPtr.Zero)) then
raise (System.Security.SecurityException(
"Unable to enable unmanaged process execution option TerminationOnCorruption. " +
"HeapSetInformation() returned FALSE; LastError = 0x" +
GetLastError().ToString("X").PadLeft(8, '0') + "."))
"""
config
|> prepend newline
|> should
equal
"""
let EnableHeapTerminationOnCorruption () =
if
(RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
&& Environment.OSVersion.Version.Major >= 6
&& // If OS is Vista or higher
Environment.Version.Major < 3)
then // and CLR not 3.0 or higher
let HeapEnableTerminationOnCorruption = 1u: uint32

if
not (HeapSetInformation(GetProcessHeap(), HeapEnableTerminationOnCorruption, UIntPtr.Zero, UIntPtr.Zero))
then
raise (
System.Security.SecurityException(
"Unable to enable unmanaged process execution option TerminationOnCorruption. "
+ "HeapSetInformation() returned FALSE; LastError = 0x"
+ GetLastError().ToString("X").PadLeft(8, '0')
+ "."
)
)
"""
2 changes: 1 addition & 1 deletion src/Fantomas.Core/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -772,7 +772,7 @@ let genExpr (e: Expr) =
+> sepNln
+> col sepNln es (fun (operator, e) ->
genSingleTextNode operator
+> sepSpace
+> sepNlnWhenWriteBeforeNewlineNotEmptyOr sepSpace
+> (fun ctx ->
match e with
| Expr.Lambda _ when
Expand Down

0 comments on commit f95faa9

Please sign in to comment.