Skip to content

Commit

Permalink
bugfix for tabnine suggestion sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
jayli committed Dec 4, 2023
1 parent 9adca42 commit af07001
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 9 deletions.
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
# Vim-EasyComplete

> A Fast & Minimalism Style Code Completion Plugin for vim/nvim.
> A Fast and Minimalism Style Completion Plugin for vim/nvim.
![](https://img.shields.io/badge/VimScript-Only-orange.svg) ![](https://img.shields.io/badge/MacOS-available-brightgreen.svg) ![](https://img.shields.io/badge/license-MIT-blue.svg) ![](https://img.shields.io/github/workflow/status/jayli/vim-easycomplete/easycomplete.CI)

### Why

There are many excellent vim auto-completion plugins such as [nvim-cmp](https://github.com/hrsh7th/nvim-cmp), [vim-lsp](https://github.com/prabirshrestha/vim-lsp), [YouCompleteMe](https://github.com/ycm-core/YouCompleteMe) and [coc.nvim](https://github.com/neoclide/coc.nvim) etc. However I want a more conncise style plugin without any uneccessary configurations. What's more, it would be a good idea to incorporate the capabilities of an AI coding assistant as well.
There are many excellent vim auto-completion plugins such as [nvim-cmp](https://github.com/hrsh7th/nvim-cmp), [vim-lsp](https://github.com/prabirshrestha/vim-lsp), [YouCompleteMe](https://github.com/ycm-core/YouCompleteMe) and [coc.nvim](https://github.com/neoclide/coc.nvim) etc. However I still want a simpler plugin without any redundant configurations. And it's a good idea to incorporate the capabilities of an AI coding assistant as well.

### What

Vim-easycomplete is a fast and minimalism style completion plugin for vim/nvim. The goal is to work everywhere out of the box with high-speed performance. It requires pure vim script. You don’t need to configure anything uneccessary. Especially, You don’t have to install Node and a bunch of Node modules unless you’re a javascript/typescript programmer.
Vim-easycomplete is a fast and minimalism style completion plugin for vim/nvim. The goal is to work everywhere out of the box. It requires pure VimScript. It's also super simple to configure. Especially, You don’t have to install Node and a bunch of Node modules unless you’re a js/ts programmer.

<img src="https://gw.alicdn.com/imgextra/i2/O1CN01OA1VV41QHbd7Y2WKu_!!6000000001951-1-tps-1209-693.gif" width=650 />

It is easy to install and use. It contains these features:
It contains these features:

- AI coding assistant via tabnine(#TabNine-Support). (Highly Recommend!)
- AI coding assistant via [tabnine](#TabNine-Support). (Highly Recommend!)
- Buffer Keywords/Directory support
- LSP([language-server-protocol](https://github.com/microsoft/language-server-protocol)) support
- Easy to install LSP Server with one command
- Written in pure vim script for vim8 and neovim
- Snippet support with ultisnips.
- Fast performance

The reason I decided to use pure vim script instead of lua or python is that I want a wider range of compatibility. And I made a lot of async handling with vim script to avoid the block of vim.
The reason I decided to use pure vim script instead of lua or python is that I want a wider range of compatibility. And I made a lot of async handling with vim script to avoid the block of rendering.

### Installation

Expand Down Expand Up @@ -123,6 +123,8 @@ let g:easycomplete_diagnostics_prev = "<C-k>"
- Set `let g:easycomplete_diagnostics_enable = 0` to disable lsp diagnostics.
- Set `let g:easycomplete_lsp_checking = 0` to disable lsp checking for installation.
- Set `let g:easycomplete_signature_enable = 0` to disable lsp signature checking.
- Set `let g:easycomplete_tabnine_suggestion = 0` to disable tabnine inline suggestions.
- Set `let g:easycomplete_directory_enable = 0` to disable directory complete.

Typing `:h easycomplete` for help.

Expand Down Expand Up @@ -322,7 +324,6 @@ let g:easycomplete_colorful = 1

[add custom completion plugin](add-custom-plugin.md)


### Issues

[WIP] If you have bug reports or feature suggestions, please use the [issue tracker](https://github.com/jayli/vim-easycomplete/issues/new). In the meantime feel free to read some of my thoughts at <https://zhuanlan.zhihu.com/p/366496399>, <https://zhuanlan.zhihu.com/p/425555993>, [https://medium.com/@lijing00333/vim-easycomplete](https://dev.to/jayli/how-to-improve-your-vimnvim-coding-experience-with-vim-easycomplete-29o0)
Expand Down
6 changes: 5 additions & 1 deletion autoload/easycomplete.vim
Original file line number Diff line number Diff line change
Expand Up @@ -1329,7 +1329,11 @@ endfunction

function! easycomplete#StoreCompleteSourceItems(plugin_name, result)
let norm_menu_list = s:NormalizeMenulist(a:result, a:plugin_name)
let sort_menu_list = s:NormalizeSort(norm_menu_list)
if a:plugin_name == "tn"
let sort_menu_list = norm_menu_list
else
let sort_menu_list = s:NormalizeSort(norm_menu_list)
endif
let g:easycomplete_source[a:plugin_name].complete_result = deepcopy(sort_menu_list)
endfunction

Expand Down
20 changes: 19 additions & 1 deletion autoload/easycomplete/sources/tn.vim
Original file line number Diff line number Diff line change
Expand Up @@ -387,16 +387,34 @@ function! s:NormalizeCompleteResult(data)
else
let l:word['menu'] = '[TN]'
endif
let percent_str = ""
if get(l:result, 'detail')
let l:word['menu'] .= ' ' . l:result['detail']
let percent_str = s:fullfill(l:result['detail'])
endif
let tmp_detail = easycomplete#util#get(l:result, 'completion_metadata', 'detail')
if !empty(tmp_detail)
let percent_str = s:fullfill(tmp_detail)
endif
let l:word["menu"] .= percent_str
let l:word["sort_number"] = matchstr(percent_str, "\\d\\+","g")
let l:word['abbr'] = l:word['word']
let l:word['word'] = tn_prefix . l:word['word']
call add(l:words, l:word)
endfor
call sort(l:words, {a, b -> str2nr(a["sort_number"]) < str2nr(b["sort_number"])})
return l:words
endfunction

" ' 4%' -> ' 4%'
" '22%' -> ' 22%'
function! s:fullfill(percent)
if a:percent[0] == " "
return a:percent
else
return " " . a:percent
endif
endfunction

function! s:log(...)
return call('easycomplete#util#log', a:000)
endfunction
Expand Down
13 changes: 13 additions & 0 deletions lua/easycomplete/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ function Util.get_word(a)
return k
end

function Util.isTN(item)
local plugin_name = Util.get_item_plugin_name(item)
if plugin_name == "tn" then
return true
else
return false
end
end

function Util.curr_lsp_constructor_calling()
Util.constructor_calling_by_name(Util.current_plugin_name())
end
Expand Down Expand Up @@ -80,6 +89,10 @@ function Util.log(...)
return vim.fn['easycomplete#util#info'](...)
end

function Util.get_item_plugin_name(...)
return vim.fn['easycomplete#util#GetPluginNameFromUserData'](...)
end

function Util.current_plugin_ctx()
return vim.fn['easycomplete#GetCurrentLspContext']()
end
Expand Down

0 comments on commit af07001

Please sign in to comment.