Skip to content

Commit 03c0d50

Browse files
committed
修改测试方式,新增几个配置项,修改默认配置
1 parent c8d8c56 commit 03c0d50

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+224
-24
lines changed

CodeService/src/FormatElement/FormatElement.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,12 @@ void FormatElement::CopyFrom(std::shared_ptr<FormatElement> node)
205205
_children = node->_children;
206206
}
207207

208+
void FormatElement::Reset()
209+
{
210+
_textRange = TextRange();
211+
_children.clear();
212+
}
213+
208214
int FormatElement::GetLastValidOffset(ChildIterator& it, FormatElement& parent)
209215
{
210216
auto& siblings = parent.GetChildren();

CodeService/src/LuaCodeStyleOptions.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ std::string GetIndentStyleName(IndentStyle style)
2222

2323
LuaCodeStyleOptions::LuaCodeStyleOptions()
2424
:
25-
keep_line_after_if_statement(std::make_shared<MinLineElement>(1)),
26-
keep_line_after_do_statement(std::make_shared<MinLineElement>(1)),
27-
keep_line_after_while_statement(std::make_shared<MinLineElement>(1)),
28-
keep_line_after_repeat_statement(std::make_shared<MinLineElement>(1)),
29-
keep_line_after_for_statement(std::make_shared<MinLineElement>(1)),
25+
keep_line_after_if_statement(std::make_shared<MinLineElement>(0)),
26+
keep_line_after_do_statement(std::make_shared<MinLineElement>(0)),
27+
keep_line_after_while_statement(std::make_shared<MinLineElement>(0)),
28+
keep_line_after_repeat_statement(std::make_shared<MinLineElement>(0)),
29+
keep_line_after_for_statement(std::make_shared<MinLineElement>(0)),
3030
keep_line_after_local_or_assign_statement(std::make_shared<KeepLineElement>()),
3131
keep_line_after_function_define_statement(std::make_shared<KeepLineElement>(1)),
3232

CodeService/src/LuaEditorConfig.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,4 +328,9 @@ void LuaEditorConfig::ParseFromSection(std::shared_ptr<LuaCodeStyleOptions> opti
328328
styleOption.second = NameStyleRuleMatcher::ParseFrom(value);
329329
}
330330
}
331+
332+
if(options->indent_style == IndentStyle::Tab)
333+
{
334+
options->align_table_field_to_first_field = false;
335+
}
331336
}

