Skip to content

Commit

Permalink
Keep new line before SynExpr.DotIndexedSet. Fixes #1314. (#1316)
Browse files Browse the repository at this point in the history
  • Loading branch information
nojaf authored Dec 22, 2020
1 parent 162d3d0 commit 88235c3
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
55 changes: 55 additions & 0 deletions src/Fantomas.Tests/SynExprSetTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -199,3 +199,58 @@ let ``multi line DotNamedIndexedPropertySet`` () =
|> string
|> StringValues
"""

[<Test>]
let ``keep new line before SynExpr.DotIndexedSet, 1314`` () =
formatSourceString
false
"""
match x with
| NotificationEvent.Lint (file, warnings) ->
let uri = Path.FilePathToUri file
diagnosticCollections.AddOrUpdate((uri, "F# Linter"), [||], (fun _ _ -> [||]))
|> ignore
let fs =
warnings
|> List.choose
(fun w ->
w.Warning.Details.SuggestedFix
|> Option.bind
(fun f ->
let f = f.Force()
let range = fcsRangeToLsp w.Warning.Details.Range
f
|> Option.map (fun f -> range, { Range = range; NewText = f.ToText })))
lintFixes.[uri] <- fs
"""
config
|> prepend newline
|> should
equal
"""
match x with
| NotificationEvent.Lint (file, warnings) ->
let uri = Path.FilePathToUri file
diagnosticCollections.AddOrUpdate((uri, "F# Linter"), [||], (fun _ _ -> [||]))
|> ignore
let fs =
warnings
|> List.choose
(fun w ->
w.Warning.Details.SuggestedFix
|> Option.bind
(fun f ->
let f = f.Force()
let range = fcsRangeToLsp w.Warning.Details.Range
f
|> Option.map (fun f -> range, { Range = range; NewText = f.ToText })))
lintFixes.[uri] <- fs
"""
1 change: 1 addition & 0 deletions src/Fantomas/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2737,6 +2737,7 @@ and genExpr astContext synExpr ctx =
| SynExpr.Upcast _ -> genTriviaFor SynExpr_Upcast synExpr.Range
| SynExpr.Downcast _ -> genTriviaFor SynExpr_Downcast synExpr.Range
| SynExpr.DotIndexedGet _ -> genTriviaFor SynExpr_DotIndexedGet synExpr.Range
| SynExpr.DotIndexedSet _ -> genTriviaFor SynExpr_DotIndexedSet synExpr.Range
| _ -> id)

expr ctx
Expand Down

0 comments on commit 88235c3

Please sign in to comment.