1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-01-23 10:40:03 +08:00

Add autocomplete delay option (#2236)

This commit is contained in:
Wang Shidong 2018-10-06 10:15:19 +08:00 committed by GitHub
parent aabe1674ca
commit 240d839614
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 119 additions and 107 deletions

View File

@ -194,6 +194,7 @@ function! SpaceVim#layers#autocomplete#set_variable(var) abort
let s:key_sequence_delay = get(a:var,
\ 'auto-completion-complete-with-key-sequence-delay',
\ 0.1)
let g:_spacevim_autocomplete_delay = get(a:var, 'auto-completion-delay', 50)
endfunction
@ -204,6 +205,12 @@ function! SpaceVim#layers#autocomplete#get_options() abort
\ 'auto-completion-complete-with-key-sequence',
\ 'auto-completion-complete-with-key-sequence-delay']
endfunction
function! SpaceVim#layers#autocomplete#getprfile() abort
endfunction
" vim:set et sw=2 cc=80:

View File

@ -1,11 +1,17 @@
" deoplete options
let g:deoplete#enable_at_startup = get(g:, 'deoplete#enable_at_startup', 1)
let g:deoplete#enable_ignore_case = get(g:, 'deoplete#enable_ignore_case', 1)
let g:deoplete#enable_smart_case = get(g:, 'deoplete#enable_smart_case', 1)
let g:deoplete#enable_camel_case = get(g:, 'deoplete#enable_camel_case', 1)
let g:deoplete#enable_refresh_always = get(g:, 'deoplete#enable_refresh_always', 1)
let g:deoplete#max_abbr_width = get(g:, 'deoplete#max_abbr_width', 0)
let g:deoplete#max_menu_width = get(g:, 'deoplete#max_menu_width', 0)
" deoplete options
let s:profile = SpaceVim#layers#autocomplete#getprfile()
call deoplete#custom#option({
\ 'auto_complete_delay' : g:_spacevim_autocomplete_delay,
\ 'ignore_case' : get(g:, 'deoplete#enable_ignore_case', 1),
\ 'smart_case' : get(g:, 'deoplete#enable_smart_case', 1),
\ 'camel_case' : get(g:, 'deoplete#enable_camel_case', 1),
\ 'refresh_always' : get(g:, 'deoplete#enable_refresh_always', 1)
\ })
" let g:deoplete#max_abbr_width = get(g:, 'deoplete#max_abbr_width', 0)
" let g:deoplete#max_menu_width = get(g:, 'deoplete#max_menu_width', 0)
" init deoplet option dict
let g:deoplete#ignore_sources = get(g:,'deoplete#ignore_sources',{})
let g:deoplete#omni#input_patterns = get(g:,'deoplete#omni#input_patterns',{})
@ -13,102 +19,104 @@ let g:deoplete#omni_patterns = get(g:, 'deoplete#omni_patterns', {})
let g:deoplete#keyword_patterns = get(g:, 'deoplete#keyword_patterns', {})
" java && jsp
let g:deoplete#omni#input_patterns.java = get(g:deoplete#omni#input_patterns, 'java', [
\'[^. \t0-9]\.\w*',
\'[^. \t0-9]\->\w*',
\'[^. \t0-9]\::\w*',
\])
let g:deoplete#omni#input_patterns.jsp = get(g:deoplete#omni#input_patterns, 'jsp', ['[^. \t0-9]\.\w*'])
call deoplete#custom#var('omni', 'input_patterns', {
\ 'java': [
\ '[^. \t0-9]\.\w*',
\ '[^. \t0-9]\->\w*',
\ '[^. \t0-9]\::\w*',
\ ],
\ 'jsp': ['[^. \t0-9]\.\w*'],
\})
if g:spacevim_enable_javacomplete2_py
let g:deoplete#ignore_sources.java = get(g:deoplete#ignore_sources, 'java', ['omni'])
call deoplete#custom#option('ignore_sources', {'java': ['omni']})
call deoplete#custom#source('javacomplete2', 'mark', '')
else
let g:deoplete#ignore_sources.java = get(g:deoplete#ignore_sources, 'java', ['javacomplete2', 'around', 'member'])
call deoplete#custom#option('ignore_sources', {'java': ['javacomplete2', 'around', 'member']})
call deoplete#custom#source('omni', 'mark', '')
call deoplete#custom#source('omni', 'rank', 9999)
endif
" sh
let g:deoplete#ignore_sources.sh = get(g:deoplete#ignore_sources, 'sh', ['around', 'member', 'tag', 'syntax'])
call deoplete#custom#option('ignore_sources', {'sh': ['around', 'member', 'tag', 'syntax']})
" go
let g:deoplete#ignore_sources.go = get(g:deoplete#ignore_sources, 'go', ['omni'])
call deoplete#custom#option('ignore_sources', {'go': ['omni']})
call deoplete#custom#source('go', 'mark', '')
call deoplete#custom#source('go', 'rank', 9999)
" markdown
let g:deoplete#ignore_sources.markdown = get(g:deoplete#ignore_sources, 'markdown', ['tag'])
call deoplete#custom#option('ignore_sources', {'markdown': ['tag']})
" perl
let g:deoplete#omni#input_patterns.perl = get(g:deoplete#omni#input_patterns, 'perl', [
\'[^. \t0-9]\.\w*',
\'[^. \t0-9]\->\w*',
\'[^. \t0-9]\::\w*',
\])
call deoplete#custom#var('omni', 'input_patterns', {
\ 'perl': [
\ '[^. \t0-9]\.\w*',
\ '[^. \t0-9]\->\w*',
\ '[^. \t0-9]\::\w*',
\ ],
\})
" javascript
"let g:deoplete#omni#input_patterns.javascript = get(g:deoplete#omni#input_patterns, 'javascript', ['[^. \t0-9]\.\w*'])
let g:deoplete#ignore_sources.javascript = get(g:deoplete#ignore_sources, 'javascript', ['omni'])
call deoplete#custom#option('ignore_sources', {'javascript': ['omni']})
call deoplete#custom#source('ternjs', 'mark', 'tern')
call deoplete#custom#source('ternjs', 'rank', 9999)
" typescript
let g:deoplete#ignore_sources.typescript = get(g:deoplete#ignore_sources, 'typescript', ['tag','omni', 'syntax'])
call deoplete#custom#option('ignore_sources', {'typescript': ['tag','omni', 'syntax']})
call deoplete#custom#source('typescript', 'rank', 9999)
" php two types, 1. phpcd (default) 2. lsp
if SpaceVim#layers#lsp#check_filetype('php')
if has('nvim')
let g:deoplete#ignore_sources.php = get(g:deoplete#ignore_sources, 'php', ['omni', 'around', 'member'])
call deoplete#custom#option('ignore_sources', {'php': ['omni', 'around', 'member']})
else
let g:deoplete#ignore_sources.php = get(g:deoplete#ignore_sources, 'php', ['around', 'member'])
call deoplete#custom#option('ignore_sources', {'php': ['around', 'member']})
endif
else
let g:deoplete#ignore_sources.php = get(g:deoplete#ignore_sources, 'php', ['omni', 'around', 'member'])
call deoplete#custom#option('ignore_sources', {'php': ['omni', 'around', 'member']})
endif
" gitcommit
let g:deoplete#omni#input_patterns.gitcommit = get(g:deoplete#omni#input_patterns, 'gitcommit', [
\'[ ]#[ 0-9a-zA-Z]*',
\])
call deoplete#custom#var('omni', 'input_patterns', {
\ 'gitcommit': [
\ '[ ]#[ 0-9a-zA-Z]*',
\ ],
\})
let g:deoplete#ignore_sources.gitcommit = get(g:deoplete#ignore_sources, 'gitcommit', ['neosnippet'])
call deoplete#custom#option('ignore_sources', {'gitcommit': ['neosnippet']})
" lua
let g:deoplete#omni_patterns.lua = get(g:deoplete#omni_patterns, 'lua', '.')
" c c++
call deoplete#custom#source('clang2', 'mark', '')
let g:deoplete#ignore_sources.c = get(g:deoplete#ignore_sources, 'c', ['omni'])
call deoplete#custom#option('ignore_sources', {'c': ['omni']})
" rust
let g:deoplete#ignore_sources.rust = get(g:deoplete#ignore_sources, 'rust', ['omni'])
call deoplete#custom#option('ignore_sources', {'rust': ['omni']})
call deoplete#custom#source('racer', 'mark', '')
" vim
let g:deoplete#ignore_sources.vim = get(g:deoplete#ignore_sources, 'vim', ['tag'])
call deoplete#custom#option('ignore_sources', {'vim': ['tag']})
" clojure
let g:deoplete#keyword_patterns.clojure = '[\w!$%&*+/:<=>?@\^_~\-\.#]*'
" ocaml
let g:deoplete#ignore_sources.ocaml = ['buffer', 'around', 'omni']
call deoplete#custom#option('ignore_sources', {'ocaml': ['buffer', 'around', 'omni']})
" erlang
let g:deoplete#omni#input_patterns.erlang = get(g:deoplete#omni#input_patterns, 'erlang', [
\'[^. \t0-9]\.\w*',
\])
call deoplete#custom#var('omni', 'input_patterns', {
\ 'erlang': [
\ '[^. \t0-9]\.\w*',
\ ],
\})
" public settings
call deoplete#custom#source('_', 'matchers', ['matcher_full_fuzzy'])
call deoplete#custom#source('file/include', 'matchers', ['matcher_head'])
let g:deoplete#ignore_sources._ = get(g:deoplete#ignore_sources, '_', ['around', 'LanguageClient'])
for key in keys(g:deoplete#ignore_sources)
if key !=# '_' && index(keys(get(g:, 'LanguageClient_serverCommands', {})), key) == -1
let g:deoplete#ignore_sources[key] = g:deoplete#ignore_sources[key] + ['around', 'LanguageClient']
endif
endfor
inoremap <expr><C-h> deoplete#mappings#smart_close_popup()."\<C-h>"
inoremap <expr><BS> deoplete#mappings#smart_close_popup()."\<C-h>"
set isfname-==

View File

@ -48,24 +48,21 @@ SpaceVim 选项 `snippet_engien` 设置为 ultisnips
为了提升用户体验,可以通过使用如下的模块选项来定制自动补全:
- `auto-completion-return-key-behavior` 选项控制当按下 `Return`/`Enter` 键时的行为,
默认为 `smart`可用的值包括如下3种
1. `complete` 补全模式,插入当前选中的列表选项
2. `smart` 智能模式,插入当前选中的列表选项,若当前选择的时 snippet则自动展开代码块。
3. `nil` 当设为 nil 时,则采用 Vim 默认的按键行为,插入新行
- `auto-completion-tab-key-behavior` 选项控制当按下 `Tab` 键时的行为,默认为
`smart`可用的值包括如下4种
1. `smart` 智能模式,自动循环补全列表、展开代码块以及跳至下一个代码块的锚点
2. `complete` 补全模式,插入当前选中的列表选项
3. `cycle` 循环模式,自动再补全列表之间循环
4. `nil` 当设为 nil 时,该行为和 `Tab` 的默认行为一致
- `auto-completion-complete-with-key-sequence` 设置一个手动补全的按键序列,输入模式下按下这一快捷键,
可以启动补全,设为 `nil` 时,这一特性将被禁用。
- `auto-completion-complete-with-key-sequence-delay` 设置手动补全按键序列延迟时间,默认是 0.1
1. `auto-completion-return-key-behavior` 选项控制当按下 `Return`/`Enter` 键时的行为,
默认为 `smart`可用的值包括如下3种
- `complete` 补全模式,插入当前选中的列表选项
- `smart` 智能模式,插入当前选中的列表选项,若当前选择的时 snippet则自动展开代码块。
- `nil` 当设为 nil 时,则采用 Vim 默认的按键行为,插入新行
2. `auto-completion-tab-key-behavior` 选项控制当按下 `Tab` 键时的行为,默认为
`smart`可用的值包括如下4种
- `smart` 智能模式,自动循环补全列表、展开代码块以及跳至下一个代码块的锚点
- `complete` 补全模式,插入当前选中的列表选项
- `cycle` 循环模式,自动再补全列表之间循环
- `nil` 当设为 nil 时,该行为和 `Tab` 的默认行为一致
3. `auto-completion-delay` 设置自动补全延迟时间,默认 50 毫秒
4. `auto-completion-complete-with-key-sequence` 设置一个手动补全的按键序列,输入模式下按下这一快捷键,
可以启动补全,设为 `nil` 时,这一特性将被禁用。
5. `auto-completion-complete-with-key-sequence-delay` 设置手动补全按键序列延迟时间,默认是 0.1
自动补全模块默认载入状态如下:
@ -74,8 +71,9 @@ SpaceVim 选项 `snippet_engien` 设置为 ultisnips
name = "autocomplete"
auto-completion-return-key-behavior = "nil"
auto-completion-tab-key-behavior = "smart"
auto-completion-delay = 200
auto-completion-complete-with-key-sequence = "nil"
auto-completion-complete-with-key-sequence-delay = 0.1
auto-completion-complete-with-key-sequence-delay = 0.1,
```
通常会建议将 `auto-completion-complete-with-key-sequence` 的值设为 `jk`,如果你不用
@ -107,17 +105,17 @@ SpaceVim 选项 `snippet_engien` 设置为 ultisnips
**自动补全相关快捷键**
| 按键 | 描述 |
| ------------ | --------------------------------------------- |
| `<C-n>` | 选择下一个列表选项 |
| `<C-p>` | 选择上一个列表选项 |
| `<Tab>` | 依据 `auto-completion-tab-key-behavior` |
| `<S-Tab>` | 选择上一个列表选项 |
| `<Return>` | 依据 `auto-completion-return-key-behavior` |
| 按键 | 描述 |
| ---------- | ------------------------------------------ |
| `<C-n>` | 选择下一个列表选项 |
| `<C-p>` | 选择上一个列表选项 |
| `<Tab>` | 依据 `auto-completion-tab-key-behavior` |
| `<S-Tab>` | 选择上一个列表选项 |
| `<Return>` | 依据 `auto-completion-return-key-behavior` |
**代码块模板相关快捷键**
| 按键 | 描述 |
| ----------- | -------------------------------------------------------------- |
| `M-/` | 如果光标前的词语为一代码块模板缩写,则展开该代码块 |
| `SPC i s` | 列出所有可用的代码块模板,选择后并插入 |
| 按键 | 描述 |
| --------- | -------------------------------------------------- |
| `M-/` | 如果光标前的词语为一代码块模板缩写,则展开该代码块 |
| `SPC i s` | 列出所有可用的代码块模板,选择后并插入 |

View File

@ -26,10 +26,10 @@ This layer provides auto-completion to SpaceVim.
The following completion engines are supported:
- [neocomplete](https://github.com/Shougo/neocomplete.vim) - vim with `+lua`
- [neocomplcache](https://github.com/Shougo/neocomplcache.vim) - vim without `+lua`
- [deoplete](https://github.com/Shougo/deoplete.nvim) - neovim with `+python3`
- [YouCompleteMe](https://github.com/Valloric/YouCompleteMe) - disabled by default, to enable ycm, see `:h g:spacevim_enable_ycm`
- [neocomplete](https://github.com/Shougo/neocomplete.vim) - vim with `+lua`
- [neocomplcache](https://github.com/Shougo/neocomplcache.vim) - vim without `+lua`
- [deoplete](https://github.com/Shougo/deoplete.nvim) - neovim with `+python3`
- [YouCompleteMe](https://github.com/Valloric/YouCompleteMe) - disabled by default, to enable ycm, see `:h g:spacevim_enable_ycm`
Snippets are supported via [neosnippet](https://github.com/Shougo/neosnippet.vim).
@ -48,31 +48,29 @@ To use this configuration layer, add following snippet to your custom configurat
You can customize the user experience of auto-completion with the following layer variables:
1. `auto-completion-return-key-behavior` set the action to perform when the `Return`/`Enter` key is pressed, the possible values are:
- `complete` completes with the current selection
- `smart` completes with current selection and expand snippet or argvs
- `nil`
2. `auto-completion-tab-key-behavior` set the action to perform when the `TAB` key is pressed, the possible values are:
- `smart` cycle candidates, expand snippets, jump parameters
- `complete` completes with the current selection
- `cycle` completes the common prefix and cycle between candidates
- `nil` insert a carriage return
3. `auto-completion-complete-with-key-sequence` is a string of two characters denoting a key sequence that will perform a `complete` action if the sequence as been entered quickly enough. If its value is `nil` then the feature is disabled.
4. `auto-completion-complete-with-key-sequence-delay` is the number of seconds to wait for the auto-completion key sequence to be entered. The default value is 0.1 seconds.
1. `auto-completion-return-key-behavior` set the action to perform when the `Return`/`Enter` key is pressed, the possible values are:
- `complete` completes with the current selection
- `smart` completes with current selection and expand snippet or argvs
- `nil`
2. `auto-completion-tab-key-behavior` set the action to perform when the `TAB` key is pressed, the possible values are:
- `smart` cycle candidates, expand snippets, jump parameters
- `complete` completes with the current selection
- `cycle` completes the common prefix and cycle between candidates
- `nil` insert a carriage return
3. `auto-completion-delay` is a number to delay the completion after input in milliseconds, by default it is 50 ms.
4. `auto-completion-complete-with-key-sequence` is a string of two characters denoting a key sequence that will perform a `complete` action if the sequence as been entered quickly enough. If its value is `nil` then the feature is disabled.
5. `auto-completion-complete-with-key-sequence-delay` is the number of seconds to wait for the auto-completion key sequence to be entered. The default value is 0.1 seconds.
The default configuration of the layer is:
```vim
call SpaceVim#layers#load('autocomplete', {
\ 'auto-completion-return-key-behavior' : 'nil',
\ 'auto-completion-tab-key-behavior' : 'smart',
\ 'auto-completion-complete-with-key-sequence' : 'nil',
\ 'auto-completion-complete-with-key-sequence-delay' : 0.1,
\ })
```toml
[[layers]]
name = "autocomplete"
auto-completion-return-key-behavior = "nil"
auto-completion-tab-key-behavior = "smart"
auto-completion-delay = 200
auto-completion-complete-with-key-sequence = "nil"
auto-completion-complete-with-key-sequence-delay = 0.1,
```
`jk` is a good candidate for `auto-completion-complete-with-key-sequence` if you dont use it already.
@ -81,11 +79,11 @@ call SpaceVim#layers#load('autocomplete', {
The following snippets or directories are added by default:
- [Shougo/neosnippet-snippets](https://github.com/Shougo/neosnippet-snippets) : neosnippet's default snippets.
- [honza/vim-snippets](https://github.com/honza/vim-snippets) : extra snippets
- `~/.SpaceVim/snippets/` : SpaceVim runtime snippets.
- `~/.SpaceVim.d/snippets/` : custom global snippets.
- `./.SpaceVim.d/snippets/` : custom local snippets (project's snippets)
- [Shougo/neosnippet-snippets](https://github.com/Shougo/neosnippet-snippets) : neosnippet's default snippets.
- [honza/vim-snippets](https://github.com/honza/vim-snippets) : extra snippets
- `~/.SpaceVim/snippets/` : SpaceVim runtime snippets.
- `~/.SpaceVim.d/snippets/` : custom global snippets.
- `./.SpaceVim.d/snippets/` : custom local snippets (project's snippets)
You can provide additional directories by setting the variable `g:neosnippet#snippets_directory` which can take a string in case of a single path or a list of paths.

View File

@ -7,6 +7,7 @@ The next release is v1.0.0.
### Added
- Add unicode#spinners api ([#1926](https://github.com/SpaceVim/SpaceVim/pull/1926))
- Add layer option for autocomplete layer ([#2236](https://github.com/SpaceVim/SpaceVim/pull/2236))
### Improvement