Skip to content

Commit 0e21e3c

Browse files
committed
resolve #15
1 parent 79644a0 commit 0e21e3c

17 files changed

+102
-145
lines changed

CodeService/src/FormatElement/AlignmentLayoutElement.cpp

Lines changed: 59 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,14 @@ void AlignmentLayoutElement::Diagnosis(DiagnosisContext& ctx, ChildIterator self
5959
int AlignmentLayoutElement::GetAlignPosition(FormatContext& ctx)
6060
{
6161
auto indentState = ctx.GetCurrentIndent();
62-
int alignOffset = 0;
63-
64-
if (!ctx.GetOptions().weak_alignment_rule)
65-
{
66-
alignOffset = GetAlignOffset(ctx);
67-
}
68-
else
69-
{
70-
alignOffset = GetAlignOffsetWithWeakRule(ctx);
71-
}
62+
// if (!ctx.GetOptions().weak_alignment_rule)
63+
// {
64+
// alignOffset = GetAlignOffset(ctx);
65+
// }
66+
// else
67+
// {
68+
int alignOffset = GetAlignOffsetWithWeakRule(ctx);
69+
// }
7270

7371
if (alignOffset == -1)
7472
{
@@ -78,55 +76,55 @@ int AlignmentLayoutElement::GetAlignPosition(FormatContext& ctx)
7876
return alignOffset + static_cast<int>(indentState.SpaceIndent + indentState.TabIndent);
7977
}
8078

81-
int AlignmentLayoutElement::GetAlignOffset(FormatContext& ctx)
82-
{
83-
int alignSignOffset = 0;
84-
bool firstContainAlignSign = true;
85-
// 先寻找等号对齐的位置,并且判断连续的带等号的语句是否应该对齐到等号
86-
// 连续的带等号的语句是否应该对齐到等号,这个行为应该由连续语句的首行决定
87-
// 如果被子节点内的其他语句共同决定则很难将连续对齐还原为普通排版
88-
for (auto statIt = _children.begin(); statIt != _children.end(); ++statIt)
89-
{
90-
const auto statement = *statIt;
91-
92-
auto& statementChildren = statement->GetChildren();
93-
94-
for (auto it = statementChildren.begin(); it != statementChildren.end(); ++it)
95-
{
96-
auto textChild = *it;
97-
if (textChild->GetType() == FormatElementType::TextElement)
98-
{
99-
const auto textElement = std::dynamic_pointer_cast<TextElement>(textChild);
100-
if (textElement->GetText() == _alignSign)
101-
{
102-
const auto signPosition = ctx.GetColumn(textElement->GetTextRange().StartOffset);
103-
if (firstContainAlignSign && it != statementChildren.begin())
104-
{
105-
firstContainAlignSign = false;
106-
auto lastStatChild = FindLastValidChild(it, statementChildren);
107-
if (lastStatChild == nullptr)
108-
{
109-
return -1;
110-
}
111-
112-
const auto lastPosition = ctx.GetColumn(lastStatChild->GetTextRange().EndOffset);
113-
114-
if (signPosition - lastPosition <= 2)
115-
{
116-
return -1;
117-
}
118-
}
119-
120-
121-
alignSignOffset = std::max(alignSignOffset,
122-
signPosition - ctx.GetColumn(statement->GetTextRange().StartOffset)
123-
);
124-
}
125-
}
126-
}
127-
}
128-
return alignSignOffset;
129-
}
79+
// int AlignmentLayoutElement::GetAlignOffset(FormatContext& ctx)
80+
// {
81+
// int alignSignOffset = 0;
82+
// bool firstContainAlignSign = true;
83+
// // 先寻找等号对齐的位置,并且判断连续的带等号的语句是否应该对齐到等号
84+
// // 连续的带等号的语句是否应该对齐到等号,这个行为应该由连续语句的首行决定
85+
// // 如果被子节点内的其他语句共同决定则很难将连续对齐还原为普通排版
86+
// for (auto statIt = _children.begin(); statIt != _children.end(); ++statIt)
87+
// {
88+
// const auto statement = *statIt;
89+
//
90+
// auto& statementChildren = statement->GetChildren();
91+
//
92+
// for (auto it = statementChildren.begin(); it != statementChildren.end(); ++it)
93+
// {
94+
// auto textChild = *it;
95+
// if (textChild->GetType() == FormatElementType::TextElement)
96+
// {
97+
// const auto textElement = std::dynamic_pointer_cast<TextElement>(textChild);
98+
// if (textElement->GetText() == _alignSign)
99+
// {
100+
// const auto signPosition = ctx.GetColumn(textElement->GetTextRange().StartOffset);
101+
// if (firstContainAlignSign && it != statementChildren.begin())
102+
// {
103+
// firstContainAlignSign = false;
104+
// auto lastStatChild = FindLastValidChild(it, statementChildren);
105+
// if (lastStatChild == nullptr)
106+
// {
107+
// return -1;
108+
// }
109+
//
110+
// const auto lastPosition = ctx.GetColumn(lastStatChild->GetTextRange().EndOffset);
111+
//
112+
// if (signPosition - lastPosition <= 2)
113+
// {
114+
// return -1;
115+
// }
116+
// }
117+
//
118+
//
119+
// alignSignOffset = std::max(alignSignOffset,
120+
// signPosition - ctx.GetColumn(statement->GetTextRange().StartOffset)
121+
// );
122+
// }
123+
// }
124+
// }
125+
// }
126+
// return alignSignOffset;
127+
// }
130128

131129
int AlignmentLayoutElement::GetAlignOffsetWithWeakRule(FormatContext& ctx)
132130
{
@@ -162,9 +160,9 @@ int AlignmentLayoutElement::GetAlignOffsetWithWeakRule(FormatContext& ctx)
162160
{
163161
canAlignToSign = true;
164162
}
165-
163+
// 采用最小对齐原则
166164
alignSignOffset = std::max(alignSignOffset,
167-
signPosition - ctx.GetColumn(statement->GetTextRange().StartOffset)
165+
lastPosition + 2 - ctx.GetColumn(statement->GetTextRange().StartOffset)
168166
);
169167
}
170168
}

CodeService/src/LuaEditorConfig.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -266,12 +266,6 @@ void LuaEditorConfig::ParseFromSection(std::shared_ptr<LuaCodeStyleOptions> opti
266266
std::stoi(configMap.at("max_continuous_line_distance"));
267267
}
268268

269-
if(configMap.count("weak_alignment_rule"))
270-
{
271-
options->weak_alignment_rule =
272-
configMap.at("weak_alignment_rule") == "true";
273-
}
274-
275269
if (configMap.count("continuous_assign_statement_align_to_equal_sign"))
276270
{
277271
options->continuous_assign_statement_align_to_equal_sign =

Test/test_script/format_text/wait_format_by_option/.editorconfig

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,6 @@ do_statement_no_indent = true
140140
if_condition_no_continuation_indent = true
141141
[{max_continuous_line_distance-eq-2.lua}]
142142
max_continuous_line_distance = 2
143-
[{weak_alignment_rule-eq-true.lua}]
144-
weak_alignment_rule = true
145143
[{table_append_expression_no_space-eq-true.lua}]
146144
table_append_expression_no_space = true
147145
[{if_condition_align_with_each_other-eq-true.lua}]

Test/test_script/format_text/wait_format_by_option/weak_alignment_rule-eq-true.lua

Lines changed: 0 additions & 9 deletions
This file was deleted.

Test/test_script/format_text/wait_format_by_option_should_be/.editorconfig

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,6 @@ do_statement_no_indent = true
135135
if_condition_no_continuation_indent = true
136136
[{max_continuous_line_distance-eq-2.lua}]
137137
max_continuous_line_distance = 2
138-
[{weak_alignment_rule-eq-true.lua}]
139-
weak_alignment_rule = true
140138
[{table_append_expression_no_space-eq-true.lua}]
141139
table_append_expression_no_space = true
142140
[{if_condition_align_with_each_other-eq-true.lua}]

Test/test_script/format_text/wait_format_by_option_should_be/continuous_assign_statement_align_to_equal_sign-eq-true.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ local h4 = {
3232
aaa, bbb, ccc, ddd, eee
3333
}
3434

35-
local h1 = {}
35+
local h1 = {}
3636
local h222222222 = {}
37-
local h3 = {}
38-
local h4 = {
37+
local h3 = {}
38+
local h4 = {
3939
aaa, bbb, ccc, ddd, eee
4040
}
4141

Test/test_script/format_text/wait_format_by_option_should_be/continuous_assign_table_field_align_to_equal_sign-eq-true.lua

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ local t4 = {
1919
}
2020

2121
local t5 = {
22-
aaaa = 123131,
23-
bbbbb = 1231313131,
22+
aaaa = 123131,
23+
bbbbb = 1231313131,
2424
}
2525

2626
local t6 = {
@@ -29,9 +29,9 @@ local t6 = {
2929
}
3030

3131
local t7 = {
32-
aaaaa = 12313,
33-
ccccc = 1231,
34-
ddddd = 12313131,
35-
hhhh = 12313131,
32+
aaaaa = 12313,
33+
ccccc = 1231,
34+
ddddd = 12313131,
35+
hhhh = 12313131,
3636

3737
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
local t = 1
2-
local t2 = 123
1+
local t = 1
2+
local t2 = 123
33

4-
local t3 = 123
4+
local t3 = 123
55

66

77
local t4 = 123

Test/test_script/format_text/wait_format_by_option_should_be/weak_alignment_rule-eq-true.lua

Lines changed: 0 additions & 9 deletions
This file was deleted.

Test/test_script/format_text/wait_format_should_be/table.lua

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,15 @@ local t8 = {
4545
}
4646

4747
local t9 = {
48-
jfwejgwojgow--[[wkngowjgw]] = 123131,
49-
joiwejgjwgw = 13131,
50-
fwhoifwjofgjw = 353,
51-
ljeogjeprjgpege = 13131,
48+
jfwejgwojgow--[[wkngowjgw]] = 123131,
49+
joiwejgjwgw = 13131,
50+
fwhoifwjofgjw = 353,
51+
ljeogjeprjgpege = 13131,
5252
}
5353

5454
local t10 = {
55-
aaa = 123131,
56-
bb = 123131,
55+
aaa = 123131,
56+
bb = 123131,
5757

5858
dd = 1313131,
5959
ee = 12313131,

0 commit comments

Comments
 (0)