Skip to content

Commit

Permalink
End String Content after String token. Fixes fsprojects#646
Browse files Browse the repository at this point in the history
  • Loading branch information
nojaf committed Apr 18, 2020
1 parent 83073f2 commit 9c4fe23
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
17 changes: 17 additions & 0 deletions src/Fantomas.Tests/SynConstTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,20 @@ module Runner =
class
end
"""

[<Test>]
let ``string content ends at string token, 646`` () =
formatSourceString false """"Yarn" ==> "Format"
"Yarn" ==> "CheckCodeFormat"
Target.runOrDefault "CheckCodeFormat"
""" config
|> prepend newline
|> should equal """
"Yarn" ==> "Format"
"Yarn" ==> "CheckCodeFormat"
Target.runOrDefault "CheckCodeFormat"
"""
7 changes: 5 additions & 2 deletions src/Fantomas/TokenParser.fs
Original file line number Diff line number Diff line change
Expand Up @@ -333,8 +333,11 @@ let rec private getTriviaFromTokensThemSelves (allTokens: Token list) (tokens: T
| head::rest when (head.TokenInfo.TokenName = "STRING_TEXT") ->
let stringTokens =
rest
|> List.takeWhile (fun ({TokenInfo = {TokenName = tn}}) -> tn = "STRING_TEXT" || tn = "STRING")
|> fun others -> List.prependItem others head
|> List.takeWhile (fun ({TokenInfo = {TokenName = tn}}) -> tn = "STRING_TEXT")
|> fun others ->
let length = List.length others
let closingQuote = rest.[length]
[ yield head; yield! others; yield closingQuote ]

let stringContent =
let builder = StringBuilder()
Expand Down

0 comments on commit 9c4fe23

Please sign in to comment.