Skip to content

Commit 780f389

Browse files
committed
修复typeformat体验
1 parent 4478869 commit 780f389

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

CodeService/src/LuaTypeFormat.cpp

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include <algorithm>
33
#include "LuaParser/LuaTokenTypeDetail.h"
44
#include "CodeService/FormatElement/SerializeContext.h"
5+
#include "Util/StringUtil.h"
56

67
int FindTokenIndexBeforePosition(std::vector<LuaToken>& tokens, int offset)
78
{
@@ -26,7 +27,6 @@ int FindTokenIndexBeforePosition(std::vector<LuaToken>& tokens, int offset)
2627
return static_cast<int>(pos - tokens.begin()) - 1;
2728
}
2829

29-
3030
LuaTypeFormat::LuaTypeFormat(std::shared_ptr<LuaParser> luaParser, LuaCodeStyleOptions& options)
3131
: _parser(luaParser),
3232
_options(options),
@@ -199,7 +199,24 @@ void LuaTypeFormat::FormatLine(int line)
199199
_result.Range.StartCharacter = 0;
200200
_result.Range.EndLine = line - 1;
201201
_result.Range.EndCharacter = 0;
202-
_result.Text = formatter.GetRangeFormattedText(_result.Range);
202+
auto formatText = formatter.GetRangeFormattedText(_result.Range);
203+
while (!formatText.empty())
204+
{
205+
char ch = formatText.back();
206+
if (ch == ' ')
207+
{
208+
formatText.pop_back();
209+
}
210+
else
211+
{
212+
break;
213+
}
214+
}
215+
if(!formatText.empty() && formatText.back() != '\n')
216+
{
217+
formatText.push_back('\n');
218+
}
219+
_result.Text = formatText;
203220
_result.Range.EndLine++;
204221
_hasResult = true;
205222
}

0 commit comments

Comments
 (0)