Skip to content

Commit

Permalink
Merge pull request #293 from jindraivanek/fix-291
Browse files Browse the repository at this point in the history
Fix 291
  • Loading branch information
nojaf authored Sep 10, 2018
2 parents 5719708 + 9edfec4 commit b5b7801
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/Fantomas.Tests/OperatorTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,18 @@ let ``should pipeline monadic bind``() =
>>= strAddLong "A long argument that is ignored" "2"
"""

[<Test>]
let ``should keep >>.~ operator``() =
formatSourceString false """let (>>.~) (g : int) (h : int) : int = g + h
let output = 2 >>.~ 3
""" config
|> should equal """let (>>.~) (g : int) (h : int) : int = g + h
let output = 2 >>.~ 3
"""

[<Test>]
let ``should not add newline before = operator after |>``() =
formatSourceString false """1 |> max 0 = 1""" config
|> should equal """1
|> max 0 = 1
"""
"""
6 changes: 6 additions & 0 deletions src/Fantomas/TokenMatcher.fs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ let tokenize defines (content : string) =
for (i, line) in lines |> Seq.zip [1..lines.Length] do
let lineTokenizer = sourceTokenizer.CreateLineTokenizer line
let finLine = ref false
let mutable lastColumn = 0
while not !finLine do
let tok, newLexState = lineTokenizer.ScanToken(!lexState)
lexState := newLexState
Expand All @@ -40,6 +41,11 @@ let tokenize defines (content : string) =
yield (EOL, Environment.NewLine)
finLine := true
| Some t ->
if lastColumn + 1 < t.LeftColumn then
// workaround for cases where tokenizer dont output "delayed" part of operator after ">."
// See https://github.com/fsharp/FSharp.Compiler.Service/issues/874
yield (Tok({ t with TokenName="DELAYED" }, i), line.[lastColumn+1..t.LeftColumn-1])
lastColumn <- t.RightColumn
yield (Tok(t, i), line.[t.LeftColumn..t.RightColumn])
}

Expand Down

0 comments on commit b5b7801

Please sign in to comment.