Skip to content

Commit c6a53c7

Browse files
committed
[bugfix] item.user_data !== item.user_data_json when plugin_name ==
"ts"
1 parent 2f871d1 commit c6a53c7

File tree

4 files changed

+29
-2
lines changed

4 files changed

+29
-2
lines changed

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lua/easycomplete/lib/speed.lua

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,16 @@ function speed.final_normalize_menulist(arr, plugin_name)
1919
for _, item in ipairs(arr) do
2020
-- 这里item会转换为"table: 0x0109a29a00",base64后无需截短
2121
local sha256_str = vim.base64.encode(tostring(item))
22-
local r_user_data = {
22+
local r_user_data = {}
23+
local t_user_data = {
2324
plugin_name = plugin_name,
2425
sha256 = sha256_str
2526
}
27+
if plugin_name == "ts" and item.user_data ~= nil then
28+
r_user_data = vim.fn.extend(vim.fn.json_decode(item.user_data), t_user_data)
29+
else
30+
r_user_data = t_user_data
31+
end
2632
table.insert(l_menu_list, vim.fn.extend({
2733
word = '',
2834
menu = '',

lua/easycomplete/lib/speed.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -652,6 +652,28 @@ fn final_normalize_menulist(lua: &Lua,
652652

653653
let r_user_data: LuaTable = lua.create_table()?;
654654

655+
if cloned_plugin_name == "ts" {
656+
// 把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)?;
666+
}
667+
}
668+
}
669+
Err(_) => {
670+
// 如果JSON解析失败,可以选择记录日志或忽略错误
671+
}
672+
}
673+
}
674+
675+
}
676+
655677
r_user_data.set("plugin_name", cloned_plugin_name)?;
656678
r_user_data.set("sha256", sha256_str)?;
657679

14.3 KB
Binary file not shown.

0 commit comments

Comments
 (0)