Skip to content

Commit

Permalink
Fixes 1951 - Single block comment in namespace is disappearing (fspro…
Browse files Browse the repository at this point in the history
…jects#2089)

* Fixes 1951 (block comment in namespace) by lowering requirements for the node in findNodeBeforeLineAndColumn()

* Explain what's needed to close issues, that aren't reproducable anymore.

* Fixes 1951 (block comment in namespace) by lowering requirements for the node in findNodeBeforeLineAndColumn()

* - Switch fix to use findNodeBeforeLineFromStart() as a fallback if findNodeBeforeLineAndColumn() comes up with None
- Leave findNodeBeforeLineAndColumn() unchanged

* - call findNodeBeforeLineFromStart() only if findNodeAfterLineAndColumn() and findNodeBeforeLineAndColumn() returned None
- fix case of test
  • Loading branch information
dawedawe authored and jindraivanek committed Mar 30, 2022
1 parent 84a0202 commit 3fc86f0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
21 changes: 21 additions & 0 deletions src/Fantomas.Tests/CommentTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -936,6 +936,27 @@ type substring =
#endif
"""

[<Test>]
let ``single block comment in namespace, 1951`` () =
formatSourceString
false
"""
namespace ASTViewer.Server
(* open Microsoft.Azure.Functions.Worker.Http
open Microsoft.Azure.Functions.Worker
open Microsoft.Extensions.Logging *)
"""
config
|> prepend newline
|> should
equal
"""
namespace ASTViewer.Server
(* open Microsoft.Azure.Functions.Worker.Http
open Microsoft.Azure.Functions.Worker
open Microsoft.Extensions.Logging *)
"""

[<Test>]
let ``line comment after "then"`` () =
formatSourceString
Expand Down
4 changes: 3 additions & 1 deletion src/Fantomas/Trivia.fs
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,9 @@ let private addTriviaToTriviaNode (startOfSourceCode: int) (triviaNodes: TriviaN
| Some n, _ ->
Some n
|> updateTriviaNode (fun tn -> tn.ContentAfter.Add(Comment(BlockComment(comment, true, false)))) triviaNodes
| None, None -> triviaNodes
| None, None ->
findNodeBeforeLineFromStart triviaNodes range.StartLine
|> updateTriviaNode (fun tn -> tn.ContentAfter.Add(Comment(BlockComment(comment, true, true)))) triviaNodes

| { Item = Comment (LineCommentAfterSourceCode _ as comment)
Range = range } ->
Expand Down

0 comments on commit 3fc86f0

Please sign in to comment.