Skip to content

Commit c26c99f

Browse files
committed
上传代码
1 parent a15fc43 commit c26c99f

File tree

8 files changed

+95
-5
lines changed

8 files changed

+95
-5
lines changed

3rd/uriparser/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,3 @@ target_compile_definitions(uriparser PRIVATE URI_LIBRARY_BUILD)
9292

9393
target_compile_definitions(uriparser PUBLIC URI_STATIC_BUILD)
9494

95-
target_compile_definitions(uriparser PUBLIC URI_NO_UNICODE)

CodeService/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ target_sources(CodeService
5353
${CodeService_SOURCE_DIR}/src/FormatElement/AlignToFirstElement.cpp
5454
${CodeService_SOURCE_DIR}/src/FormatElement/IndentOnLineBreakElement.cpp
5555
${CodeService_SOURCE_DIR}/src/FormatElement/KeepElement.cpp
56+
${CodeService_SOURCE_DIR}/src/FormatElement/PlaceholderElement.cpp
5657
${CodeService_SOURCE_DIR}/src/FormatElement/SubExpressionElement.cpp
5758
${CodeService_SOURCE_DIR}/src/FormatElement/DiagnosisContext.cpp
5859
${CodeService_SOURCE_DIR}/src/FormatElement/RangeFormatContext.cpp
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#include "CodeService/FormatElement/PlaceholderElement.h"
2+
3+
PlaceholderElement::PlaceholderElement(std::shared_ptr<FormatElement> parent, std::shared_ptr<LuaAstNode> expression)
4+
: FormatElement(expression->GetTextRange()),
5+
_parent(parent),
6+
_expression(expression)
7+
{
8+
}
9+
10+
FormatElementType PlaceholderElement::GetType()
11+
{
12+
return FormatElementType::PlaceholderElement;
13+
}
14+
15+
std::shared_ptr<LuaAstNode> PlaceholderElement::GetRawAstNode()
16+
{
17+
return _expression;
18+
}
19+
20+
void PlaceholderElement::Replace(std::shared_ptr<FormatElement> layout)
21+
{
22+
if (!_parent.expired())
23+
{
24+
auto parent = _parent.lock();
25+
26+
auto& children = parent->GetChildren();
27+
for (auto& child : children)
28+
{
29+
if (child.get() == this)
30+
{
31+
child = layout;
32+
break;
33+
}
34+
}
35+
}
36+
}

CodeService/src/LuaFormatter.cpp

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "CodeService/FormatElement/NoIndentElement.h"
1818
#include "CodeService/FormatElement/SerializeContext.h"
1919
#include "CodeService/FormatElement/IndentOnLineBreakElement.h"
20+
#include "CodeService/FormatElement/PlaceHolderElement.h"
2021
#include "Util/StringUtil.h"
2122

2223
bool nextMatch(LuaAstNode::ChildIterator it, LuaAstNodeType type, const LuaAstNode::ChildrenContainer& container)
@@ -1029,6 +1030,9 @@ std::shared_ptr<FormatElement> LuaFormatter::FormatIfStatement(std::shared_ptr<L
10291030
{
10301031
auto env = std::make_shared<StatementElement>();
10311032
auto& children = ifStatement->GetChildren();
1033+
1034+
std::vector<std::shared_ptr<PlaceholderElement>> placeholderExpressions;
1035+
10321036
for (auto it = children.begin(); it != children.end(); ++it)
10331037
{
10341038
const auto child = *it;
@@ -1056,13 +1060,21 @@ std::shared_ptr<FormatElement> LuaFormatter::FormatIfStatement(std::shared_ptr<L
10561060
}
10571061
case LuaAstNodeType::Expression:
10581062
{
1059-
std::shared_ptr<FormatElement> expression = nullptr;
1060-
if (_options.if_condition_no_continuation_indent)
1063+
if (_options.if_condition_align_with_each_other)
10611064
{
1062-
expression = std::make_shared<LongExpressionLayoutElement>(0);
1065+
placeholderExpressions.push_back(std::make_shared<PlaceholderElement>(env, child));
1066+
env->AddChild(placeholderExpressions.back());
10631067
}
1068+
else
1069+
{
1070+
std::shared_ptr<FormatElement> expression = nullptr;
1071+
if (_options.if_condition_no_continuation_indent)
1072+
{
1073+
expression = std::make_shared<LongExpressionLayoutElement>(0);
1074+
}
10641075

1065-
env->AddChild(FormatExpression(child, expression));
1076+
env->AddChild(FormatExpression(child, expression));
1077+
}
10661078
env->Add<KeepBlankElement>(1);
10671079
break;
10681080
}
@@ -1074,6 +1086,11 @@ std::shared_ptr<FormatElement> LuaFormatter::FormatIfStatement(std::shared_ptr<L
10741086
}
10751087
}
10761088

1089+
if (!placeholderExpressions.empty())
1090+
{
1091+
FormatIfConditionAlign(placeholderExpressions);
1092+
}
1093+
10771094
return env;
10781095
}
10791096

@@ -2156,6 +2173,19 @@ std::shared_ptr<FormatElement> LuaFormatter::FormatTableAppendExpression(std::sh
21562173
return FormatExpression(expression, env);
21572174
}
21582175

2176+
void LuaFormatter::FormatIfConditionAlign(std::vector<std::shared_ptr<PlaceholderElement>>& placeholders)
2177+
{
2178+
bool canAlign = true;
2179+
for(auto placeholder: placeholders)
2180+
{
2181+
2182+
}
2183+
2184+
2185+
2186+
2187+
2188+
}
21592189

21602190
std::shared_ptr<FormatElement> LuaFormatter::FormatRangeBlock(std::shared_ptr<LuaAstNode> blockNode,
21612191
LuaFormatRange& validRange)

include/CodeService/FormatElement/FormatElementType.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ enum class FormatElementType
1414
LongExpressionLayoutElement,
1515
NoIndentElement,
1616
IndentOnLineBreakElement,
17+
PlaceholderElement,
1718

1819
ControlStart,
1920
KeepLineElement,
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#pragma once
2+
3+
#include "FormatElement.h"
4+
5+
class PlaceholderElement : public FormatElement
6+
{
7+
public:
8+
PlaceholderElement(std::shared_ptr<FormatElement> parent, std::shared_ptr<LuaAstNode> expression);
9+
10+
FormatElementType GetType() override;
11+
12+
std::shared_ptr<LuaAstNode> GetRawAstNode();
13+
14+
void Replace(std::shared_ptr<FormatElement> layout);
15+
private:
16+
std::weak_ptr<FormatElement> _parent;
17+
std::shared_ptr<LuaAstNode> _expression;
18+
};

include/CodeService/LuaCodeStyleOptions.h

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

106106
bool continuous_assign_table_field_align_to_equal_sign = true;
107107

108+
bool if_condition_align_with_each_other = false;
109+
108110
bool table_append_expression_no_space = false;
109111

110112
std::string end_of_line = "\r\n";

include/CodeService/LuaFormatter.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "LuaParser/LuaParser.h"
55
#include "LuaCodeStyleOptions.h"
66
#include "FormatElement/FormatElement.h"
7+
#include "FormatElement/PlaceHolderElement.h"
78
#include "LuaDiagnosisInfo.h"
89
#include "LuaFormatRange.h"
910

@@ -127,6 +128,8 @@ class LuaFormatter
127128

128129
// special rule [#8](https://github.com/CppCXY/EmmyLuaCodeStyle/issues/8)
129130
std::shared_ptr<FormatElement> FormatTableAppendExpression(std::shared_ptr<LuaAstNode> expression);
131+
132+
void FormatIfConditionAlign(std::vector<std::shared_ptr<PlaceholderElement>>& placeholders);
130133
// special handle range format
131134
std::shared_ptr<FormatElement> FormatRangeBlock(std::shared_ptr<LuaAstNode> blockNode, LuaFormatRange& validRange);
132135
private:

0 commit comments

Comments
 (0)