Skip to content

Commit

Permalink
Add extra space between prefix operator and string.
Browse files Browse the repository at this point in the history
Fixes #736
  • Loading branch information
nojaf committed Mar 28, 2020
1 parent 79c64f2 commit 410e2ba
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
9 changes: 9 additions & 0 deletions src/Fantomas.Tests/OperatorTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -341,4 +341,13 @@ let ``equal sign operator should not move to next line`` () =
|> should equal """
let result =
(typ.GetInterface(typeof<System.Collections.IEnumerable>.FullName) = null)
"""

[<Test>]
let ``operator before verbatim string add extra space, 736`` () =
formatSourceString false """Target M.Tools (fun _ -> !! @"Tools\Tools.sln" |> rebuild)
""" config
|> prepend newline
|> should equal """
Target M.Tools (fun _ -> !! @"Tools\Tools.sln" |> rebuild)
"""
8 changes: 7 additions & 1 deletion src/Fantomas/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -988,7 +988,13 @@ and genExpr astContext synExpr =
ifElse astContext.IsNakedRange expr (sepOpenS +> expr +> sepCloseS)
// Separate two prefix ops by spaces
| PrefixApp(s1, PrefixApp(s2, e)) -> !- (sprintf "%s %s" s1 s2) +> genExpr astContext e
| PrefixApp(s, e) -> !- s +> genExpr astContext e
| PrefixApp(s, e) ->
let extraSpaceBeforeString =
match e with
| String(_) -> sepSpace
| _ -> sepNone

!- s +> extraSpaceBeforeString +> genExpr astContext e
// Handle spaces of infix application based on which category it belongs to
| InfixApps(e, es) ->
let sepAfterExpr f =
Expand Down
7 changes: 6 additions & 1 deletion src/Fantomas/SourceParser.fs
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,14 @@ let rec (|Const|) c =
// Auto print may cut off the array
| SynConst.UInt16s us -> sprintf "%A" us

let (|String|_|) e =
match e with
| SynExpr.Const(SynConst.String(s,_),_) -> Some s
| _ -> None

let (|MultilineString|_|) e =
match e with
| SynExpr.Const(SynConst.String(s,_),_) when (String.isMultiline s) -> Some e
| String(s) when (String.isMultiline s) -> Some e
| _ -> None

let (|Unresolved|) (Const s as c, r) = (c, r, s)
Expand Down

0 comments on commit 410e2ba

Please sign in to comment.