Skip to content

Commit 29a69ce

Browse files
committed
FIX #35
1 parent 3a63d3e commit 29a69ce

File tree

7 files changed

+45
-13
lines changed

7 files changed

+45
-13
lines changed

CodeService/src/FormatElement/KeepElement.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
#include "CodeService/FormatElement/KeepElement.h"
22
#include "Util/format.h"
33

4-
KeepElement::KeepElement(int keepBlank, bool hasLinebreak)
4+
KeepElement::KeepElement(int keepBlank, bool hasLinebreak, bool allowContinueIndent)
55
: _keepBlank(keepBlank),
6-
_hasLinebreak(hasLinebreak)
6+
_hasLinebreak(hasLinebreak),
7+
_allowContinueIndent(allowContinueIndent)
78
{
89
}
910

@@ -15,7 +16,6 @@ FormatElementType KeepElement::GetType()
1516
void KeepElement::Serialize(SerializeContext& ctx, ChildIterator selfIt,
1617
FormatElement& parent)
1718
{
18-
1919
const int lastElementLine = GetLastValidLine(ctx, selfIt, parent);
2020
const int nextElementLine = GetNextValidLine(ctx, selfIt, parent);
2121

@@ -43,8 +43,7 @@ void KeepElement::Serialize(SerializeContext& ctx, ChildIterator selfIt,
4343
void KeepElement::Diagnosis(DiagnosisContext& ctx, ChildIterator selfIt,
4444
FormatElement& parent)
4545
{
46-
47-
if(selfIt == parent.GetChildren().begin())
46+
if (selfIt == parent.GetChildren().begin())
4847
{
4948
return;
5049
}

CodeService/src/FormatElement/LongExpressionLayoutElement.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ void LongExpressionLayoutElement::SerializeSubExpression(SerializeContext& ctx,
4747
}
4848
if (child->Is(FormatElementType::KeepElement))
4949
{
50-
if (ctx.GetCharacterCount() == 0 && !_hasContinuation)
50+
auto keepElement = std::dynamic_pointer_cast<KeepElement>(child);
51+
if (keepElement->AllowContinueIndent() && ctx.GetCharacterCount() == 0 && !_hasContinuation)
5152
{
5253
IndentSubExpression(ctx);
5354
}

CodeService/src/LuaFormatter.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2219,16 +2219,17 @@ std::shared_ptr<FormatElement> LuaFormatter::FormatCallExpression(std::shared_pt
22192219
{
22202220
if (!ast_util::WillCallArgHaveParentheses(next, _options.call_arg_parentheses))
22212221
{
2222-
env->Add<KeepElement>(1);
2222+
//TODO workaround
2223+
env->Add<KeepElement>(1, false, false);
22232224
}
22242225
else
22252226
{
2226-
env->Add<KeepElement>(0);
2227+
env->Add<KeepElement>(0, false, false);
22272228
}
22282229
}
22292230
else
22302231
{
2231-
env->Add<KeepElement>(1);
2232+
env->Add<KeepElement>(1, false, false);
22322233
}
22332234

22342235
break;
@@ -2256,7 +2257,7 @@ std::shared_ptr<FormatElement> LuaFormatter::FormatCallExpression(std::shared_pt
22562257
needSpace = false;
22572258
}
22582259

2259-
env->Add<KeepElement>(needSpace ? 1 : 0);
2260+
env->Add<KeepElement>(needSpace ? 1 : 0, false, !nextCallArgList);
22602261

22612262
break;
22622263
}

Test/test_script/format_text/wait_format/expression.lua

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,17 @@ call(
4141
aaaa),
4242
call(aaa,bbbb,ccc)
4343
)
44+
TEST
45+
[[
46+
47+
]]
48+
[[
49+
50+
]]
51+
local t = TEST
52+
[[
53+
54+
]]
55+
[[
56+
57+
]]

Test/test_script/format_text/wait_format_should_be/expression.lua

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ function f()
3131
local c = { aaa, 13131, 2424242 }
3232
local ddd = call { aaaa, bbb, ccc }
3333
local eee = calll
34-
{ 12313, 35353, fff }
34+
{ 12313, 35353, fff }
3535
local fff = function() end
3636
dd.e().e().aaa = 1231
3737
end
@@ -41,3 +41,17 @@ call(
4141
aaaa),
4242
call(aaa, bbbb, ccc)
4343
)
44+
TEST
45+
[[
46+
47+
]]
48+
[[
49+
50+
]]
51+
local t = TEST
52+
[[
53+
54+
]]
55+
[[
56+
57+
]]

include/CodeService/FormatElement/KeepElement.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,21 @@
55
class KeepElement : public FormatElement
66
{
77
public:
8+
89
/*
910
* @param keepBlank 表示如果下一个元素和当前元素在同一行则保持几个空格
1011
* @remark 如果下一个元素和当前元素在不同行则换行
1112
*/
12-
explicit KeepElement(int keepBlank, bool hasLinebreak = false);
13+
explicit KeepElement(int keepBlank, bool hasLinebreak = false, bool allowContinueIndent = true);
1314

1415
FormatElementType GetType() override;
1516

17+
bool AllowContinueIndent() const { return _allowContinueIndent; }
18+
1619
void Serialize(SerializeContext& ctx, ChildIterator selfIt, FormatElement& parent) override;
1720
void Diagnosis(DiagnosisContext& ctx, ChildIterator selfIt, FormatElement& parent) override;
1821
private:
1922
int _keepBlank;
2023
bool _hasLinebreak;
24+
bool _allowContinueIndent;
2125
};

include/CodeService/LuaFormatter.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#include "LuaParser/LuaParser.h"
55
#include "LuaCodeStyleOptions.h"
66
#include "FormatElement/FormatElement.h"
7-
#include "FormatElement/PlaceholderElement.h"
87
#include "LuaDiagnosisInfo.h"
98
#include "LuaFormatRange.h"
109

0 commit comments

Comments
 (0)