Skip to content

Commit a80f888

Browse files
authored
Retain significant whitespace in nested, indented #if directives (#1867)
1 parent 383b729 commit a80f888

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

src/Fantomas.Tests/CompilerDirectivesTests.fs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2639,3 +2639,24 @@ let isUnix =
26392639
|> fun p -> (p = 4) || (p = 6) || (p = 128)
26402640
#endif
26412641
"""
2642+
2643+
[<Test>]
2644+
let ``indented #if directive inside another non-indented #if directive should format correctly, 1866`` () =
2645+
formatSourceString
2646+
false
2647+
"""
2648+
#if FOO
2649+
#if BAR
2650+
#endif
2651+
#endif
2652+
"""
2653+
config
2654+
|> prepend newline
2655+
|> should
2656+
equal
2657+
"""
2658+
#if FOO
2659+
#if BAR
2660+
#endif
2661+
#endif
2662+
"""

src/Fantomas/TokenParser.fs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,14 @@ let rec private getTokenizedHashes (sourceCode: string) : Token list =
157157
(fun t ->
158158
let info =
159159
{ t.TokenInfo with
160-
LeftColumn = t.TokenInfo.LeftColumn + hashContentLength
161-
RightColumn = t.TokenInfo.RightColumn + hashContentLength }
160+
LeftColumn =
161+
t.TokenInfo.LeftColumn
162+
+ hashContentLength
163+
+ offset
164+
RightColumn =
165+
t.TokenInfo.RightColumn
166+
+ hashContentLength
167+
+ offset }
162168

163169
{ t with
164170
LineNumber = lineNumber

0 commit comments

Comments
 (0)