Skip to content

Commit 3fefe6e

Browse files
committed
fix typeformat 吃掉东西的bug
1 parent 05566b0 commit 3fefe6e

File tree

3 files changed

+22
-7
lines changed

3 files changed

+22
-7
lines changed

CodeService/src/TypeFormat/LuaTypeFormat.cpp

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -160,12 +160,12 @@ void LuaTypeFormat::AnalysisReturn(int line, int character)
160160

161161
if (_typeOptions.format_line)
162162
{
163-
FormatLine(line);
163+
FormatLine(line, character);
164164
}
165165

166-
if (_typeOptions.fix_indent) {
167-
FixIndent(line, character);
168-
}
166+
// if (_typeOptions.fix_indent) {
167+
// FixIndent(line, character);
168+
// }
169169
}
170170

171171
void LuaTypeFormat::CompleteMissToken(int line, int character, LuaError& luaError)
@@ -280,8 +280,21 @@ void LuaTypeFormat::CompleteMissToken(int line, int character, LuaError& luaErro
280280
}
281281
}
282282

283-
void LuaTypeFormat::FormatLine(int line)
283+
void LuaTypeFormat::FormatLine(int line, int character)
284284
{
285+
auto luaFile = _parser->GetLuaFile();
286+
auto offset = luaFile->GetOffsetFromPosition(line, character);
287+
auto& tokens = _parser->GetTokenParser()->GetTokens();
288+
auto tokenIndex = FindTokenIndexAfterPosition(tokens, offset);
289+
if (tokenIndex != -1)
290+
{
291+
auto& token = tokens[tokenIndex];
292+
if (token.TokenType == TK_STRING || token.TokenType == TK_LONG_COMMENT)
293+
{
294+
return;
295+
}
296+
}
297+
285298
LuaCodeStyleOptions temp = _options;
286299
temp.insert_final_newline = true;
287300
temp.remove_expression_list_finish_comma = false;
@@ -326,7 +339,7 @@ void LuaTypeFormat::FormatLine(int line)
326339

327340
void LuaTypeFormat::FixIndent(int line, int character)
328341
{
329-
// FixEndIndent(line, character);
342+
FixEndIndent(line, character);
330343

331344
// auto root = _parser->GetAst();
332345
// auto astNode = FindAstNodeBeforePosition(root, offset);

include/CodeService/TypeFormat/LuaTypeFormat.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class LuaTypeFormat
2727
private:
2828
void AnalysisReturn(int line, int character);
2929
void CompleteMissToken(int line, int character, LuaError& luaError);
30-
void FormatLine(int line);
30+
void FormatLine(int line, int character);
3131
void FixIndent(int line, int character);
3232

3333
void FixEndIndent(int line, int character);
@@ -38,3 +38,4 @@ class LuaTypeFormat
3838
bool _hasResult;
3939
std::vector<Result> _results;
4040
};
41+

include/CodeService/TypeFormat/LuaTypeFormatOptions.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ class LuaTypeFormatOptions
1313
bool auto_complete_table_sep = true;
1414
bool fix_indent = true;
1515
};
16+

0 commit comments

Comments
 (0)