From e90e00ca4a96d35fcccbf012a75599bae91df70f Mon Sep 17 00:00:00 2001 From: jayli Date: Mon, 8 Jan 2024 12:23:20 +0800 Subject: [PATCH] bugfix for cpp fuzzy match err --- autoload/easycomplete/sources/cpp.vim | 21 ++++++++++++++++++++- autoload/easycomplete/util.vim | 2 ++ plugin/easycomplete.vim | 18 +++++++++--------- 3 files changed, 31 insertions(+), 10 deletions(-) diff --git a/autoload/easycomplete/sources/cpp.vim b/autoload/easycomplete/sources/cpp.vim index 3a22336c..154a424e 100644 --- a/autoload/easycomplete/sources/cpp.vim +++ b/autoload/easycomplete/sources/cpp.vim @@ -21,9 +21,28 @@ endfunction function! easycomplete#sources#cpp#filter(matches) let ctx = easycomplete#context() let matches = map(copy(a:matches), function("easycomplete#util#FunctionSurffixMap")) - return matches + let matches_ret = map(copy(matches), function("s:CppItemPrefixHandling")) + return matches_ret +endfunction + +function! s:CppItemPrefixHandling(key, val) + " `•clockid_t` -> `clockid_t` + " ` std::chrono` -> `std::chrono` + let item = a:val + let first_char = strcharpart(item['abbr'], 0, 1) + let abbr = item['abbr'] + if char2nr(first_char) == 32 " 首字符是空格 + let item['abbr'] = substitute(abbr, "^\\s\\+\\(.\\{\-}\\)$","\\1","g") + elseif strlen(first_char) > 1 + let item['abbr'] = strcharpart(abbr, 1) + endif + return item endfunction function! s:log(...) return call('easycomplete#util#log', a:000) endfunction + +function! s:console(...) + return call('easycomplete#log#log', a:000) +endfunction diff --git a/autoload/easycomplete/util.vim b/autoload/easycomplete/util.vim index 9bfd94dc..2a1cabc0 100644 --- a/autoload/easycomplete/util.vim +++ b/autoload/easycomplete/util.vim @@ -168,7 +168,9 @@ endfunction " }}} " trim {{{ function! easycomplete#util#trim(str) if !empty(a:str) + " 删除头部空格 let a1 = substitute(a:str, "^\\s\\+\\(.\\{\-}\\)$","\\1","g") + " 删除尾部空格 let a1 = substitute(a:str, "^\\(.\\{\-}\\)\\s\\+$","\\1","g") return a1 endif diff --git a/plugin/easycomplete.vim b/plugin/easycomplete.vim index 580e2420..f456bd05 100644 --- a/plugin/easycomplete.vim +++ b/plugin/easycomplete.vim @@ -49,7 +49,7 @@ if g:easycomplete_nerd_font == 1 \ 'error': "", \ 'warning': "", \ 'information': '', - \ 'hint': '' + \ 'hint': '' \ } let g:easycomplete_lsp_type_font = { \ 'class': get(kind_icons, "class", ""), 'color': get(kind_icons, "color", ""), @@ -66,14 +66,14 @@ if g:easycomplete_nerd_font == 1 \ 'let': get(kind_icons, "let", ""), 'parameter': get(kind_icons, 'parameter', "󰏗"), \ 'operator': get(kind_icons, 'operator', "󱧕"), 'property': get(kind_icons, 'property', "󰙅"), \ 'local': get(kind_icons, 'local', ""), - \ 'r':'', 't':'', - \ 'f':'f', 'c':'', - \ 'u':'𝘶', 'e':'𝘦', - \ 's':'󰙅', 'v':'', - \ 'i':'𝘪', 'm':'', - \ 'p':'𝘱', 'k':'𝘬', - \ 'o':"󱧕", 'd':'𝘥', - \ 'l':"", 'a':"𝘢", + \ 'r':'', 't':'', + \ 'f':'f', 'c':'', + \ 'u':'𝘶', 'e':'𝘦', + \ 's':'󰙅', 'v':'', + \ 'i':'𝘪', 'm':'', + \ 'p':'𝘱', 'k':'𝘬', + \ 'o':"󱧕", 'd':'𝘥', + \ 'l':"", 'a':"𝘢", \ } endif