Skip to content

Commit 9643d20

Browse files
committed
Add space_inside_function_param_list_parentheses option.
1 parent 34960f6 commit 9643d20

File tree

7 files changed

+85
-1
lines changed

7 files changed

+85
-1
lines changed

CodeService/src/LuaEditorConfig.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,12 @@ void LuaEditorConfig::ParseFromSection(std::shared_ptr<LuaCodeStyleOptions> opti
387387
configMap.at("space_inside_function_call_parentheses") == "true";
388388
}
389389

390+
if(configMap.count("space_inside_function_param_list_parentheses"))
391+
{
392+
options->space_inside_function_param_list_parentheses =
393+
configMap.at("space_inside_function_param_list_parentheses") == "true";
394+
}
395+
390396
if (configMap.count("space_before_open_square_bracket"))
391397
{
392398
options->space_before_open_square_bracket =

CodeService/src/LuaFormatter.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1476,12 +1476,18 @@ std::shared_ptr<FormatElement> LuaFormatter::FormatParamList(std::shared_ptr<Lua
14761476
paramListLayoutEnv->Add<OperatorElement>(child);
14771477
paramListLayoutEnv->Add<KeepElement>(1);
14781478
}
1479+
else if (child->GetTokenType() == '(')
1480+
{
1481+
env->Add<OperatorElement>(child);
1482+
env->Add<KeepElement>(_options.space_inside_function_param_list_parentheses
1483+
&& children.size() > 2 ? 1 : 0);
1484+
}
14791485
else if (child->GetTokenType() == ')')
14801486
{
14811487
env->AddChild(paramListLayoutEnv);
14821488
if (!paramListLayoutEnv->GetChildren().empty())
14831489
{
1484-
env->Add<KeepElement>(0);
1490+
env->Add<KeepElement>(_options.space_inside_function_param_list_parentheses ? 1 : 0);
14851491
}
14861492

14871493
env->Add<OperatorElement>(child);

Test/test_script/format_text/wait_format_by_option/.editorconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,8 @@ space_before_function_open_parenthesis = true
170170
space_before_open_square_bracket = true
171171
[{space_inside_function_call_parentheses.lua}]
172172
space_inside_function_call_parentheses = true
173+
[{space_inside_function_param_list_parentheses.lua}]
174+
space_inside_function_param_list_parentheses = true
173175
[{minLine-eq-1.lua}]
174176
keep_line_after_if_statement = minLine:1
175177
keep_line_after_do_statement = minLine:1
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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+
function t:fffff(
23+
aaa
24+
)
25+
local t = 13
26+
end
27+
28+
local already_formatted = function( x, y, z )
29+
return x, y, z
30+
end
31+
32+
already_formatted( 'a', 'b', 'c' )
33+
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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+
function t:fffff(
23+
aaa
24+
)
25+
local t = 13
26+
end
27+
28+
local already_formatted = function( x, y, z )
29+
return x, y, z
30+
end
31+
32+
already_formatted('a', 'b', 'c')
33+

include/CodeService/LuaCodeStyleOptions.h

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

8181
bool space_inside_function_call_parentheses = false;
8282

83+
bool space_inside_function_param_list_parentheses = false;
84+
8385
bool space_before_open_square_bracket = false;
8486

8587
/*

lua.template.editorconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ space_before_function_open_parenthesis = false
101101

102102
space_inside_function_call_parentheses = false
103103

104+
space_inside_function_param_list_parentheses = false
105+
104106
space_before_open_square_bracket = false
105107

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

0 commit comments

Comments
 (0)