Skip to content

Commit

Permalink
Print in keyword after correct SynBinding. Fixes fsprojects#1143. (fs…
Browse files Browse the repository at this point in the history
  • Loading branch information
nojaf committed Oct 2, 2020
1 parent b0dedcd commit a241023
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
15 changes: 15 additions & 0 deletions src/Fantomas.Tests/LetBindingTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1061,3 +1061,18 @@ let internal sepSpace =
else
(!- " ") ctx
"""

[<Test>]
let ``in keyword in LetOrUse with and keyword, 1176`` () =
formatSourceString false """
do
let rec f = ()
and g = () in
()
""" config
|> prepend newline
|> should equal """
do let rec f = ()
and g = () in
()
"""
2 changes: 1 addition & 1 deletion src/Fantomas/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2000,7 +2000,7 @@ and genExpr astContext synExpr =
mkRange "IN" binding.RangeOfBindingAndRhs.End e.Range.Start

Map.tryFindOrEmptyList IN ctx.TriviaTokenNodes
|> TriviaHelpers.``keyword token inside range`` inRange
|> TriviaHelpers.``keyword token after start column and on same line`` inRange
|> List.tryHead

let isInSameLine ctx =
Expand Down
8 changes: 8 additions & 0 deletions src/Fantomas/TriviaHelpers.fs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ module internal TriviaHelpers =
| TriviaNodeType.Token (_, tok) when (RangeHelpers.``range contains`` range t.Range) -> Some(tok, t)
| _ -> None)

let ``keyword token after start column and on same line`` (range: range) (trivia: TriviaNode list) =
trivia
|> List.choose (fun t ->
match t.Type with
| TriviaNodeType.Token (_, tok) when (range.StartLine = t.Range.StartLine
&& range.StartColumn < t.Range.StartColumn) -> Some(tok, t)
| _ -> None)

let ``has line comment after`` triviaNode =
triviaNode.ContentAfter
|> List.filter (fun tn ->
Expand Down

0 comments on commit a241023

Please sign in to comment.