Skip to content

Commit

Permalink
Extract helper function to Context.
Browse files Browse the repository at this point in the history
  • Loading branch information
nojaf committed Feb 9, 2024
1 parent 50b257a commit c4f0774
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Fantomas.Core/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2925,7 +2925,7 @@ let genBinding (b: BindingNode) (ctx: Context) : Context =
+> afterLetKeyword
+> sepSpace
+> genFunctionName
+> indent
+> experimentalDoubleIndent
+> sepNln
+> genParameters
+> onlyIf nlnOnSeparateLine sepNln
Expand All @@ -2934,7 +2934,7 @@ let genBinding (b: BindingNode) (ctx: Context) : Context =
sepNln +> genSingleTextNode b.Equals
else
sepSpace +> genSingleTextNode b.Equals)
+> unindent
+> experimentalDoubleUnindent
+> onlyIf hasTriviaAfterLeadingKeyword unindent)
ctx

Expand Down
18 changes: 18 additions & 0 deletions src/Fantomas.Core/Context.fs
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,24 @@ let indent (ctx: Context) =
let unindent (ctx: Context) =
writerEvent (UnIndentBy ctx.Config.IndentSize) ctx

let experimentalDoubleIndent (ctx: Context) =
let indentSize =
if not ctx.Config.ExperimentalDoubleIndentParameters then
ctx.Config.IndentSize
else
2 * ctx.Config.IndentSize

writerEvent (IndentBy indentSize) ctx

let experimentalDoubleUnindent (ctx: Context) =
let indentSize =
if not ctx.Config.ExperimentalDoubleIndentParameters then
ctx.Config.IndentSize
else
2 * ctx.Config.IndentSize

writerEvent (UnIndentBy indentSize) ctx

/// Apply function f at an absolute indent level (use with care)
let atIndentLevel alsoSetIndent level (f: Context -> Context) (ctx: Context) =
if level < 0 then
Expand Down
9 changes: 9 additions & 0 deletions src/Fantomas.Core/Context.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,15 @@ val lastWriteEventIsNewline: ctx: Context -> bool
val indent: ctx: Context -> Context
/// Unindent one more level based on configuration
val unindent: ctx: Context -> Context

/// Add double indent if ExperimentalDoubleIndentParameters is active
/// Otherwise, add single indent
val experimentalDoubleIndent: ctx: Context -> Context

/// Add double unindent if ExperimentalDoubleIndentParameters is active
/// Otherwise, add single unindent
val experimentalDoubleUnindent: ctx: Context -> Context

// /// Apply function f at an absolute indent level (use with care)
val atIndentLevel: alsoSetIndent: bool -> level: int -> f: (Context -> Context) -> ctx: Context -> Context
// /// Set minimal indentation (`atColumn`) at current column position - next newline will be indented on `max indent atColumn`
Expand Down

0 comments on commit c4f0774

Please sign in to comment.