Skip to content

Commit a64453b

Browse files
committed
IMPL #43
1 parent 48b9aca commit a64453b

File tree

3 files changed

+55
-5
lines changed

3 files changed

+55
-5
lines changed

CodeService/src/LuaEditorConfig.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ void LuaEditorConfig::ParseFromSection(std::shared_ptr<LuaCodeStyleOptions> opti
243243
options->continuation_indent_size = std::stoi(configMap.at("continuation_indent_size"));
244244
}
245245

246-
if(configMap.count("statement_inline_comment_space")
246+
if (configMap.count("statement_inline_comment_space")
247247
&& IsNumber(configMap.at("statement_inline_comment_space")))
248248
{
249249
options->statement_inline_comment_space = std::stoi(configMap.at("statement_inline_comment_space"));
@@ -346,12 +346,18 @@ void LuaEditorConfig::ParseFromSection(std::shared_ptr<LuaCodeStyleOptions> opti
346346
configMap.at("long_chain_expression_allow_one_space_after_colon") == "true";
347347
}
348348

349-
if(configMap.count("remove_empty_header_and_footer_lines_in_function"))
349+
if (configMap.count("remove_empty_header_and_footer_lines_in_function"))
350350
{
351351
options->remove_empty_header_and_footer_lines_in_function =
352352
configMap.at("remove_empty_header_and_footer_lines_in_function") == "true";
353353
}
354354

355+
if (configMap.count("remove_expression_list_finish_comma"))
356+
{
357+
options->remove_expression_list_finish_comma =
358+
configMap.at("remove_expression_list_finish_comma") == "true";
359+
}
360+
355361
if (configMap.count("end_of_line"))
356362
{
357363
auto lineSeparatorSymbol = configMap.at("end_of_line");
@@ -380,10 +386,12 @@ void LuaEditorConfig::ParseFromSection(std::shared_ptr<LuaCodeStyleOptions> opti
380386

381387
if (configMap.count("max_line_length"))
382388
{
383-
if (IsNumber(configMap.at("max_line_length"))) {
389+
if (IsNumber(configMap.at("max_line_length")))
390+
{
384391
options->max_line_length = std::stoi(configMap.at("max_line_length"));
385392
}
386-
else if(configMap.at("max_line_length") == "unset"){
393+
else if (configMap.at("max_line_length") == "unset")
394+
{
387395
options->max_line_length = std::numeric_limits<int>::max();
388396
}
389397
}

CodeService/src/LuaFormatter.cpp

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,40 @@ std::shared_ptr<FormatElement> LuaFormatter::FormatExpressionList(std::shared_pt
639639
return env;
640640
}
641641

642+
std::shared_ptr<FormatElement> LuaFormatter::FormatCallArgsExpressionList(std::shared_ptr<LuaAstNode> expressionList,
643+
std::shared_ptr<FormatElement> env)
644+
{
645+
auto& children = expressionList->GetChildren();
646+
for (auto& node : children)
647+
{
648+
switch (node->GetType())
649+
{
650+
case LuaAstNodeType::Expression:
651+
{
652+
auto subEnv = std::make_shared<SubExpressionElement>();
653+
env->AddChild(FormatExpression(node, subEnv));
654+
env->Add<KeepElement>(0);
655+
break;
656+
}
657+
case LuaAstNodeType::GeneralOperator:
658+
{
659+
if (_options.remove_expression_list_finish_comma && node == children.back())
660+
{
661+
break;
662+
}
663+
env->Add<TextElement>(node);
664+
env->Add<KeepElement>(1);
665+
break;
666+
}
667+
default:
668+
DefaultHandle(node, env);
669+
env->Add<KeepElement>(1);
670+
}
671+
}
672+
673+
return env;
674+
}
675+
642676
std::shared_ptr<FormatElement> LuaFormatter::FormatAssignLeftExpressionList(std::shared_ptr<LuaAstNode> expressionList)
643677
{
644678
auto env = std::make_shared<LongExpressionLayoutElement>(_options.continuation_indent_size);
@@ -1242,7 +1276,7 @@ std::shared_ptr<FormatElement> LuaFormatter::FormatCallArgList(std::shared_ptr<L
12421276
layout = std::make_shared<CallArgsListLayoutElement>();
12431277
}
12441278

1245-
env->AddChild(FormatExpressionList(child, layout));
1279+
env->AddChild(FormatCallArgsExpressionList(child, layout));
12461280
env->Add<KeepElement>(0);
12471281
break;
12481282
}
@@ -1341,6 +1375,11 @@ std::shared_ptr<FormatElement> LuaFormatter::FormatParamList(std::shared_ptr<Lua
13411375
{
13421376
if (child->GetText() == ",")
13431377
{
1378+
if(_options.remove_expression_list_finish_comma
1379+
&& NextMatch(it, LuaAstNodeType::GeneralOperator, children))
1380+
{
1381+
break;
1382+
}
13441383
paramListLayoutEnv->Add<TextElement>(child);
13451384
paramListLayoutEnv->Add<KeepElement>(1);
13461385
}

include/CodeService/LuaFormatter.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ class LuaFormatter
3737
std::shared_ptr<FormatElement> FormatExpressionList(std::shared_ptr<LuaAstNode> expressionList,
3838
std::shared_ptr<FormatElement> env = nullptr);
3939

40+
std::shared_ptr<FormatElement> FormatCallArgsExpressionList(std::shared_ptr<LuaAstNode> expressionList,
41+
std::shared_ptr<FormatElement> env);
42+
4043
std::shared_ptr<FormatElement> FormatAssignLeftExpressionList(std::shared_ptr<LuaAstNode> expressionList);
4144

4245
std::shared_ptr<FormatElement> FormatComment(std::shared_ptr<LuaAstNode> comment);

0 commit comments

Comments
 (0)