Skip to content

Commit

Permalink
Don't add spaces for single op_Multiply operator name. (#2453)
Browse files Browse the repository at this point in the history
  • Loading branch information
nojaf authored Aug 29, 2022
1 parent 30f73bc commit bda3daa
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* Splitting list results in code that doesn't compile. [#2201](https://github.com/fsprojects/fantomas/issues/2201)
* Idempotency problem when using a list with interpolated strings. [#2242](https://github.com/fsprojects/fantomas/issues/2242)
* Idempotency problem when using set and spread syntax. [#2392](https://github.com/fsprojects/fantomas/issues/2392)
* Formatting (*) returns ( * ). [#2452](https://github.com/fsprojects/fantomas/issues/2452)

## [5.0.0-beta-007] - 2022-08-19

Expand Down
15 changes: 15 additions & 0 deletions src/Fantomas.Core.Tests/OperatorTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1415,3 +1415,18 @@ fun sum count -> sum / float count
"""
(fun sum count -> sum / float count) <*| sum xs <*| count
"""

[<Test>]
let ``single star operator, 2452`` () =
formatSourceString
false
"""
let (*) x y = x + y
"""
config
|> prepend newline
|> should
equal
"""
let (*) x y = x + y
"""
14 changes: 10 additions & 4 deletions src/Fantomas.Core/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4926,12 +4926,18 @@ and genSynBindingValue
// The idea is to solve this only where this can occur and not at the SynIdent level.
and genSynBindingFunctionName (functionName: SynLongIdent) =
match functionName with
| OperatorNameWithStar (text, synIdentRange, synLongIdentRange) ->
!- $"( {text} )"
| OperatorNameWithStar (lpr, text, rpr, synIdentRange, synLongIdentRange) ->
sepOpenTFor lpr +> sepSpace +> !-text +> sepSpace +> sepCloseTFor (Some rpr)
|> genTriviaFor SynIdent_ synIdentRange
|> genTriviaFor SynLongIdent_ synLongIdentRange
| PrefixedOperatorNameWithStar (prefix, text, synIdentRange, synLongIdentRange) ->
genSynIdent false prefix +> sepDot +> !- $"( {text} )"
| PrefixedOperatorNameWithStar (prefix, lpr, text, rpr, synIdentRange, synLongIdentRange) ->
genSynIdent false prefix
+> sepDot
+> sepOpenTFor lpr
+> sepSpace
+> !-text
+> sepSpace
+> sepCloseTFor (Some rpr)
|> genTriviaFor SynIdent_ synIdentRange
|> genTriviaFor SynLongIdent_ synLongIdentRange
| _ -> genSynLongIdent false functionName
Expand Down
10 changes: 4 additions & 6 deletions src/Fantomas.Core/SourceParser.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1202,12 +1202,10 @@ let (|PatLongIdent|_|) =

let (|OperatorNameWithStar|PrefixedOperatorNameWithStar|NotAnOperatorNameWithStar|) (synLongIdent: SynLongIdent) =
match synLongIdent.IdentsWithTrivia with
| [ SynIdent (_, Some (IdentTrivia.OriginalNotationWithParen (text = text))) as synIdent ] when text.StartsWith("*") ->
OperatorNameWithStar(text, synIdent.FullRange, synLongIdent.FullRange)
| [ prefix; SynIdent (_, Some (IdentTrivia.OriginalNotationWithParen (text = text))) as synIdent ] when
text.StartsWith("*")
->
PrefixedOperatorNameWithStar(prefix, text, synIdent.FullRange, synLongIdent.FullRange)
| [ SynIdent(trivia = Some (ParenStarSynIdent (lpr, originalNotation, rpr))) as synIdent ] ->
OperatorNameWithStar(lpr, originalNotation, rpr, synIdent.FullRange, synLongIdent.FullRange)
| [ prefix; SynIdent(trivia = Some (ParenStarSynIdent (lpr, originalNotation, rpr))) as synIdent ] ->
PrefixedOperatorNameWithStar(prefix, lpr, originalNotation, rpr, synIdent.FullRange, synLongIdent.FullRange)
| _ -> NotAnOperatorNameWithStar

let (|PatParen|_|) =
Expand Down

0 comments on commit bda3daa

Please sign in to comment.