@@ -1254,10 +1254,11 @@ std::shared_ptr<FormatElement> LuaFormatter::FormatCallArgList(std::shared_ptr<L
12541254
12551255 if (startLine != endLine)
12561256 {
1257- if (!expression->GetChildren ().empty ())
1257+ if (!expression->GetChildren ().empty ())
12581258 {
12591259 auto first = expression->GetChildren ().front ();
1260- if (first->GetType () == LuaAstNodeType::ClosureExpression || first->GetType () == LuaAstNodeType::TableExpression)
1260+ if (first->GetType () == LuaAstNodeType::ClosureExpression || first->GetType () ==
1261+ LuaAstNodeType::TableExpression)
12611262 {
12621263 canAligned = false ;
12631264 break ;
@@ -1550,6 +1551,7 @@ std::shared_ptr<FormatElement> LuaFormatter::FormatTableExpression(std::shared_p
15501551 }
15511552
15521553 int leftBraceLine = 0 ;
1554+ bool forceChopDownEndBracket = false ;
15531555
15541556 for (auto it = children.begin (); it != children.end (); ++it)
15551557 {
@@ -1562,6 +1564,11 @@ std::shared_ptr<FormatElement> LuaFormatter::FormatTableExpression(std::shared_p
15621564 {
15631565 env->Add <TextElement>(child);
15641566 leftBraceLine = _parser->GetLine (child->GetTextRange ().EndOffset );
1567+ auto next = NextNode (it, children);
1568+ if (next && next->GetTokenType () != ' }' )
1569+ {
1570+ forceChopDownEndBracket = leftBraceLine != _parser->GetLine (next->GetTextRange ().StartOffset );
1571+ }
15651572 }
15661573 else if (child->GetTokenType () == ' }' )
15671574 {
@@ -1573,8 +1580,24 @@ std::shared_ptr<FormatElement> LuaFormatter::FormatTableExpression(std::shared_p
15731580 {
15741581 env->Add <KeepElement>(_options.keep_one_space_between_table_and_bracket ? 1 : 0 );
15751582 env->AddChild (tableFieldLayout);
1583+
1584+ if (forceChopDownEndBracket)
1585+ {
1586+ if (_parser->GetLine (tableFieldLayout->GetTextRange ().EndOffset ) != _parser->GetLine (
1587+ child->GetTextRange ().StartOffset ))
1588+ {
1589+ env->Add <KeepElement>(1 );
1590+ }
1591+ else
1592+ {
1593+ env->Add <LineElement>();
1594+ }
1595+ }
1596+ else
1597+ {
1598+ env->Add <KeepElement>(_options.keep_one_space_between_table_and_bracket ? 1 : 0 );
1599+ }
15761600 tableFieldLayout = nullptr ;
1577- env->Add <KeepElement>(_options.keep_one_space_between_table_and_bracket ? 1 : 0 );
15781601 }
15791602 env->Add <TextElement>(child);
15801603 }
0 commit comments