1717#include " CodeService/FormatElement/NoIndentElement.h"
1818#include " CodeService/FormatElement/SerializeContext.h"
1919#include " CodeService/FormatElement/IndentOnLineBreakElement.h"
20+ #include " CodeService/FormatElement/PlaceHolderElement.h"
2021#include " Util/StringUtil.h"
2122
2223bool nextMatch (LuaAstNode::ChildIterator it, LuaAstNodeType type, const LuaAstNode::ChildrenContainer& container)
@@ -1029,6 +1030,9 @@ std::shared_ptr<FormatElement> LuaFormatter::FormatIfStatement(std::shared_ptr<L
10291030{
10301031 auto env = std::make_shared<StatementElement>();
10311032 auto & children = ifStatement->GetChildren ();
1033+
1034+ std::vector<std::shared_ptr<PlaceholderElement>> placeholderExpressions;
1035+
10321036 for (auto it = children.begin (); it != children.end (); ++it)
10331037 {
10341038 const auto child = *it;
@@ -1056,13 +1060,21 @@ std::shared_ptr<FormatElement> LuaFormatter::FormatIfStatement(std::shared_ptr<L
10561060 }
10571061 case LuaAstNodeType::Expression:
10581062 {
1059- std::shared_ptr<FormatElement> expression = nullptr ;
1060- if (_options.if_condition_no_continuation_indent )
1063+ if (_options.if_condition_align_with_each_other )
10611064 {
1062- expression = std::make_shared<LongExpressionLayoutElement>(0 );
1065+ placeholderExpressions.push_back (std::make_shared<PlaceholderElement>(env, child));
1066+ env->AddChild (placeholderExpressions.back ());
10631067 }
1068+ else
1069+ {
1070+ std::shared_ptr<FormatElement> expression = nullptr ;
1071+ if (_options.if_condition_no_continuation_indent )
1072+ {
1073+ expression = std::make_shared<LongExpressionLayoutElement>(0 );
1074+ }
10641075
1065- env->AddChild (FormatExpression (child, expression));
1076+ env->AddChild (FormatExpression (child, expression));
1077+ }
10661078 env->Add <KeepBlankElement>(1 );
10671079 break ;
10681080 }
@@ -1074,6 +1086,11 @@ std::shared_ptr<FormatElement> LuaFormatter::FormatIfStatement(std::shared_ptr<L
10741086 }
10751087 }
10761088
1089+ if (!placeholderExpressions.empty ())
1090+ {
1091+ FormatIfConditionAlign (placeholderExpressions);
1092+ }
1093+
10771094 return env;
10781095}
10791096
@@ -2156,6 +2173,19 @@ std::shared_ptr<FormatElement> LuaFormatter::FormatTableAppendExpression(std::sh
21562173 return FormatExpression (expression, env);
21572174}
21582175
2176+ void LuaFormatter::FormatIfConditionAlign (std::vector<std::shared_ptr<PlaceholderElement>>& placeholders)
2177+ {
2178+ bool canAlign = true ;
2179+ for (auto placeholder: placeholders)
2180+ {
2181+
2182+ }
2183+
2184+
2185+
2186+
2187+
2188+ }
21592189
21602190std::shared_ptr<FormatElement> LuaFormatter::FormatRangeBlock (std::shared_ptr<LuaAstNode> blockNode,
21612191 LuaFormatRange& validRange)
0 commit comments