Skip to content
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

Add space before arrow when trivia before is present. #2889

Merged
merged 1 commit into from
Jun 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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