MCPcopy Create free account
hub / github.com/Koihik/LuaFormatter / visitArgs

Method visitArgs

src/FormatVisitor.cpp:1399–1465  ·  view source on GitHub ↗

LP explist? RP | tableconstructor | string;

Source from the content-addressed store, hash-verified

1397
1398// LP explist? RP | tableconstructor | string;
1399antlrcpp::Any FormatVisitor::visitArgs(LuaParser::ArgsContext* ctx) {
1400 LOG_FUNCTION_BEGIN();
1401 if (ctx->LP() != nullptr) {
1402 cur_writer() << ctx->LP()->getText();
1403 if (ctx->explist() != nullptr) {
1404 bool breakAfterLp = false;
1405 auto p = calcASTLengthAndLines(ctx->explist(), [=]() {
1406 cur_writer() << commentAfter(ctx->LP(), "");
1407 visitExplist(ctx->explist());
1408 cur_writer() << commentAfter(ctx->explist(), "");
1409 });
1410 int length = p.first;
1411 int lines = p.second;
1412 if (!config_.get<bool>("break_before_functioncall_rp")) {
1413 length++;
1414 }
1415 bool beyondLimit = cur_columns() + length > config_.get<int>("column_limit");
1416 if (beyondLimit || lines > 1) {
1417 breakAfterLp = config_.get<bool>("break_after_functioncall_lp");
1418 }
1419 if (config_.get<bool>("spaces_inside_functioncall_parens") && !breakAfterLp) {
1420 cur_writer() << " ";
1421 }
1422 functioncallLpHasBreak_.push_back(breakAfterLp);
1423 if (breakAfterLp) {
1424 // break line on '(' keeping comments
1425 cur_writer() << commentAfterNewLine(ctx->LP(), INC_CONTINUATION_INDENT);
1426 cur_writer() << indentWithAlign();
1427 } else {
1428 std::string comment = commentAfter(ctx->LP(), "");
1429 if (!comment.empty() && comment.back() == '\n') {
1430 // avoid a duplicate newline
1431 comment.pop_back();
1432 }
1433 cur_writer() << comment;
1434 }
1435 visitExplist(ctx->explist());
1436 // 'visitExplist' will leave 'indent_' on 0 if we detect that it will break line
1437 // on '(' by itself, therefore we cannot decrement 'indent_'
1438 if (config_.get<bool>("break_before_functioncall_rp")) {
1439 if (breakAfterLp) {
1440 cur_writer() << commentAfterNewLine(ctx->explist(), DEC_CONTINUATION_INDENT);
1441 cur_writer() << indentWithAlign();
1442 } else {
1443 cur_writer() << commentAfter(ctx->explist(), "");
1444 }
1445 } else {
1446 if (breakAfterLp) {
1447 decContinuationIndent();
1448 }
1449 cur_writer() << commentAfter(ctx->explist(), "");
1450 }
1451 if (config_.get<bool>("spaces_inside_functioncall_parens")) {
1452 cur_writer() << " ";
1453 }
1454 functioncallLpHasBreak_.pop_back();
1455 cur_writer() << ctx->RP()->getText();
1456 } else {

Callers

nothing calls this directly

Calls 3

LPMethod · 0.80
explistMethod · 0.80
RPMethod · 0.80

Tested by

no test coverage detected