From c4f0774bfc40a7a7b91feb25dc5c52aa0f29c442 Mon Sep 17 00:00:00 2001 From: nojaf Date: Fri, 9 Feb 2024 11:52:25 +0100 Subject: [PATCH] Extract helper function to Context. --- src/Fantomas.Core/CodePrinter.fs | 4 ++-- src/Fantomas.Core/Context.fs | 18 ++++++++++++++++++ src/Fantomas.Core/Context.fsi | 9 +++++++++ 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/Fantomas.Core/CodePrinter.fs b/src/Fantomas.Core/CodePrinter.fs index 94a282eb62..3ab606d351 100644 --- a/src/Fantomas.Core/CodePrinter.fs +++ b/src/Fantomas.Core/CodePrinter.fs @@ -2925,7 +2925,7 @@ let genBinding (b: BindingNode) (ctx: Context) : Context = +> afterLetKeyword +> sepSpace +> genFunctionName - +> indent + +> experimentalDoubleIndent +> sepNln +> genParameters +> onlyIf nlnOnSeparateLine sepNln @@ -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 diff --git a/src/Fantomas.Core/Context.fs b/src/Fantomas.Core/Context.fs index 31540dcb3f..14629a5ced 100644 --- a/src/Fantomas.Core/Context.fs +++ b/src/Fantomas.Core/Context.fs @@ -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 diff --git a/src/Fantomas.Core/Context.fsi b/src/Fantomas.Core/Context.fsi index 9118d47469..dab39de20b 100644 --- a/src/Fantomas.Core/Context.fsi +++ b/src/Fantomas.Core/Context.fsi @@ -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`