Skip to content

Commit

Permalink
Retain significant whitespace in nested, indented #if directives (#1867)
Browse files Browse the repository at this point in the history
  • Loading branch information
kentcb committed Aug 19, 2021
1 parent 383b729 commit a80f888
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
21 changes: 21 additions & 0 deletions src/Fantomas.Tests/CompilerDirectivesTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2639,3 +2639,24 @@ let isUnix =
|> fun p -> (p = 4) || (p = 6) || (p = 128)
#endif
"""

[<Test>]
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
"""
10 changes: 8 additions & 2 deletions src/Fantomas/TokenParser.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a80f888

Please sign in to comment.