CodeService/src/LuaFormatter.cpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1590,16 +1590,10 @@ std::shared_ptr<FormatElement> LuaFormatter::FormatAlignTableField(LuaAstNode::C
15901590
// 认为tableField 可以(但不是必须这样做)按照等号对齐
15911591
if (alignToEq && _options.continuous_assign_table_field_align_to_equal_sign)
15921592
{
1593-
auto newEnv = std::make_shared<AlignToFirstElement>();
15941593
auto alignmentLayoutElement = std::make_shared<AlignmentLayoutElement>();
1595-
for (auto child : env->GetChildren())
1596-
{
1597-
alignmentLayoutElement->AddChild(child);
1598-
}
1599-
1600-
newEnv->AddChild(alignmentLayoutElement);
1601-
1602-
env = newEnv;
1594+
alignmentLayoutElement->CopyFrom(env);
1595+
env->Reset();
1596+
env->AddChild(alignmentLayoutElement);
16031597
}
16041598

16051599
return env;

Test/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@ target_sources(CodeFormatTest
1919
target_link_libraries(CodeFormatTest CodeService Util)
2020

2121
add_test(NAME GrammarTest COMMAND CodeFormatTest CheckGrammar -w ${CodeFormatTest_SOURCE_DIR}/test_script/grammar)
22-
add_test(NAME FormatTest COMMAND CodeFormatTest CheckFormatResult -w ${CodeFormatTest_SOURCE_DIR}/test_script/format_text -f ${CodeFormatTest_SOURCE_DIR}/test_script/format_text_shouldbe)
22+
add_test(NAME FormatTest COMMAND CodeFormatTest CheckFormatResult -w ${CodeFormatTest_SOURCE_DIR}/test_script/format_tex/wait_format -f ${CodeFormatTest_SOURCE_DIR}/test_script/format_text/wait_format_should_be)
23+
#add_test(NAME FormatByOptionTest COMMAND CodeFormatTest CheckFormatResultByOption -w ${CodeFormatTest_SOURCE_DIR}/test_script/format_tex/wait_format_by_option -f ${CodeFormatTest_SOURCE_DIR}/test_script/format_text/wait_format_by_option_should_be)
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
2+
# see https://github.com/CppCXY/EmmyLuaCodeStyle
3+
[*.lua]
4+
# optional space/tab
5+
indent_style = space
6+
# if indent_style is space, this is valid
7+
indent_size = 4
8+
# if indent_style is tab, this is valid
9+
tab_width = 4
10+
continuation_indent_size = 4
11+
align_call_args = false
12+
keep_one_space_between_call_args_and_parentheses = false
13+
align_function_define_params = true
14+
keep_one_space_between_table_and_bracket = true
15+
align_table_field_to_first_field = true
16+
keep_one_space_between_namedef_and_attribute = false
17+
continuous_assign_statement_align_to_equal_sign = true
18+
continuous_assign_table_field_align_to_equal_sign = true
19+
label_no_indent = false
20+
do_statement_no_indent = false
21+
# optional crlf/lf
22+
end_of_line = crlf
23+
24+
# The following configuration supports three expressions
25+
# minLine:${n}
26+
# keepLine
27+
# KeepLine:${n}
28+
29+
keep_line_after_if_statement = minLine:1
30+
keep_line_after_do_statement = minLine:1
31+
keep_line_after_while_statement = minLine:1
32+
keep_line_after_repeat_statement = minLine:1
33+
keep_line_after_for_statement = minLine:1
34+
keep_line_after_local_or_assign_statement = keepLine
35+
keep_line_after_function_define_statement = keepLine:1
36+
37+
# the following is code diagnostic options
38+
enable_check_codestyle = true
39+
# this mean utf8 length
40+
max_line_length = 120
41+
# this will check text end with new line(format always end with new line)
42+
insert_final_newline = true
43+
44+
45+
enable_name_style_check = false
46+
# the following is name style check rule
47+
# base option off/camel_case/snake_case/upper_snake_case/pascal_case/same(filename/first_param/'<const string>', snake_case/pascal_case/camel_case)
48+
# all option can use '|' represent or
49+
# for example:
50+
# snake_case | upper_snake_case
51+
# same(first_param, snake_case)
52+
# same('m')
53+
local_name_define_style = snake_case
54+
function_param_name_style = snake_case
55+
function_name_define_style = snake_case
56+
local_function_name_define_style = snake_case
57+
table_field_name_define_style = snake_case
58+
global_variable_name_define_style = snake_case|upper_snake_case
59+
module_name_define_style = same('m')|same(filename, snake_case)
60+
require_module_name_style = same(first_param, snake_case)
61+
class_name_define_style = same(filename, snake_case)
62+
[{indent_style-eq-space.lua}]
63+
# optional space/tab
64+
indent_style = space
65+
[{indent_style-eq-tab.lua}]
66+
# optional space/tab
67+
indent_style = tab
68+
align_table_field_to_first_field = true
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
local t = function()
2+
local a = 131
3+
local b = function()
4+
local c = {
5+
d = function()
6+
local e = 13
7+
local f = print {
8+
{
9+
{
10+
{
11+
{
12+
{
13+
(function(a1, a2, a3, a4, a5, a6)
14+
return {
15+
[function()
16+
aaa, bbb, ccc = 1, 2, 3
17+
18+
return aa, bb, cc, dd, ee
19+
end] = {
20+
gggg
21+
}
22+
}
23+
end)(1, 2, 3, 4, 5, 6)
24+
}
25+
}
26+
}
27+
}
28+
}
29+
}
30+
end
31+
}
32+
end
33+
end
34+
function ff()
35+
if aaa and bbbb then
36+
function dddd(aaa,
37+
bbbb,cccc,ddd)
38+
end
39+
end
40+
end
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
local t = {
2+
(function(a1, a2, a3, a4, a5, a6)
3+
return {
4+
[function()
5+
aaa, bbb, ccc = 1, 2, 3
6+
7+
return aa, bb, cc, dd, ee
8+
end] = {
9+
gggg
10+
}
11+
}
12+
end)(1, 2, 3, 4, 5, 6)
13+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
local t = function()
2+
local a = 131
3+
local b = function()
4+
local c = {
5+
d = function()
6+
local e = 13
7+
local f = print {
8+
{
9+
{
10+
{
11+
{
12+
{
13+
(function(a1, a2, a3, a4, a5, a6)
14+
return {
15+
[function()
16+
aaa, bbb, ccc = 1, 2, 3
17+
18+
return aa, bb, cc, dd, ee
19+
end] = {
20+
gggg
21+
}
22+
}
23+
end)(1, 2, 3, 4, 5, 6)
24+
}
25+
}
26+
}
27+
}
28+
}
29+
}
30+
end
31+
}
32+
end
33+
end
34+
function ff()
35+
if aaa and bbbb then
36+
function dddd(aaa,
37+
bbbb, cccc, ddd)
38+
end
39+
end
40+
end

Test/test_script/format_text/wait_format_by_option_should_be/indent_style-eq-tab.lua

Whitespace-only changes.

0 commit comments

Comments
 (0)