diff --git a/src/main/java/com/tang/intellij/lua/editor/formatter/LuaLanguageCodeStyleSettingsProvider.kt b/src/main/java/com/tang/intellij/lua/editor/formatter/LuaLanguageCodeStyleSettingsProvider.kt index 5cf0a1351..788ab1a36 100644 --- a/src/main/java/com/tang/intellij/lua/editor/formatter/LuaLanguageCodeStyleSettingsProvider.kt +++ b/src/main/java/com/tang/intellij/lua/editor/formatter/LuaLanguageCodeStyleSettingsProvider.kt @@ -64,8 +64,11 @@ class LuaLanguageCodeStyleSettingsProvider : LanguageCodeStyleSettingsProvider() "CALL_PARAMETERS_WRAP", "ALIGN_MULTILINE_PARAMETERS_IN_CALLS", + "ALIGN_MULTILINE_CHAINED_METHODS", + // keep when reformatting "KEEP_SIMPLE_BLOCKS_IN_ONE_LINE", + "KEEP_MULTIPLE_EXPRESSIONS_IN_ONE_LINE", //align group declarations "ALIGN_CONSECUTIVE_VARIABLE_DECLARATIONS" diff --git a/src/main/java/com/tang/intellij/lua/editor/formatter/blocks/LuaIndexExprBlock.kt b/src/main/java/com/tang/intellij/lua/editor/formatter/blocks/LuaIndexExprBlock.kt index 2c4277d1a..a10b62532 100644 --- a/src/main/java/com/tang/intellij/lua/editor/formatter/blocks/LuaIndexExprBlock.kt +++ b/src/main/java/com/tang/intellij/lua/editor/formatter/blocks/LuaIndexExprBlock.kt @@ -31,14 +31,16 @@ class LuaIndexExprBlock(psi: LuaIndexExpr, wrap: Wrap?, alignment: Alignment?, i private val dotAlign = Alignment.createAlignment(true) private val align: Alignment? get() { - val p = parentBlock ?: return dotAlign - if (p is LuaIndexExprBlock) - return p.align - else { - if (p.elementType == LuaTypes.CALL_EXPR) { - val pp = p.parentBlock - if (pp is LuaIndexExprBlock) - return pp.align + if (ctx.settings.ALIGN_MULTILINE_CHAINED_METHODS) { + val p = parentBlock ?: return dotAlign + if (p is LuaIndexExprBlock) + return p.align + else { + if (p.elementType == LuaTypes.CALL_EXPR) { + val pp = p.parentBlock + if (pp is LuaIndexExprBlock) + return pp.align + } } } return dotAlign diff --git a/src/main/java/com/tang/intellij/lua/editor/formatter/blocks/LuaScriptBlock.kt b/src/main/java/com/tang/intellij/lua/editor/formatter/blocks/LuaScriptBlock.kt index be4aff3f9..1bf188fa7 100644 --- a/src/main/java/com/tang/intellij/lua/editor/formatter/blocks/LuaScriptBlock.kt +++ b/src/main/java/com/tang/intellij/lua/editor/formatter/blocks/LuaScriptBlock.kt @@ -139,9 +139,11 @@ open class LuaScriptBlock(val psi: PsiElement, } override fun getSpacing(child1: Block?, child2: Block): Spacing? { - if ((child1 is LuaScriptBlock && child1.psi is LuaStatement) && - (child2 is LuaScriptBlock && child2.psi is LuaStatement)) { - return Spacing.createSpacing(1, 0, 1, true, 1) + if (!ctx.settings.KEEP_MULTIPLE_EXPRESSIONS_IN_ONE_LINE) { + if ((child1 is LuaScriptBlock && child1.psi is LuaStatement) && + (child2 is LuaScriptBlock && child2.psi is LuaStatement)) { + return Spacing.createSpacing(1, 0, 1, true, 1) + } } return ctx.spaceBuilder.getSpacing(this, child1, child2) }