Skip to content

Commit ec0311b

Browse files
committed
typeformat支持自动填补表的逗号
1 parent 763d15e commit ec0311b

File tree

6 files changed

+34
-12
lines changed

6 files changed

+34
-12
lines changed

CodeService/src/FormatElement/SepElement.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
#include "CodeService/FormatElement/SepElement.h"
22

3+
4+
std::shared_ptr<SepElement> SepElement::After(std::shared_ptr<FormatElement> node)
5+
{
6+
auto sep = std::make_shared<SepElement>();
7+
sep->_textRange = TextRange(node->GetTextRange().EndOffset, node->GetTextRange().EndOffset);
8+
return sep;
9+
}
10+
311
SepElement::SepElement()
412
: TextElement(""),
513
_empty(false)

CodeService/src/LuaFormatter.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2058,8 +2058,7 @@ std::shared_ptr<FormatElement> LuaFormatter::FormatAlignTableField(LuaAstNode::C
20582058
{
20592059
if (!sep)
20602060
{
2061-
sep = std::make_shared<SepElement>();
2062-
layoutChildren.insert(rIt.base(), sep);
2061+
layoutChildren.insert(rIt.base(), SepElement::After((*rIt)));
20632062
}
20642063

20652064
break;
@@ -2077,8 +2076,7 @@ std::shared_ptr<FormatElement> LuaFormatter::FormatAlignTableField(LuaAstNode::C
20772076
}
20782077
else if (!sep)
20792078
{
2080-
sep = std::make_shared<SepElement>();
2081-
layoutChildren.insert(rIt.base(), sep);
2079+
layoutChildren.insert(rIt.base(), SepElement::After((*rIt)));
20822080
}
20832081

20842082
break;

CodeService/src/TypeFormat/LuaTypeFormat.cpp

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,17 @@ void LuaTypeFormat::AnalysisReturn(int line, int character)
8181
return;
8282
}
8383

84-
FormatLine(line);
84+
if (_typeOptions.format_line)
85+
{
86+
FormatLine(line);
87+
}
88+
89+
8590
}
8691

8792
void LuaTypeFormat::CompleteMissToken(int line, int character, LuaError& luaError)
8893
{
89-
if(!_typeOptions.auto_complete_end)
94+
if (!_typeOptions.auto_complete_end)
9095
{
9196
return;
9297
}
@@ -197,15 +202,18 @@ void LuaTypeFormat::CompleteMissToken(int line, int character, LuaError& luaErro
197202

198203
void LuaTypeFormat::FormatLine(int line)
199204
{
200-
if(!_typeOptions.format_line)
201-
{
202-
return;
203-
}
204-
205205
LuaCodeStyleOptions temp = _options;
206206
temp.insert_final_newline = true;
207207
temp.remove_expression_list_finish_comma = false;
208-
temp.trailing_table_separator = TrailingTableSeparator::Keep;
208+
if (_typeOptions.auto_complete_table_sep)
209+
{
210+
temp.trailing_table_separator = TrailingTableSeparator::Smart;
211+
}
212+
else
213+
{
214+
temp.trailing_table_separator = TrailingTableSeparator::Keep;
215+
}
216+
209217
LuaFormatter formatter(_parser, temp);
210218
formatter.BuildFormattedElement();
211219

CodeService/src/TypeFormat/LuaTypeFormatOptions.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,10 @@ LuaTypeFormatOptions LuaTypeFormatOptions::ParseFrom(std::map<std::string, std::
1414
options.format_line = stringOptions["format_line"] == "true";
1515
}
1616

17+
if(stringOptions.count("auto_complete_table_sep"))
18+
{
19+
options.auto_complete_table_sep = stringOptions["auto_complete_table_sep"] == "true";
20+
}
21+
1722
return options;
1823
}

include/CodeService/FormatElement/SepElement.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
class SepElement : public TextElement
66
{
77
public:
8+
static std::shared_ptr<SepElement> After(std::shared_ptr<FormatElement> node);
9+
810
SepElement();
911

1012
explicit SepElement(std::shared_ptr<LuaAstNode> node);

include/CodeService/TypeFormat/LuaTypeFormatOptions.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ class LuaTypeFormatOptions
1010

1111
bool format_line = true;
1212
bool auto_complete_end = true;
13+
bool auto_complete_table_sep = true;
1314
};

0 commit comments

Comments
 (0)