From a80f888cbb71e8d0bd65d05c6ceccf9502d30f69 Mon Sep 17 00:00:00 2001 From: Kent Boogaart Date: Fri, 20 Aug 2021 02:27:53 +1000 Subject: [PATCH] Retain significant whitespace in nested, indented #if directives (#1867) --- src/Fantomas.Tests/CompilerDirectivesTests.fs | 21 +++++++++++++++++++ src/Fantomas/TokenParser.fs | 10 +++++++-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/Fantomas.Tests/CompilerDirectivesTests.fs b/src/Fantomas.Tests/CompilerDirectivesTests.fs index 541c968b3c..634038c766 100644 --- a/src/Fantomas.Tests/CompilerDirectivesTests.fs +++ b/src/Fantomas.Tests/CompilerDirectivesTests.fs @@ -2639,3 +2639,24 @@ let isUnix = |> fun p -> (p = 4) || (p = 6) || (p = 128) #endif """ + +[] +let ``indented #if directive inside another non-indented #if directive should format correctly, 1866`` () = + formatSourceString + false + """ +#if FOO + #if BAR + #endif +#endif +""" + config + |> prepend newline + |> should + equal + """ +#if FOO +#if BAR +#endif +#endif +""" diff --git a/src/Fantomas/TokenParser.fs b/src/Fantomas/TokenParser.fs index 36cd77beac..660c42688e 100644 --- a/src/Fantomas/TokenParser.fs +++ b/src/Fantomas/TokenParser.fs @@ -157,8 +157,14 @@ let rec private getTokenizedHashes (sourceCode: string) : Token list = (fun t -> let info = { t.TokenInfo with - LeftColumn = t.TokenInfo.LeftColumn + hashContentLength - RightColumn = t.TokenInfo.RightColumn + hashContentLength } + LeftColumn = + t.TokenInfo.LeftColumn + + hashContentLength + + offset + RightColumn = + t.TokenInfo.RightColumn + + hashContentLength + + offset } { t with LineNumber = lineNumber