Skip to content

Commit

Permalink
Attach trivia to node after when node before is on the previous line. (
Browse files Browse the repository at this point in the history
…#2662)

* Attach trivia to node after when node before is on the previous line.

* Remove unused case, swap order.
  • Loading branch information
nojaf authored Dec 26, 2022
1 parent 871e165 commit e9f1524
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
16 changes: 16 additions & 0 deletions src/Fantomas.Core.Tests/CommentTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2576,3 +2576,19 @@ type MyType2 =
=
inputA
"""

[<Test>]
let ``block comment before unit in binding, 2660`` () =
formatSourceString
false
"""
let run (log: ILogger) =
(* foo *) ()
"""
config
|> prepend newline
|> should
equal
"""
let run (log: ILogger) = (* foo *) ()
"""
17 changes: 11 additions & 6 deletions src/Fantomas.Core/Flowering.fs
Original file line number Diff line number Diff line change
Expand Up @@ -284,13 +284,18 @@ let blockCommentToTriviaInstruction (containerNode: Node) (trivia: TriviaNode) :

match nodeBefore, nodeAfter with
| Some nb, None when nb.Range.EndLine = trivia.Range.StartLine -> nb.AddAfter(triviaWith false false)
| Some nb, Some na when
(nb.Range.EndLine < trivia.Range.StartLine
&& na.Range.StartLine > trivia.Range.EndLine)
->
nb.AddBefore(triviaWith true true)
| Some nb, _ when nb.Range.EndLine = trivia.Range.StartLine -> nb.AddAfter(triviaWith false false)
| None, Some na -> na.AddBefore(triviaWith true false)
| Some nb, Some na ->
if nb.Range.EndLine = trivia.Range.StartLine then
// before (* comment *) after
nb.AddAfter(triviaWith false false)
elif
(nb.Range.EndLine < trivia.Range.StartLine
&& trivia.Range.EndLine = na.Range.StartLine)
then
// before
// (* comment *) after
na.AddBefore(triviaWith false false)
| _ -> ()

let addToTree (tree: Oak) (trivia: TriviaNode seq) =
Expand Down

0 comments on commit e9f1524

Please sign in to comment.