Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Dec 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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