Skip to content

Commit

Permalink
WIP preserve in keyword.
Browse files Browse the repository at this point in the history
  • Loading branch information
nojaf committed Sep 25, 2020
1 parent 038fde0 commit bd55433
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 1 deletion.
15 changes: 15 additions & 0 deletions src/Fantomas.Tests/LetBindingTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -967,3 +967,18 @@ let x =
()
"""

[<Test>]
let ``preserve in keyword via trivia, 340`` () =
formatSourceString false """
let x = List.singleton <|
let item = "text"
item
""" config
|> prepend newline
|> should equal """
let x =
List.singleton
<| let item = "text" in
item
"""
1 change: 1 addition & 0 deletions src/Fantomas/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,7 @@ and genLetBinding astContext pref b =
+> leadingExpressionIsMultiline
(afterLetKeyword
+> genPat
+> dumpAndContinue
+> enterNodeTokenByName rangeBetweenBindingPatternAndExpression EQUALS)
(genExprSepEqPrependType astContext p e (Some(valInfo)))

Expand Down
3 changes: 2 additions & 1 deletion src/Fantomas/TokenParser.fs
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,8 @@ let private keywordTrivia =
"DEFAULT"
"ABSTRACT"
"KEYWORD_STRING"
"QMARK" ]
"QMARK"
"IN" ]

let private numberTrivia =
[ "UINT8"
Expand Down
5 changes: 5 additions & 0 deletions src/Fantomas/Trivia.fs
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,11 @@ let private addTriviaToTriviaNode triviaBetweenAttributeAndParentBinding
findConstNodeAfter triviaNodes range
|> updateTriviaNode (fun tn -> tn.ContentBefore.Add(Keyword(kw))) triviaNodes

| { Item = Keyword ({ Content = keyword }); Range = range } when (keyword = "in") ->
// find largest SynExpr right before in range
findNodeBeforeLineAndColumn triviaNodes range.StartLine range.StartColumn
|> updateTriviaNode (fun tn -> tn.ContentAfter.Add trivia.Item) triviaNodes

| { Item = Keyword ({ Content = keyword }); Range = range } when (keyword = "if"
|| keyword = "then"
|| keyword = "else"
Expand Down

0 comments on commit bd55433

Please sign in to comment.