diff --git a/src/Fantomas.Tests/OperatorTests.fs b/src/Fantomas.Tests/OperatorTests.fs index a1c00dbee3..83f7d872cf 100644 --- a/src/Fantomas.Tests/OperatorTests.fs +++ b/src/Fantomas.Tests/OperatorTests.fs @@ -177,9 +177,18 @@ let ``should pipeline monadic bind``() = >>= strAddLong "A long argument that is ignored" "2" """ +[] +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 +""" + [] let ``should not add newline before = operator after |>``() = formatSourceString false """1 |> max 0 = 1""" config |> should equal """1 |> max 0 = 1 -""" \ No newline at end of file +""" diff --git a/src/Fantomas/TokenMatcher.fs b/src/Fantomas/TokenMatcher.fs index ca61f2516e..aea5e33335 100644 --- a/src/Fantomas/TokenMatcher.fs +++ b/src/Fantomas/TokenMatcher.fs @@ -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 @@ -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]) }