Skip to content

Commit 962c7da

Browse files
committed
bugfix for runtime error:“error converting Lua nil to String (expected string or number)”
1 parent 336c986 commit 962c7da

File tree

3 files changed

+16
-14
lines changed

3 files changed

+16
-14
lines changed

autoload/easycomplete.vim

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1923,7 +1923,6 @@ function! easycomplete#StoreCompleteSourceItems(plugin_name, result)
19231923
if g:env_is_nvim
19241924
let norm_menu_list = s:util_toolkit.final_normalize_menulist(a:result, a:plugin_name)
19251925
else
1926-
" TODO here 这里在nvim中报错,需要再测试
19271926
let norm_menu_list = s:FinalNormalizeMenulist(a:result, a:plugin_name)
19281927
endif
19291928
" call s:console(a:plugin_name, reltimestr(reltime(tt)))

lua/easycomplete/lib/speed.rs

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -654,24 +654,27 @@ fn final_normalize_menulist(lua: &Lua,
654654

655655
if cloned_plugin_name == "ts" {
656656
// 把ts里的user_data原有的字段存到r_user_data里
657-
let user_data_string: String = item.get("user_data")?;
658-
if !user_data_string.is_empty() {
659-
match serde_json::from_str::<serde_json::Value>(&user_data_string) {
660-
Ok(user_data_json_value) => {
661-
if let serde_json::Value::Object(map) = user_data_json_value {
662-
for (key, value) in map.iter() {
663-
// 使用mlua的序列化功能将serde_json::Value转换为Lua值
664-
let lua_value: mlua::Value = lua.to_value(value)?;
665-
r_user_data.set(&**key, lua_value)?;
657+
let user_data_value: mlua::Value = item.get("user_data")?;
658+
if let mlua::Value::String(user_data_str) = user_data_value {
659+
let user_data_string = user_data_str.to_str()?;
660+
if !user_data_string.is_empty() {
661+
// 原有处理逻辑
662+
match serde_json::from_str::<serde_json::Value>(&user_data_string) {
663+
Ok(user_data_json_value) => {
664+
// console(&user_data_json_value);
665+
if let serde_json::Value::Object(map) = user_data_json_value {
666+
for (key, value) in map.iter() {
667+
let lua_value: mlua::Value = lua.to_value(value)?;
668+
r_user_data.set(&**key, lua_value)?;
669+
}
666670
}
667671
}
668-
}
669-
Err(_) => {
670-
// 如果JSON解析失败,可以选择记录日志或忽略错误
672+
Err(_) => {
673+
// 如果JSON解析失败,可以选择记录日志或忽略错误
674+
}
671675
}
672676
}
673677
}
674-
675678
}
676679

677680
r_user_data.set("plugin_name", cloned_plugin_name)?;
160 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)