Skip to content

Commit

Permalink
Add colAutoNlnSkip0 to avoid going too new lines too early
Browse files Browse the repository at this point in the history
  • Loading branch information
dungpa committed Apr 24, 2013
1 parent c8e1eac commit c3e00a1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
3 changes: 1 addition & 2 deletions src/Fantomas.Tests/FunctionDefinitionTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,7 @@ let inline heterogenousAdd(value1 : ^T when (^T or ^U) : (static member (+) : ^T
let inline add(value1 : ^T when ^T : (static member (+) : ^T * ^T -> ^T),
value2 : ^T) = value1 + value2
let inline heterogenousAdd(
value1 : ^T when (^T or ^U) : (static member (+) : ^T * ^U
let inline heterogenousAdd(value1 : ^T when (^T or ^U) : (static member (+) : ^T * ^U
-> ^T),
value2 : ^U) = value1 + value2
"""
Expand Down
24 changes: 12 additions & 12 deletions src/Fantomas/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -344,10 +344,10 @@ and genExpr = function
| TypedExpr(Downcast, e, t) -> genExpr e -- " :?> " +> genType t
| TypedExpr(Upcast, e, t) -> genExpr e -- " :> " +> genType t
| TypedExpr(Typed, e, t) -> genExpr e +> sepColon +> genType t
| Tuple es -> atCurrentColumn (col sepComma es (autoNln << genExpr))
| Tuple es -> atCurrentColumn (colAutoNlnSkip0 sepComma es genExpr)
| ArrayOrList(isArray, xs) ->
ifElse isArray (sepOpenA +> atCurrentColumn (col sepSemi xs (autoNln << genExpr)) +> sepCloseA)
(sepOpenL +> atCurrentColumn (col sepSemi xs (autoNln << genExpr)) +> sepCloseL)
ifElse isArray (sepOpenA +> atCurrentColumn (colAutoNlnSkip0 sepSemi xs genExpr) +> sepCloseA)
(sepOpenL +> atCurrentColumn (colAutoNlnSkip0 sepSemi xs genExpr) +> sepCloseL)
| Record(xs, eo) ->
sepOpenS +> opt (!- " with ") eo genExpr
+> atCurrentColumn (col sepSemiNln xs genRecordFieldName)
Expand Down Expand Up @@ -396,9 +396,9 @@ and genExpr = function
| DotGetAppSpecial(s, es) ->
!- s
+> atCurrentColumn
(coli sepNone es (fun i (s, e) ->
autoNlni i (!- (sprintf ".%s" s)
+> ifElse (hasParenthesis e) sepBeforeArg sepSpace +> genExpr e)))
(colAutoNlnSkip0 sepNone es (fun (s, e) ->
(!- (sprintf ".%s" s)
+> ifElse (hasParenthesis e) sepBeforeArg sepSpace +> genExpr e)))
| DotGetApp(e, es) ->
noNln (genExpr e)
+> indent
Expand Down Expand Up @@ -434,7 +434,7 @@ and genExpr = function
| TryFinally(e1, e2) ->
atCurrentColumn (!- "try " +> indent +> sepNln +> genExpr e1 +> unindent ++ "finally"
+> indent +> sepNln +> genExpr e2 +> unindent)
| SequentialSimple es -> atCurrentColumn (col sepSemi es (autoNln << genExpr))
| SequentialSimple es -> atCurrentColumn (colAutoNlnSkip0 sepSemi es genExpr)
/// It seems too annoying to use sepSemiNln
| Sequentials es ->
atCurrentColumn (col sepNln es genExpr)
Expand Down Expand Up @@ -795,14 +795,14 @@ and genPat = function
| [PatSeq(PatTuple, [p1; p2])] when s = "(::)" -> aoc +> genPat p1 -- " :: " +> genPat p2
| [p] -> aoc -- s +> tpsoc +> ifElse (hasParenInPat p) (genPat p) (sepSpace +> genPat p)
/// This pattern is potentially long
| ps -> atCurrentColumn (aoc -- s +> tpsoc +> sepSpace +> col sepSpace ps (autoNln << genPat))
| ps -> atCurrentColumn (aoc -- s +> tpsoc +> sepSpace +> colAutoNlnSkip0 sepSpace ps genPat)
| PatParen(PatConst(c)) -> genConst c
| PatParen(p) -> sepOpenT +> genPat p +> sepCloseT
| PatSeq(PatTuple, ps) -> atCurrentColumn (col sepComma ps (autoNln << genPat))
| PatSeq(PatList, ps) -> sepOpenL +> atCurrentColumn (col sepSemi ps (autoNln << genPat)) +> sepCloseL
| PatSeq(PatArray, ps) -> sepOpenA +> atCurrentColumn (col sepSemi ps (autoNln << genPat)) +> sepCloseA
| PatSeq(PatTuple, ps) -> atCurrentColumn (colAutoNlnSkip0 sepComma ps genPat)
| PatSeq(PatList, ps) -> sepOpenL +> atCurrentColumn (colAutoNlnSkip0 sepSemi ps genPat) +> sepCloseL
| PatSeq(PatArray, ps) -> sepOpenA +> atCurrentColumn (colAutoNlnSkip0 sepSemi ps genPat) +> sepCloseA
| PatRecord(xs) ->
sepOpenS +> atCurrentColumn (col sepSemi xs (autoNln << genPatRecordFieldName)) +> sepCloseS
sepOpenS +> atCurrentColumn (colAutoNlnSkip0 sepSemi xs genPatRecordFieldName) +> sepCloseS
| PatConst(c) -> genConst c
| PatIsInst(t) -> !- ":? " +> genType t
/// Quotes will be printed by inner expression
Expand Down
5 changes: 3 additions & 2 deletions src/Fantomas/FormatConfig.fs
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,9 @@ let autoNln f (ctx : Context) =
else
f ctx

/// Skip auto newline for index 0
let autoNlni i = if i = 0 then id else autoNln
/// Similar to col, skip auto newline for index 0
let colAutoNlnSkip0 f' (c : seq<'T>) f (ctx : Context) =
coli f' c (fun i c -> if i = 0 then f c else autoNln (f c)) ctx

/// Skip all auto-breaking newlines
let noNln f (ctx : Context) : Context =
Expand Down

0 comments on commit c3e00a1

Please sign in to comment.