Skip to content

Commit 34960f6

Browse files
committed
Add space_inside_function_call_parentheses option.
1 parent cd6e485 commit 34960f6

File tree

7 files changed

+81
-4
lines changed

7 files changed

+81
-4
lines changed

CodeService/src/LuaEditorConfig.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,12 @@ void LuaEditorConfig::ParseFromSection(std::shared_ptr<LuaCodeStyleOptions> opti
381381
configMap.at("space_before_function_open_parenthesis") == "true";
382382
}
383383

384+
if(configMap.count("space_inside_function_call_parentheses"))
385+
{
386+
options->space_inside_function_call_parentheses =
387+
configMap.at("space_inside_function_call_parentheses") == "true";
388+
}
389+
384390
if (configMap.count("space_before_open_square_bracket"))
385391
{
386392
options->space_before_open_square_bracket =

CodeService/src/LuaFormatter.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1350,14 +1350,25 @@ std::shared_ptr<FormatElement> LuaFormatter::FormatCallArgList(std::shared_ptr<L
13501350
}
13511351

13521352
env->AddChild(FormatCallArgsExpressionList(child, layout));
1353-
env->Add<KeepElement>(0);
1353+
env->Add<KeepElement>(_options.space_inside_function_call_parentheses ? 1 : 0);
1354+
13541355
break;
13551356
}
13561357
case LuaAstNodeType::GeneralOperator:
13571358
{
1358-
env->Add<OperatorElement>(child);
1359-
env->Add<KeepElement>(0);
1360-
break;
1359+
if (child->GetTokenType() == '(')
1360+
{
1361+
env->Add<OperatorElement>(child);
1362+
env->Add<KeepElement>(_options.space_inside_function_call_parentheses
1363+
&& children.size() > 2 ? 1 : 0);
1364+
break;
1365+
}
1366+
else
1367+
{
1368+
env->Add<OperatorElement>(child);
1369+
env->Add<KeepElement>(0);
1370+
break;
1371+
}
13611372
}
13621373
case LuaAstNodeType::StringLiteralExpression:
13631374
case LuaAstNodeType::TableExpression:

Test/test_script/format_text/wait_format_by_option/.editorconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,8 @@ remove_expression_list_finish_comma = true
168168
[{space_option.lua}]
169169
space_before_function_open_parenthesis = true
170170
space_before_open_square_bracket = true
171+
[{space_inside_function_call_parentheses.lua}]
172+
space_inside_function_call_parentheses = true
171173
[{minLine-eq-1.lua}]
172174
keep_line_after_if_statement = minLine:1
173175
keep_line_after_do_statement = minLine:1
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
local f0 = function()
2+
end
3+
4+
local f1 = function(a)
5+
return a
6+
end
7+
8+
local f2 = function(a,b)
9+
return a, b
10+
end
11+
12+
local f3 = function(a,b,c)
13+
return a, b, c
14+
end
15+
16+
f0()
17+
18+
local a = f1(123)
19+
local b1, b2 = f2( 'b1','b2')
20+
local c1, c2, c3 = f3('c1', 'c2','c3' )
21+
22+
local d1, d2, d3 = f3(
23+
'c1',
24+
'c2',
25+
'c3'
26+
)
27+
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
local f0 = function()
2+
end
3+
4+
local f1 = function(a)
5+
return a
6+
end
7+
8+
local f2 = function(a, b)
9+
return a, b
10+
end
11+
12+
local f3 = function(a, b, c)
13+
return a, b, c
14+
end
15+
16+
f0()
17+
18+
local a = f1( 123 )
19+
local b1, b2 = f2( 'b1', 'b2' )
20+
local c1, c2, c3 = f3( 'c1', 'c2', 'c3' )
21+
22+
local d1, d2, d3 = f3(
23+
'c1',
24+
'c2',
25+
'c3'
26+
)
27+

include/CodeService/LuaCodeStyleOptions.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ class LuaCodeStyleOptions
7878

7979
bool space_before_function_open_parenthesis = false;
8080

81+
bool space_inside_function_call_parentheses = false;
82+
8183
bool space_before_open_square_bracket = false;
8284

8385
/*

lua.template.editorconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ remove_empty_header_and_footer_lines_in_function = true
9999

100100
space_before_function_open_parenthesis = false
101101

102+
space_inside_function_call_parentheses = false
103+
102104
space_before_open_square_bracket = false
103105

104106
# if true, ormat like this "local t <const> = 1"

0 commit comments

Comments
 (0)