Skip to content

Commit 8591439

Browse files
committed
bugfix
1 parent 85c6ffe commit 8591439

File tree

2 files changed

+12
-16
lines changed

2 files changed

+12
-16
lines changed

lua/easycomplete/lib/speed.rs

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,7 @@ fn complete_menu_filter(
368368
fullmatch_result.raw_insert(1, item.clone());
369369
} else if item_word_lower.starts_with(&word_lower) {
370370
fullmatch_result.push(item.clone());
371+
// sumbline_fuzzy 排序结果已经考虑到首字母匹配靠前排序了,这里应该不是必须了
371372
// } else if item_word_lower.chars().next() == word_lower.chars().next() {
372373
// firstchar_result.push(item.clone());
373374
} else {
@@ -382,21 +383,18 @@ fn complete_menu_filter(
382383
let stunt_items: LuaTable = globals.get("easycomplete_stunt_menuitems")?;
383384
let stunt_items_len_i64: i64 = stunt_items.len()?;
384385
let stunt_items_len_i32: i32 = stunt_items_len_i64.try_into().unwrap();
385-
// 数字
386+
386387
let first_complete_hit: i32 = globals.get("easycomplete_first_complete_hit")?;
387388
let mut sorted_fuzzymatch_result: LuaTable;
388389
if stunt_items_len_i32 == 0 && first_complete_hit == 1 {
389390
sorted_fuzzymatch_result = sort_table_by_word_len(lua, fuzzymatch_result.clone())?;
390391
} else {
391392
sorted_fuzzymatch_result = fuzzymatch_result.clone();
392393
}
393-
// local filtered_menu = {}
394-
// for _, v in ipairs(fullmatch_result) do table.insert(filtered_menu, v) end
395-
// for _, v in ipairs(firstchar_result) do table.insert(filtered_menu, v) end
396-
// for _, v in ipairs(fuzzymatch_result) do table.insert(filtered_menu, v) end
397-
let mut tmp_items = Vec::new();
398394

399-
// 提取所有元素
395+
// 将几个数组合并到一起 [A..] + [B..] + [C..]
396+
let mut tmp_items = Vec::new();
397+
// 提取所有元素,依次合并
400398
tmp_items.extend(fullmatch_result.sequence_values::<mlua::Value>().collect::<Result<Vec<_>,_>>()?);
401399
tmp_items.extend(firstchar_result.sequence_values::<mlua::Value>().collect::<Result<Vec<_>,_>>()?);
402400
tmp_items.extend(fuzzymatch_result.sequence_values::<mlua::Value>().collect::<Result<Vec<_>,_>>()?);
@@ -560,8 +558,6 @@ fn matchfuzzypos(lua: &Lua, (list, word, opt): (LuaTable, String, LuaTable)) ->
560558
let t_word: String = item.get(key.clone())?;
561559
let mut position: LuaTable = lua.create_table()?;
562560
let mut score: i32;
563-
// let m = best_match(&word, &t_word).expect("No match");
564-
// match best_match(&word, &t_word) {
565561
let match_result = FuzzySearch::new(&word, &t_word)
566562
// .case_sensitive() // 不需要大小写敏感
567563
.score_with(&scoring)
@@ -581,13 +577,14 @@ fn matchfuzzypos(lua: &Lua, (list, word, opt): (LuaTable, String, LuaTable)) ->
581577
}
582578
}
583579
None => {
584-
// catch 异常情况
580+
// catch exception
585581
// do nothing and continue
586582
}
587583
}
588584
i += 1;
589585
}
590586

587+
// matchfuzzy 转换为向量
591588
let mut matchfuzzy_vec: Vec<Table> = matchfuzzy
592589
.sequence_values::<Table>()
593590
.collect::<Result<Vec<_>, _>>()?;
@@ -603,7 +600,7 @@ fn matchfuzzypos(lua: &Lua, (list, word, opt): (LuaTable, String, LuaTable)) ->
603600

604601
let mut new_matchfuzzy = lua.create_table()?;
605602

606-
// 4. 写回排序后的结果
603+
// 写回排序后的结果
607604
for (i, item) in matchfuzzy_vec.into_iter().enumerate() {
608605
let mut p: LuaTable = item.get("position")?;
609606
let mut s: i32 = item.get("score")?;
@@ -623,13 +620,14 @@ fn matchfuzzypos(lua: &Lua, (list, word, opt): (LuaTable, String, LuaTable)) ->
623620
Ok(result)
624621
}
625622

626-
// 161 个元素的遍历,lua 10ms,rust 5ms
623+
// 161 个元素的遍历,lua 10ms,rust 5ms, vim 15ms
627624
// 只做对 buf keyword 的 raw 格式的封装
628625
// 参数同 lua
626+
//
627+
// 返回:完整的封装好的列表,列表会被缓存到全局对象中
629628
fn final_normalize_menulist(lua: &Lua,
630629
(arr, plugin_name): (LuaTable, String))
631630
-> Result<LuaTable, LuaError> {
632-
// arr, plugin_name
633631
let mut result: LuaTable = lua.create_table()?;
634632
let cloned_plugin_name: &str = &plugin_name.clone();
635633
let arr_len: usize = arr.raw_len().try_into().expect("final len error");
@@ -641,14 +639,14 @@ fn final_normalize_menulist(lua: &Lua,
641639
// local l_menu_list = {}
642640
let l_menu_list : LuaTable = lua.create_table()?;
643641

644-
// let mut indexed : usize = Vec::with_capacity(arr_len);
645642
let mut iter = arr.sequence_values::<Table>();
646643
while let Some(every_item) = iter.next() {
647644
let item = every_item?;
648645
let now = Local::now();
649646
let timestamp: u32 = now.timestamp_subsec_nanos();
650647
let timestamp_str = format!("{}", timestamp);
651648
let sha256_str = timestamp_str;
649+
// 时间戳就已经符合要求了,不用再强制做 base64 编码
652650
// let sha256_str = encode(timestamp_str.as_bytes());
653651
// console(&sha256_str);
654652

@@ -665,8 +663,6 @@ fn final_normalize_menulist(lua: &Lua,
665663
let json_value: serde_json::Value = serde_json::from_str(json_raw_value).unwrap();
666664
let json_string: String = serde_json::to_string(&json_value).unwrap();
667665

668-
// println!("{}", json_string);
669-
670666
let t_item : LuaTable = lua.create_table()?;
671667
t_item.set("user_data", json_string)?;
672668
t_item.set("word", "")?;
0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)