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

Fixes Formatting Bug #4052

Merged
merged 1 commit into from
Dec 7, 2017
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
10 changes: 10 additions & 0 deletions src/fsharp/vs/ServiceFormatting/TokenMatcher.fs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ let (|RawDelimiter|_|) = function
Some origTokText
| _ -> None

let (|RawComment|_|) = function
| (Token origTok, origTokText) when origTok.CharClass = FSharpTokenCharKind.Comment ->
Some origTokText
| _ -> None

let (|RawAttribute|_|) = function
| RawDelimiter "[<" :: moreOrigTokens ->
let rec loop ts acc =
Expand Down Expand Up @@ -572,6 +577,11 @@ let integrateComments (originalText : string) (newText : string) =
maintainIndent (fun () ->
for x in commentTokensText do addText x)
loop moreOrigTokens moreNewTokens

| (_ :: moreOrigTokens), (RawComment newTokText :: moreNewTokens) ->
addText newTokText
loop moreOrigTokens moreNewTokens


// Emit end-of-line from new tokens
| _, (NewLine newTokText :: moreNewTokens) ->
Expand Down
22 changes: 22 additions & 0 deletions vsintegration/tests/unittests/ServiceFormatting/CommentTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -363,3 +363,25 @@ let hello() = "hello world"
let hello() = "hello world"
(* This is a comment. *)
"""

[<Test>]
let ``should keep comments inside unit``() =
formatSourceString false """
let x =
((*comment*))
printf "a"
// another comment 1
printf "b"
// another comment 2
printf "c"
""" config
|> prepend newline
|> should equal """
let x =
((*comment*))
printf "a"
// another comment 1
printf "b"
// another comment 2
printf "c"
"""