Skip to content

Commit b313f8b

Browse files
committed
先增加目录匹配 #388
1 parent 111b5ee commit b313f8b

File tree

9 files changed

+44
-40
lines changed

9 files changed

+44
-40
lines changed

README-cn.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ require("easycomplete").config({
5555

5656
执行 `:PackerInstall`
5757

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+
5860
还可以通过全局变量的方式来配置,这段lua配置和上面这段代码作用完全一样:
5961

6062
```lua
@@ -189,7 +191,7 @@ let g:easycomplete_cmdline = 1
189191
| `g:easycomplete_tabnine_suggestion` | 0 | Tabnine 行内补全(for nvim only) |
190192
| `g:easycomplete_lsp_checking` | 1 | 打开文件时是否立即检查 lsp 是否安装 |
191193
| `g:easycomplete_tabnine_enable` | 1 | 启用 Tabnine:启用后补全菜单里会出现 Tabnine 补全项 |
192-
| `g:easycomplete_directory_enable` | 1 | 目录匹配 |
194+
| `g:easycomplete_path_enable` | 1 | 目录匹配 |
193195
| `g:easycomplete_tabnine_config` | `{}` | [TabNine 配置](#ai-coding-via-tabnine-support) |
194196
| `g:easycomplete_filetypes` | `{}` | [自定义文件类型配置](#language-support) |
195197
| `g:easycomplete_enable` | 1 | 是否启用插件 |
@@ -232,7 +234,7 @@ LSP 服务会安装在本地路径: `~/.config/vim-easycomplete/servers`。
232234

233235
| 名称 | 语言 | LSP 服务 | LSP 是否需要安装 | 依赖 | URL |
234236
|-------------|-----------|:------------------------:|:------------------:|:------------:|:--------:|
235-
| directory | directory | No Need | 内置 || |
237+
| path | path | No Need | 内置 || |
236238
| buf | buf & dict| No Need | 内置 || |
237239
| snips | Snippets | ultisnips/LuaSnip | 内置 | python3/lua | |
238240
| ts | js/ts | tsserver | Yes | node/npm | |

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ https://github.com/user-attachments/assets/30c265f3-e65c-47d0-8762-e9e8250d7b4d
1616
It contains these features:
1717

1818
- Full [lsp]([language-server-protocol](https://github.com/microsoft/language-server-protocol)) support. Easy to install LSP Server with one command
19-
- Keywords/Directory support
19+
- Keywords/path support
2020
- Implemented based on pure vimscript
2121
- Snippet support.
2222
- Fast performance
@@ -56,6 +56,8 @@ require("easycomplete").config({
5656

5757
Run `:PackerInstall`
5858

59+
[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)
60+
5961
You can configure it through global variables like this which is exactly the same as the above configuration:
6062

6163
```lua
@@ -190,7 +192,7 @@ Global configurations:
190192
| `g:easycomplete_tabnine_suggestion` | 0 | Tabnine inline suggestion(for nvim only) |
191193
| `g:easycomplete_lsp_checking` | 1 | Check whether the lsp is installed while opening a file |
192194
| `g:easycomplete_tabnine_enable` | 1 | Enable Tabnine |
193-
| `g:easycomplete_directory_enable` | 1 | Directory complete |
195+
| `g:easycomplete_path_enable` | 1 | Path complete |
194196
| `g:easycomplete_tabnine_config` | `{}` | [TabNine Configuration](#ai-coding-via-tabnine-support) |
195197
| `g:easycomplete_filetypes` | `{}` | [Custom filetyps configuration](#language-support) |
196198
| `g:easycomplete_enable` | 1 | Enable this plugin |
@@ -235,7 +237,7 @@ All supported languages:
235237

236238
| Plugin Name | Languages | Language Server | Installer | Requirements | URL |
237239
|-------------|-----------|:------------------------:|:------------------:|:------------:|:---:|
238-
| directory | directory | No Need | Integrated | None | |
240+
| path | path | No Need | Integrated | None | |
239241
| buf | buf & dict| No Need | Integrated | None | |
240242
| snips | Snippets | ultisnips/LuaSnip | Integrated | python3/lua | |
241243
| 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

doc/easycomplete.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ a bunch of Node modules unless you’re a js/ts programmer.
1616

1717
Vim-Easycomplete is easy to install and use. It contains these features:
1818

19-
- Keywords/Directory support
19+
- Keywords/path support
2020
- Implemented based on pure vimscript
2121
- Snippet support.
2222
- Fast performance
@@ -168,7 +168,7 @@ Global configurations:
168168
| `g:easycomplete_tabnine_suggestion` | 0 | Tabnine inline suggestion(for nvim only) |
169169
| `g:easycomplete_lsp_checking` | 1 | Check whether the lsp is installed while opening a file |
170170
| `g:easycomplete_tabnine_enable` | 1 | Enable Tabnine |
171-
| `g:easycomplete_directory_enable` | 1 | Directory complete |
171+
| `g:easycomplete_path_enable` | 1 | Path complete |
172172
| `g:easycomplete_tabnine_config` | `{}` | [TabNine Configuration](#ai-coding-via-tabnine-support) |
173173
| `g:easycomplete_filetypes` | `{}` | [Custom filetyps configuration](#language-support) |
174174
| `g:easycomplete_enable` | 1 | Enable this plugin |
@@ -216,7 +216,7 @@ All supported languages:
216216

217217
| Plugin Name | Languages | Language Server | Installer | Requirements | URL |
218218
|-------------|-----------|:------------------------:|:------------------:|:------------:|:---:|
219-
| directory | directory | No Need | Integrated | None | |
219+
| path | path | No Need | Integrated | None | |
220220
| buf | buf & dict| No Need | Integrated | None | |
221221
| snips | Snippets | ultisnips/LuaSnip | Integrated | python3/lua | |
222222
| ts | js/ts | tsserver | Yes | node/npm | |
@@ -271,7 +271,7 @@ All supported languages:
271271

272272
| Plugin Name | Languages | Language Server | Installer |
273273
| ----------- | --------------------- | ---------------------- | --------- |
274-
| directory | directory suggestion | No Need | No Need |
274+
| path | path suggestion | No Need | No Need |
275275
| buf | keywords & dictionary | No Need | No Need |
276276
| snips | Snippets Support | ultisnips/vim-snippets | No |
277277
| ts | JavaScript/TypeScript | tsserver | Yes |

lua/easycomplete/pum.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ end
4444

4545
-- for cmdline only
4646
function pum.get_path_cmp_items()
47-
local typing_path = vim.fn['easycomplete#sources#directory#TypingAPath']()
47+
local typing_path = vim.fn['easycomplete#sources#path#TypingAPath']()
4848
-- 取根目录
4949
-- insert模式下为了避免和输入注释"//"频繁干扰,去掉了根目录的路径匹配
5050
-- 这里不存在这个频繁干扰的问题,再加回来
@@ -54,7 +54,7 @@ function pum.get_path_cmp_items()
5454
if typing_path.is_path == 0 then
5555
return {}
5656
else
57-
local ret = vim.fn['easycomplete#sources#directory#GetDirAndFiles'](typing_path, typing_path.fname)
57+
local ret = vim.fn['easycomplete#sources#path#GetDirAndFiles'](typing_path, typing_path.fname)
5858
return ret
5959
end
6060
end

plugin/easycomplete.vim

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,8 @@ endif
157157
if g:env_is_vim || !has('nvim-0.11.0')
158158
let g:easycomplete_winborder = 0
159159
endif
160-
if !exists("g:easycomplete_directory_enable")
161-
let g:easycomplete_directory_enable = 1
160+
if !exists("g:easycomplete_path_enable")
161+
let g:easycomplete_path_enable = 1
162162
endif
163163
if !exists("g:easycomplete_tabnine_config")
164164
let g:easycomplete_tabnine_config = {}
@@ -250,7 +250,7 @@ let g:easycomplete_config = {
250250
\ 'g:easycomplete_ghost_text': g:easycomplete_ghost_text,
251251
\ 'g:easycomplete_cursor_word_hl': g:easycomplete_cursor_word_hl,
252252
\ 'g:easycomplete_signature_offset': g:easycomplete_signature_offset,
253-
\ 'g:easycomplete_directory_enable': g:easycomplete_directory_enable,
253+
\ 'g:easycomplete_path_enable': g:easycomplete_path_enable,
254254
\ 'g:easycomplete_winborder': g:easycomplete_winborder,
255255
\ 'g:easycomplete_pum_maxheight': g:easycomplete_pum_maxheight
256256
\ }
@@ -300,9 +300,9 @@ endif
300300
augroup easycomplete#PluginRegister
301301

302302
au User easycomplete_default_plugin call easycomplete#RegisterSource({
303-
\ 'name': 'directory',
303+
\ 'name': 'path',
304304
\ 'whitelist': ['*'],
305-
\ 'completor': function('easycomplete#sources#directory#completor'),
305+
\ 'completor': function('easycomplete#sources#path#completor'),
306306
\ })
307307

308308
au User easycomplete_default_plugin call easycomplete#RegisterSource({

0 commit comments

Comments
 (0)