Skip to content

Commit 0bd909b

Browse files
committed
Merge branch 'dev'
2 parents 499a882 + b313f8b commit 0bd909b

File tree

12 files changed

+222
-120
lines changed

12 files changed

+222
-120
lines changed

README-cn.md

Lines changed: 35 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,38 @@ Vim-easycomplete 是一个快速极简的自动补全插件,兼容 vim 和 neo
2626

2727
Vim 8.2 及以上版本,Neovim 0.7.0 及以上,支持 MacOS/Linux/FreeBSD。
2828

29-
lua 配置(基于 Packer.nvim ):
29+
lua 配置(基于 Packer.nvim ),通过 `require("easycomplete").config(opt)` 配置:
30+
31+
```lua
32+
use { 'jayli/vim-easycomplete', requires = {'L3MON4D3/LuaSnip'}}
33+
-- snippet 可选方案还有 'SirVer/ultisnips'
34+
-- `tabnine_enable = 0` 等同于 `vim.g.easycomplete_tabnine_enable = 0`
35+
require("easycomplete").config({
36+
cmdline = 1,
37+
pum_noselect = 0,
38+
tabnine_enable = 0,
39+
nerd_font = 1,
40+
enable = 1,
41+
winborder = 1,
42+
ghost_text = 1,
43+
menu_abbr = 0,
44+
pum_format = {"abbr", "kind", "menu"},
45+
setup = function()
46+
vim.keymap.set('n', 'gr', ':EasyCompleteReference<CR>')
47+
vim.keymap.set('n', 'gd', ':EasyCompleteGotoDefinition<CR>')
48+
vim.keymap.set('n', 'rn', ':EasyCompleteRename<CR>')
49+
-- Plugin has already bind shift-k to `:EasyCompleteHover`
50+
-- vim.keymap.set('n', 'gh', ':EasyCompleteHover<CR>')
51+
vim.keymap.set('n', 'gb', ':BackToOriginalBuffer<CR>')
52+
end
53+
})
54+
```
55+
56+
执行 `:PackerInstall`
57+
58+
[完整配置](https://github.com/jayli/vim-easycomplete/wiki/2.-%E5%AE%89%E8%A3%85%E5%92%8C%E9%85%8D%E7%BD%AE#%E5%9F%BA%E4%BA%8E-lua-%E7%9A%84%E5%AE%8C%E6%95%B4%E9%85%8D%E7%BD%AE)
59+
60+
还可以通过全局变量的方式来配置,这段lua配置和上面这段代码作用完全一样:
3061

3162
```lua
3263
-- lua
@@ -68,7 +99,7 @@ vim.g.easycomplete_cmdline = 1
6899
```
69100
执行 `:PackerInstall`
70101

71-
Vimscript 配置(基于vim-plug):
102+
在非 lua 中,可以使用 viml 配置,Vimscript 配置(基于vim-plug):
72103

73104
```vim
74105
" vim
@@ -113,24 +144,6 @@ let g:easycomplete_cmdline = 1
113144

114145
[一个例子](custom-config.md).
115146

116-
可以使用 Lua setup 风格初始化配置:`require("easycomplete").setup()`:
117-
118-
```lua
119-
-- lua style setup
120-
-- `tabnine_enable = 0` alias `vim.g.easycomplete_tabnine_enable = 0`
121-
require("easycomplete").setup({
122-
cmdline = 1,
123-
pum_noselect = 0,
124-
tabnine_enable = 0,
125-
nerd_font = 1,
126-
enable = 1,
127-
winborder = 1,
128-
ghost_text = 1,
129-
menu_abbr = 0,
130-
pum_format = {"abbr", "kind", "menu"}
131-
})
132-
```
133-
134147
## 使用
135148

136149
输入过程中自动显示匹配菜单,并通过 `Tab` 来选择下一个匹配项,`Shift-Tab` 选择上一个匹配项。`Ctrl-]` 跳转到定义处,`Ctrl-t`跳回(和 tags 跳转快捷键一致)。
@@ -178,7 +191,7 @@ require("easycomplete").setup({
178191
| `g:easycomplete_tabnine_suggestion` | 0 | Tabnine 行内补全(for nvim only) |
179192
| `g:easycomplete_lsp_checking` | 1 | 打开文件时是否立即检查 lsp 是否安装 |
180193
| `g:easycomplete_tabnine_enable` | 1 | 启用 Tabnine:启用后补全菜单里会出现 Tabnine 补全项 |
181-
| `g:easycomplete_directory_enable` | 1 | 目录匹配 |
194+
| `g:easycomplete_path_enable` | 1 | 目录匹配 |
182195
| `g:easycomplete_tabnine_config` | `{}` | [TabNine 配置](#ai-coding-via-tabnine-support) |
183196
| `g:easycomplete_filetypes` | `{}` | [自定义文件类型配置](#language-support) |
184197
| `g:easycomplete_enable` | 1 | 是否启用插件 |
@@ -221,7 +234,7 @@ LSP 服务会安装在本地路径: `~/.config/vim-easycomplete/servers`。
221234

222235
| 名称 | 语言 | LSP 服务 | LSP 是否需要安装 | 依赖 | URL |
223236
|-------------|-----------|:------------------------:|:------------------:|:------------:|:--------:|
224-
| directory | directory | No Need | 内置 || |
237+
| path | path | No Need | 内置 || |
225238
| buf | buf & dict| No Need | 内置 || |
226239
| snips | Snippets | ultisnips/LuaSnip | 内置 | python3/lua | |
227240
| ts | js/ts | tsserver | Yes | node/npm | |

README.md

Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Vim-easycomplete is a fast and minimalism style completion plugin for both vim a
1515
It contains these features:
1616

1717
- Full [lsp]([language-server-protocol](https://github.com/microsoft/language-server-protocol)) support. Easy to install LSP Server with one command
18-
- Keywords/Directory support
18+
- Keywords/path support
1919
- Implemented based on pure vimscript
2020
- Snippet support.
2121
- Fast performance
@@ -26,7 +26,38 @@ It contains these features:
2626

2727
Requires Vim 8.2 or higher version on MacOS/Linux/FreeBSD. Neovim 0.7.0 or higher.
2828

29-
Lua config with Packer.nvim:
29+
Lua config with Packer.nvim via `require("easycomplete").config(opt)`:
30+
31+
```lua
32+
use { 'jayli/vim-easycomplete', requires = {'L3MON4D3/LuaSnip'}}
33+
-- For snippet support, 'SirVer/ultisnips' is an alternative option
34+
-- `tabnine_enable = 0` alias `vim.g.easycomplete_tabnine_enable = 0`
35+
require("easycomplete").config({
36+
cmdline = 1,
37+
pum_noselect = 0,
38+
tabnine_enable = 0,
39+
nerd_font = 1,
40+
enable = 1,
41+
winborder = 1,
42+
ghost_text = 1,
43+
menu_abbr = 0,
44+
pum_format = {"abbr", "kind", "menu"},
45+
setup = function()
46+
vim.keymap.set('n', 'gr', ':EasyCompleteReference<CR>')
47+
vim.keymap.set('n', 'gd', ':EasyCompleteGotoDefinition<CR>')
48+
vim.keymap.set('n', 'rn', ':EasyCompleteRename<CR>')
49+
-- Plugin has already bind shift-k to `:EasyCompleteHover`
50+
-- vim.keymap.set('n', 'gh', ':EasyCompleteHover<CR>')
51+
vim.keymap.set('n', 'gb', ':BackToOriginalBuffer<CR>')
52+
end
53+
})
54+
```
55+
56+
Run `:PackerInstall`
57+
58+
[Full configuration](https://github.com/jayli/vim-easycomplete/wiki/2.-%E5%AE%89%E8%A3%85%E5%92%8C%E9%85%8D%E7%BD%AE#%E5%9F%BA%E4%BA%8E-lua-%E7%9A%84%E5%AE%8C%E6%95%B4%E9%85%8D%E7%BD%AE)
59+
60+
You can configure it through global variables like this which is exactly the same as the above configuration:
3061

3162
```lua
3263
-- lua
@@ -65,6 +96,7 @@ vim.g.easycomplete_cmdline = 1
6596
-- vim.g.easycomplete_use_default_cr = 0
6697
-- vim.keymap.set('i', '<C-L>', '<Plug>EasycompleteCR')
6798
```
99+
68100
Run `:PackerInstall`
69101

70102
Vimscript config with vim-plug:
@@ -110,24 +142,6 @@ Run `:PlugInstall`.
110142

111143
[Full configuration example](custom-config.md).
112144

113-
Lua style setup with `require("easycomplete").setup()`:
114-
115-
```lua
116-
-- lua style setup
117-
-- `tabnine_enable = 0` alias `vim.g.easycomplete_tabnine_enable = 0`
118-
require("easycomplete").setup({
119-
cmdline = 1,
120-
pum_noselect = 0,
121-
tabnine_enable = 0,
122-
nerd_font = 1,
123-
enable = 1,
124-
winborder = 1,
125-
ghost_text = 1,
126-
menu_abbr = 0,
127-
pum_format = {"abbr", "kind", "menu"}
128-
})
129-
```
130-
131145
## Useage
132146

133147
- `Tab`/`S-Tab`: select next/previous matched items.
@@ -177,7 +191,7 @@ Global configurations:
177191
| `g:easycomplete_tabnine_suggestion` | 0 | Tabnine inline suggestion(for nvim only) |
178192
| `g:easycomplete_lsp_checking` | 1 | Check whether the lsp is installed while opening a file |
179193
| `g:easycomplete_tabnine_enable` | 1 | Enable Tabnine |
180-
| `g:easycomplete_directory_enable` | 1 | Directory complete |
194+
| `g:easycomplete_path_enable` | 1 | Path complete |
181195
| `g:easycomplete_tabnine_config` | `{}` | [TabNine Configuration](#ai-coding-via-tabnine-support) |
182196
| `g:easycomplete_filetypes` | `{}` | [Custom filetyps configuration](#language-support) |
183197
| `g:easycomplete_enable` | 1 | Enable this plugin |
@@ -222,7 +236,7 @@ All supported languages:
222236

223237
| Plugin Name | Languages | Language Server | Installer | Requirements | URL |
224238
|-------------|-----------|:------------------------:|:------------------:|:------------:|:---:|
225-
| directory | directory | No Need | Integrated | None | |
239+
| path | path | No Need | Integrated | None | |
226240
| buf | buf & dict| No Need | Integrated | None | |
227241
| snips | Snippets | ultisnips/LuaSnip | Integrated | python3/lua | |
228242
| ts | js/ts | tsserver | Yes | node/npm | |

autoload/easycomplete.vim

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ let g:easycomplete_ghost_text_str = ""
8686
let b:easycomplete_typing_timer = 0
8787
let s:easycomplete_toolkit = g:env_is_nvim ? v:lua.require("easycomplete") : v:null
8888
let s:util_toolkit = g:env_is_nvim ? v:lua.require("easycomplete.util") : v:null
89-
let b:is_directory_complete = 0
89+
let b:is_path_complete = 0
9090
let b:fast_bs_timer = 0
9191

9292
function! easycomplete#Enable()
@@ -1178,23 +1178,23 @@ function! s:CompletorCallingAtFirstComplete(ctx)
11781178

11791179
" TODO 原本在设计 CompletorCalling 机制时,每个CallCompeltorByName返回true时继
11801180
" 续执行,返回false中断执行,目的是为了实现那些排他性的CompleteCalling,比如
1181-
" directory. 这样就只能串行执行每个插件的 completor()
1181+
" path. 这样就只能串行执行每个插件的 completor()
11821182
"
11831183
" 但在 runtime 中不能很好的执行,因为每个 complete_plugin 的
11841184
" completor 的调用顺序不确定,如果让所有 completor 全都异步,是可以实现排他性
11851185
" complete的,但即便每个调用都是异步,对于 lsp request 已经发出的情况,由于不
11861186
" 能abort掉 lsp 进程,因此还是会有返回值冲刷进 g:easycomplete_menuitems,进而
11871187
" 污染匹配结果。
11881188
"
1189-
" 这里默认只有 directory 唯一一个需要排他的情况,把 directory 提前。
1189+
" 这里默认只有 path 唯一一个需要排他的情况,把 path 提前。
11901190
" 设计上需要重新考虑下,是否是只能有一个排他completor,还是存在多个共存的
11911191
" 情况,还不清楚,先这样hack掉
11921192
try
1193-
let source_directory = ['directory']
1193+
let source_path = ['path']
11941194
let source_names = []
11951195

11961196
for name in keys(g:easycomplete_source)
1197-
if name == "directory"
1197+
if name == "path"
11981198
continue
11991199
endif
12001200
if name == "snips" || name == "buf"
@@ -1207,8 +1207,8 @@ function! s:CompletorCallingAtFirstComplete(ctx)
12071207
call add(source_names, name)
12081208
endif
12091209
endfor
1210-
" 最后把 source_directory 放在最前面
1211-
let source_names = source_directory + source_names
1210+
" 最后把 source_path 放在最前面
1211+
let source_names = source_path + source_names
12121212

12131213
let l:count = 0
12141214
while l:count < len(source_names)
@@ -1866,12 +1866,12 @@ function! easycomplete#CompleteAdd(menu_list, plugin_name)
18661866
let filtered_menu = g_easycomplete_menuitems
18671867
let start_pos = col('.') - strwidth(typing_word)
18681868

1869-
if a:plugin_name == "directory"
1869+
if a:plugin_name == "path"
18701870
" let typed = strpart(getline('.'), 0, col('.') - 1)
18711871
" let start_pos = strwidth(typed) - strwidth(fnamemodify(typed, ":t"))
1872-
let b:is_directory_complete = 1
1872+
let b:is_path_complete = 1
18731873
else
1874-
let b:is_directory_complete = 0
1874+
let b:is_path_complete = 0
18751875
endif
18761876

18771877
try
@@ -1962,7 +1962,7 @@ function! s:FirstCompleteRendering(start_pos, menuitems)
19621962
endif
19631963
let l:ctx = easycomplete#context()
19641964
let typing_word = l:ctx["typing"]
1965-
if b:is_directory_complete
1965+
if b:is_path_complete
19661966
let typing_word = easycomplete#util#GetFileName(l:ctx["typed"])
19671967
endif
19681968
let should_stop_render = 0
@@ -1982,7 +1982,7 @@ function! s:FirstCompleteRendering(start_pos, menuitems)
19821982
endif
19831983

19841984
if !should_stop_render && len(source_result) > 0
1985-
if b:is_directory_complete
1985+
if b:is_path_complete
19861986
let filtered_menu = deepcopy(source_result)
19871987
else
19881988
" distinct 只去重 bufkeyword 和 dict

autoload/easycomplete/sources/directory.vim renamed to autoload/easycomplete/sources/path.vim

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11

2-
function! easycomplete#sources#directory#completor(opt, ctx)
2+
function! easycomplete#sources#path#completor(opt, ctx)
33
let l:typing_path = s:TypingAPath(a:ctx)
44
if !l:typing_path.is_path
55
call easycomplete#complete(a:opt['name'], a:ctx, a:ctx['startcol'], [])
66
return v:true
77
endif
88
call easycomplete#util#timer_start(
9-
\ "easycomplete#sources#directory#CompleteHandler",
9+
\ "easycomplete#sources#path#CompleteHandler",
1010
\ [a:ctx['typing'], a:opt['name'], a:ctx, a:ctx['startcol'], l:typing_path],
1111
\ 10 )
1212
" 展开目录时,中断其他complete逻辑
@@ -15,20 +15,20 @@ function! easycomplete#sources#directory#completor(opt, ctx)
1515
return v:false
1616
endfunction
1717

18-
function! easycomplete#sources#directory#CompleteHandler(...)
18+
function! easycomplete#sources#path#CompleteHandler(...)
1919
return call(function("s:CompleteHandler"), a:000)
2020
endfunction
2121

2222
function! s:CompleteHandler(typing, name, ctx, startcol, typing_path)
23-
if g:easycomplete_directory_enable == 0
23+
if g:easycomplete_path_enable == 0
2424
call easycomplete#complete(a:name, a:ctx, a:startcol, [])
2525
return
2626
endif
2727
let spath_start = a:typing_path.short_path_start
2828
try
2929
let result = s:GetDirAndFiles(a:typing_path, a:typing_path.fname)
3030
catch
31-
call s:errlog('[Directory]', v:exception)
31+
call s:errlog('[Path]', v:exception)
3232
return
3333
endtry
3434
if len(result) == 0
@@ -39,7 +39,7 @@ function! s:CompleteHandler(typing, name, ctx, startcol, typing_path)
3939
call easycomplete#complete(a:name, a:ctx, a:startcol, result)
4040
endfunction
4141

42-
function! easycomplete#sources#directory#pum()
42+
function! easycomplete#sources#path#pum()
4343
if g:env_is_vim && (!pumvisible() || !exists('g:easycomplete_stunt_menuitems'))
4444
return v:valse
4545
endif
@@ -49,7 +49,7 @@ function! easycomplete#sources#directory#pum()
4949
if empty(g:easycomplete_stunt_menuitems)
5050
return v:false
5151
endif
52-
if get(g:easycomplete_stunt_menuitems[-1], 'plugin_name', "") == "directory"
52+
if get(g:easycomplete_stunt_menuitems[-1], 'plugin_name', "") == "path"
5353
return v:true
5454
endif
5555
return v:false
@@ -92,7 +92,7 @@ function! s:GetDirAndFiles(typing_path, base)
9292
return s:GetWrappedFileAndDirsList(result_list, s:GetPathName(path), l:base)
9393
endfunction
9494

95-
function! easycomplete#sources#directory#GetDirAndFiles(typing_path, base)
95+
function! easycomplete#sources#path#GetDirAndFiles(typing_path, base)
9696
return s:GetDirAndFiles(a:typing_path, a:base)
9797
endfunction
9898

@@ -137,7 +137,7 @@ function! s:GetWrappedFileAndDirsList(rlist, fpath, base)
137137
return result_with_kind
138138
endfunction
139139

140-
function! easycomplete#sources#directory#TypingAPath(...)
140+
function! easycomplete#sources#path#TypingAPath(...)
141141
return call(function('s:TypingAPath'), a:000)
142142
endfunction
143143

autoload/easycomplete/sources/tn.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ function! s:CompleteHandler(res)
477477
endfunction
478478

479479
function! s:UpdateRendering(result)
480-
if easycomplete#sources#directory#pum()
480+
if easycomplete#sources#path#pum()
481481
return
482482
endif
483483
call easycomplete#StoreCompleteSourceItems(s:tn_name, a:result)

custom-config.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ vim.g.easycomplete_tabnine_enable = 1
8585
-- Enable Tabnine suggestion, default is off
8686
vim.g.easycomplete_tabnine_suggestion = 0
8787

88-
-- Enable directory complete. Default is on
89-
vim.g.easycomplete_directory_enable = 1
88+
-- Enable path complete. Default is on
89+
vim.g.easycomplete_path_enable = 1
9090

9191
-- Show abbr(shortname) at `menu` position in pum
9292
vim.g.easycomplete_menu_abbr = 1

0 commit comments

Comments
 (0)