From 108bb3146bac9cb9f71a5dafe25f37b542f6daad Mon Sep 17 00:00:00 2001 From: Jochem Pouwels Date: Thu, 25 Feb 2021 15:39:28 +0100 Subject: [PATCH] Implemented "Chained method calls" setting This is a standard CodeStyle setting in most languages --- .../LuaLanguageCodeStyleSettingsProvider.kt | 2 ++ .../formatter/blocks/LuaIndexExprBlock.kt | 18 ++++++++++-------- 2 files changed, 12 insertions(+), 8 deletions(-) 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 49eabd047..6ac829d94 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 @@ -59,6 +59,8 @@ class LuaLanguageCodeStyleSettingsProvider : LanguageCodeStyleSettingsProvider() "METHOD_PARAMETERS_WRAP", "ALIGN_MULTILINE_PARAMETERS", + "ALIGN_MULTILINE_CHAINED_METHODS", + "CALL_PARAMETERS_WRAP", "ALIGN_MULTILINE_PARAMETERS_IN_CALLS", 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