Skip to content

Commit

Permalink
print Trivia before entire LetBang expression (#880)
Browse files Browse the repository at this point in the history
* print Trivia before entire LetBang expression. Fixes #879

* Bump to alpha 008
  • Loading branch information
nojaf committed Jun 2, 2020
1 parent 8824f4a commit eee0f32
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 7 deletions.
2 changes: 1 addition & 1 deletion RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
### 4.0.0-alpha-007 - 06/2020
### 4.0.0-alpha-008 - 06/2020
* WIP for [#705](https://github.com/fsprojects/fantomas/issues/705)

### 3.3.0 - 02/2020
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>netcoreapp3.1</TargetFramework>
<IsPackable>false</IsPackable>
<GenerateProgramFile>false</GenerateProgramFile>
<Version>4.0.0-alpha-007</Version>
<Version>4.0.0-alpha-008</Version>
<NoWarn>FS0988</NoWarn>
</PropertyGroup>
<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/Fantomas.CoreGlobalTool/Fantomas.CoreGlobalTool.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>netcoreapp3.1</TargetFramework>
<ToolCommandName>fantomas</ToolCommandName>
<PackAsTool>True</PackAsTool>
<Version>4.0.0-alpha-007</Version>
<Version>4.0.0-alpha-008</Version>
<AssemblyName>fantomas-tool</AssemblyName>
</PropertyGroup>
<ItemGroup>
Expand Down
57 changes: 57 additions & 0 deletions src/Fantomas.Tests/ComputationExpressionTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1315,4 +1315,61 @@ let a =
let! bar = async { return foo a }
return bar
}
"""

[<Test>]
let ``new line between let and let bang, 879`` () =
formatSourceString false """let rec loop () =
async {
let! msg = inbox.Receive()
match msg with
| Handle (eventSource,command,reply) ->
let! stream = eventSource |> eventStore.GetStream
let newEvents =
stream |> Result.map (asEvents >> behaviour command >> enveloped eventSource)
let! result =
newEvents
|> function
| Ok events -> eventStore.Append events
| Error err -> async { return Error err }
do reply.Reply result
return! loop ()
}
""" ({ config with
SpaceBeforeUppercaseInvocation = true
IndentSpaceNum = 2
SpaceAroundDelimiter = false
MultilineBlockBracketsOnSameColumn = true })
|> prepend newline
|> should equal """
let rec loop () =
async {
let! msg = inbox.Receive ()
match msg with
| Handle (eventSource, command, reply) ->
let! stream = eventSource |> eventStore.GetStream
let newEvents =
stream
|> Result.map
(asEvents
>> behaviour command
>> enveloped eventSource)
let! result =
newEvents
|> function
| Ok events -> eventStore.Append events
| Error err -> async { return Error err}
do reply.Reply result
return! loop ()
}
"""
2 changes: 1 addition & 1 deletion src/Fantomas.Tests/Fantomas.Tests.fsproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\netfx.props" />
<PropertyGroup>
<Version>4.0.0-alpha-007</Version>
<Version>4.0.0-alpha-008</Version>
<NoWarn>FS0988</NoWarn>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
Expand Down
5 changes: 3 additions & 2 deletions src/Fantomas/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -968,8 +968,9 @@ and genExpr astContext synExpr =
sprintf "%s%s" (if isUse then "use " else "let ") (if isRecursive then "rec " else "")

genLetBinding astContext prefix binding
| LetOrUseBangStatement(isUse, pat, expr, _) ->
ifElse isUse (!- "use! ") (!- "let! ")
| LetOrUseBangStatement(isUse, pat, expr, r) ->
enterNode r // print Trivia before entire LetBang expression
+> ifElse isUse (!- "use! ") (!- "let! ")
+> genPat astContext pat -- " = "
+> autoIndentAndNlnIfExpressionExceedsPageWidth (genExpr astContext expr)
| AndBangStatement(pat, expr) ->
Expand Down
2 changes: 1 addition & 1 deletion src/Fantomas/Fantomas.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<Import Project="..\netfx.props" />
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<Version>4.0.0-alpha-007</Version>
<Version>4.0.0-alpha-008</Version>
<Description>Source code formatter for F#</Description>
</PropertyGroup>
<ItemGroup>
Expand Down

0 comments on commit eee0f32

Please sign in to comment.