Skip to content

Commit f616e90

Browse files
committed
修复从lua读取的bug
1 parent b6989e9 commit f616e90

File tree

3 files changed

+33
-33
lines changed

3 files changed

+33
-33
lines changed

CodeFormatLib/src/CodeFormatLib.cpp

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -219,9 +219,9 @@ int type_format(lua_State *L) {
219219
}
220220
}
221221
auto typeFormatResult = LuaCodeFormat::GetInstance()
222-
.TypeFormat(filename,
223-
static_cast<std::size_t>(line), static_cast<std::size_t>(character),
224-
std::move(text), configMap, stringTypeOptions);
222+
.TypeFormat(filename,
223+
static_cast<std::size_t>(line), static_cast<std::size_t>(character),
224+
std::move(text), configMap, stringTypeOptions);
225225

226226
if (typeFormatResult.Type == ResultType::Err) {
227227
lua_pushboolean(L, false);
@@ -576,37 +576,37 @@ int spell_analysis(lua_State *L) {
576576
return 0;
577577
}
578578

579-
InfoNode CreateFromLua(InfoTree &t, lua_State *L, int idx) {
580-
if (lua_istable(L, idx)) {
579+
InfoNode CreateFromLua(InfoTree &t, lua_State *L) {
580+
if (lua_istable(L, -1)) {
581581
// lua 不区分 数组和table, 太难了
582-
auto len = luaL_len(L, idx);
582+
auto len = luaL_len(L, -1);
583583
if (len != 0) {
584584
auto arr = t.CreateArray();
585585
for (auto i = 0; i < len; i++) {
586-
if (lua_geti(L, idx, i)) {
587-
arr.AddChild(CreateFromLua(t, L, -1));
586+
if (lua_geti(L, -1, i)) {
587+
arr.AddChild(CreateFromLua(t, L));
588588
}
589589
lua_pop(L, 1);
590590
}
591591
return arr;
592592
} else {
593593
auto object = t.CreateObject();
594594
lua_pushnil(L);
595-
while (lua_next(L, idx) != 0) {
595+
while (lua_next(L, -2) != 0) {
596596
if (lua_isstring(L, -2)) {
597597
auto key = luaToString(L, -2);
598-
object.AddChild(key, CreateFromLua(t, L, -1));
598+
object.AddChild(key, CreateFromLua(t, L));
599599
}
600600
lua_pop(L, 1);
601601
}
602602
return object;
603603
}
604-
} else if (lua_isnumber(L, idx)) {
605-
return t.CreateNumber(lua_tonumber(L, idx));
606-
} else if (lua_isstring(L, idx)) {
607-
return t.CreateString(lua_tostring(L, idx));
608-
} else if (lua_isboolean(L, idx)) {
609-
return t.CreateBool(lua_toboolean(L, idx));
604+
} else if (lua_isnumber(L, -1)) {
605+
return t.CreateNumber(lua_tonumber(L, -1));
606+
} else if (lua_isstring(L, -1)) {
607+
return t.CreateString(lua_tostring(L, -1));
608+
} else if (lua_isboolean(L, -1)) {
609+
return t.CreateBool(lua_toboolean(L, -1));
610610
} else {
611611
return t.CreateNone();
612612
}
@@ -627,7 +627,7 @@ int update_name_style_config(lua_State *L) {
627627
while (lua_next(L, -2) != 0) {
628628
if (lua_isstring(L, -2)) {
629629
auto key = luaToString(L, -2);
630-
root.AddChild(key, CreateFromLua(tree, L, -1));
630+
root.AddChild(key, CreateFromLua(tree, L));
631631
}
632632
lua_pop(L, 1);
633633
}
@@ -719,20 +719,20 @@ int spell_suggest(lua_State *L) {
719719
}
720720

721721
static const luaL_Reg lib[] = {
722-
{"format", format},
723-
{"range_format", range_format},
724-
{"type_format", type_format},
725-
{"update_config", update_config},
726-
{"diagnose_file", diagnose_file},
727-
{"set_default_config", set_default_config},
728-
{"spell_load_dictionary_from_path", spell_load_dictionary_from_path},
722+
{"format", format },
723+
{"range_format", range_format },
724+
{"type_format", type_format },
725+
{"update_config", update_config },
726+
{"diagnose_file", diagnose_file },
727+
{"set_default_config", set_default_config },
728+
{"spell_load_dictionary_from_path", spell_load_dictionary_from_path },
729729
{"spell_load_dictionary_from_buffer", spell_load_dictionary_from_buffer},
730-
{"spell_analysis", spell_analysis},
731-
{"spell_suggest", spell_suggest},
732-
{"set_nonstandard_symbol", set_nonstandard_symbol},
733-
{"name_style_analysis", name_style_analysis},
734-
{"update_name_style_config", update_name_style_config},
735-
{nullptr, nullptr}
730+
{"spell_analysis", spell_analysis },
731+
{"spell_suggest", spell_suggest },
732+
{"set_nonstandard_symbol", set_nonstandard_symbol },
733+
{"name_style_analysis", name_style_analysis },
734+
{"update_name_style_config", update_name_style_config },
735+
{nullptr, nullptr }
736736
};
737737

738738
extern "C" EXPORT int luaopen_code_format(lua_State *L) {

CodeService/src/Diagnostic/NameStyle/NameStyleChecker.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -466,10 +466,10 @@ std::string NameStyleChecker::MakeDiagnosticInfo(std::string_view ruleName, LuaS
466466
break;
467467
}
468468
default: {
469-
break;
469+
continue;
470470
}
471471
}
472-
if (index != rules.size() - 1) {
472+
if (index + 1 < rules.size()) {
473473
ruleMessage.append(" | ");
474474
}
475475
}

CodeService/src/Diagnostic/NameStyle/NameStyleRuleMatcher.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ bool NameStyleRuleMatcher::Match(LuaSyntaxNode &n, const LuaSyntaxTree &t, const
66
if (rules.empty()) {
77
return true;
88
}
9-
9+
1010
for (auto &rule: rules) {
1111
auto text = n.GetText(t);
1212
switch (rule.Type) {

0 commit comments

Comments
 (0)