Skip to content

Commit

Permalink
Don't break line between TypeApp and Parenthesis tuple inside DotGet. F…
Browse files Browse the repository at this point in the history
…ixes #1134. (#1135)
  • Loading branch information
nojaf authored Sep 13, 2020
1 parent 5632847 commit fe9b65f
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 5 deletions.
70 changes: 70 additions & 0 deletions src/Fantomas.Tests/DotGetTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,73 @@ root.SetAttribute
+ System.Diagnostics.FileVersionInfo.GetVersionInfo(System.Reflection.Assembly.GetExecutingAssembly().Location)
.FileVersion)
"""

[<Test>]
let ``keep parenthesis on same line as SynExpr.TypeApp`` () =
formatSourceString false """
Equinox.EventStore.Resolver<'event, 'state, _>(gateway, codec, fold, initial, cacheStrategy, accessStrategy).Resolve
""" { config with MaxLineLength = 100 }
|> prepend newline
|> should equal """
Equinox.EventStore.Resolver<'event, 'state, _>(gateway,
codec,
fold,
initial,
cacheStrategy,
accessStrategy)
.Resolve
"""

[<Test>]
let ``don't break line for generic function call, 1134`` () =
formatSourceString false """
module Services =
/// Builds a Stream Resolve function appropriate to the store being used
type StreamResolver(storage: Storage.Instance) =
member __.Resolve
(
codec: FsCodec.IEventCodec<'event, byte [], _>,
fold: ('state -> 'event seq -> 'state),
initial: 'state,
snapshot: (('event -> bool) * ('state -> 'event))
)
=
match storage with
| Storage.MemoryStore store ->
Equinox.MemoryStore.Resolver(store, FsCodec.Box.Codec.Create(), fold, initial).Resolve
| Storage.EventStore (gateway, cache) ->
let accessStrategy =
Equinox.EventStore.AccessStrategy.RollingSnapshots snapshot
let cacheStrategy =
Equinox.EventStore.CachingStrategy.SlidingWindow(cache, TimeSpan.FromMinutes 20.)
Equinox.EventStore.Resolver<'event, 'state, _>(gateway, codec, fold, initial, cacheStrategy, accessStrategy).Resolve
""" config
|> prepend newline
|> should equal """
module Services =
/// Builds a Stream Resolve function appropriate to the store being used
type StreamResolver(storage: Storage.Instance) =
member __.Resolve(codec: FsCodec.IEventCodec<'event, byte [], _>,
fold: ('state -> 'event seq -> 'state),
initial: 'state,
snapshot: (('event -> bool) * ('state -> 'event))) =
match storage with
| Storage.MemoryStore store ->
Equinox.MemoryStore.Resolver(store, FsCodec.Box.Codec.Create(), fold, initial).Resolve
| Storage.EventStore (gateway, cache) ->
let accessStrategy =
Equinox.EventStore.AccessStrategy.RollingSnapshots snapshot
let cacheStrategy =
Equinox.EventStore.CachingStrategy.SlidingWindow(cache, TimeSpan.FromMinutes 20.)
Equinox.EventStore.Resolver<'event, 'state, _>(gateway,
codec,
fold,
initial,
cacheStrategy,
accessStrategy)
.Resolve
"""
18 changes: 13 additions & 5 deletions src/Fantomas/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1881,11 +1881,18 @@ and genExpr astContext synExpr =
+> indent
+> (ifElse (not hasPar && addSpaceBefore) sepSpace sepNone)
+> (fun ctx ->
match e2 with
| Paren (_, App (_), _) when astContext.IsInsideDotGet -> genExpr astContext e2 ctx
| Paren (_, DotGet (App (_), _), _) when astContext.IsInsideDotGet -> genExpr astContext e2 ctx
| ConstExpr (SynConst.Unit, _) when astContext.IsInsideDotGet -> genExpr astContext e2 ctx
| _ -> appNlnFun e2 (genExpr astContext e2) ctx)
let expr =
if astContext.IsInsideDotGet then
match e1, e2 with
| _, Paren (_, App (_), _)
| _, Paren (_, DotGet (App (_), _), _)
| TypeApp _, Paren (_, Tuple _, _)
| _, ConstExpr (SynConst.Unit, _) -> genExpr astContext e2
| _ -> appNlnFun e2 (genExpr astContext e2)
else
appNlnFun e2 (genExpr astContext e2)

expr ctx)
+> unindent)

genApp ctx
Expand Down Expand Up @@ -2605,6 +2612,7 @@ and genExpr astContext synExpr =
| SynExpr.While _ -> genTriviaFor SynExpr_While synExpr.Range
| SynExpr.MatchLambda _ -> genTriviaFor SynExpr_MatchLambda synExpr.Range
| SynExpr.LongIdent _ -> genTriviaFor SynExpr_LongIdent synExpr.Range
| SynExpr.DotGet _ -> genTriviaFor SynExpr_DotGet synExpr.Range
| _ -> id)

and genMultilineRecordInstance (inheritOpt: (SynType * SynExpr) option)
Expand Down

0 comments on commit fe9b65f

Please sign in to comment.