Skip to content

Commit

Permalink
Add space before arrow when trivia before is present. (#2889)
Browse files Browse the repository at this point in the history
  • Loading branch information
nojaf authored Jun 1, 2023
1 parent a6cf0bb commit e9653fd
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
### 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)

## [6.0.3] - 2023-05-14

### Fixed
Expand Down
23 changes: 23 additions & 0 deletions src/Fantomas.Core.Tests/PatternMatchingTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2321,3 +2321,26 @@ let f () =
tail -> 1
| _ -> None
"""

[<Test>]
let ``multiline trivia for arrow, 2888`` () =
formatSourceString
false
"""
match subcategory with
| BuildPhaseSubcategory.Internal
// Getting here means the compiler has ICE-d. Let's not pile on by showing the unknownSubcategory assert below.
// Just treat as an unknown-to-LanguageService error.
-> false
"""
config
|> prepend newline
|> should
equal
"""
match subcategory with
| BuildPhaseSubcategory.Internal
// Getting here means the compiler has ICE-d. Let's not pile on by showing the unknownSubcategory assert below.
// Just treat as an unknown-to-LanguageService error.
-> false
"""
11 changes: 10 additions & 1 deletion src/Fantomas.Core/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2013,7 +2013,16 @@ let genClause (isLastItem: bool) (node: MatchClauseNode) =

expressionFitsOnRestOfLine (sepSpace +> genExpr node.BodyExpr) long

(genSingleTextNodeWithSpaceSuffix sepSpace node.Arrow
let sepArrow =
if not node.Arrow.HasContentBefore then
genSingleTextNodeWithSpaceSuffix sepSpace node.Arrow
else
// In the weird case where the arrow has content before it and there is no multiline whenExpr,
// we need to ensure a space was written before the arrow to avoid offset errors.
// See https://github.com/fsprojects/fantomas/issues/2888
!- $" {node.Arrow.Text} " |> genNode node.Arrow

(sepArrow
+> ifElse
(ctx.Config.ExperimentalKeepIndentInBranch && isLastItem)
genKeepIndentInBranch
Expand Down

0 comments on commit e9653fd

Please sign in to comment.