mirror of
https://github.com/prabirshrestha/asyncomplete.vim.git
synced 2025-12-14 20:35:41 +01:00
Add setting for minimum string length to trigger auto popup (#135)
* Add setting for minimum string length to trigger auto popup * Use ternary * Use simplified function * Fix bug in new return function * Add documentation for min_chars * Add buffer override for min_chars
This commit is contained in:
@@ -259,6 +259,14 @@ function! asyncomplete#cancel_popup() abort
|
||||
return pumvisible() ? "\<C-e>" : ''
|
||||
endfunction
|
||||
|
||||
function! s:get_min_chars(source_name) abort
|
||||
if exists('b:asyncomplete_min_chars')
|
||||
return b:asyncomplete_min_chars
|
||||
else
|
||||
return get(s:sources[a:source_name], 'min_chars', g:asyncomplete_min_chars)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! s:on_change() abort
|
||||
if s:should_skip() | return | endif
|
||||
|
||||
@@ -288,11 +296,12 @@ function! s:on_change() abort
|
||||
let l:refresh_pattern = get(b:, 'asyncomplete_refresh_pattern', '\(\k\+$\)')
|
||||
let [l:_, l:startidx, l:endidx] = asyncomplete#utils#matchstrpos(l:ctx['typed'], l:refresh_pattern)
|
||||
let l:startcol = l:startidx + 1
|
||||
let l:typed_len = l:endidx - l:startidx
|
||||
|
||||
if l:startidx > -1
|
||||
if s:should_skip_popup() | return | endif
|
||||
for l:source_name in b:asyncomplete_active_sources
|
||||
if !has_key(l:sources_to_notify, l:source_name)
|
||||
if l:typed_len >= s:get_min_chars(l:source_name) && !has_key(l:sources_to_notify, l:source_name)
|
||||
if has_key(s:matches, l:source_name) && s:matches[l:source_name]['ctx']['lnum'] ==# l:ctx['lnum'] && s:matches[l:source_name]['startcol'] ==# l:startcol
|
||||
continue
|
||||
endif
|
||||
|
||||
@@ -87,6 +87,14 @@ g:asyncomplete_preprocessor *g:asyncomplete_preprocessor*
|
||||
|
||||
context and matches in arguments in preprecessor function should be treated
|
||||
as immutable.
|
||||
|
||||
g:asyncomplete_min_chars *g:asyncomplete_min_chars*
|
||||
|
||||
Type: |Number|
|
||||
Default: 1
|
||||
|
||||
Minimum consecutive characters to trigger auto-popup. Overridden by buffer
|
||||
variable if set (`b:asyncomplete_min_chars`)
|
||||
===============================================================================
|
||||
3. Functions *asyncomplete-functions*
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ endif
|
||||
let g:asyncomplete_manager = get(g:, 'asyncomplete_manager', 'asyncomplete#managers#vim#init')
|
||||
let g:asyncomplete_change_manager = get(g:, 'asyncomplete_change_manager', ['asyncomplete#utils#_on_change#textchangedp#init', 'asyncomplete#utils#_on_change#timer#init'])
|
||||
let g:asyncomplete_triggers = get(g:, 'asyncomplete_triggers', {'*': ['.', '>', ':'] })
|
||||
let g:asyncomplete_min_chars = get(g:, 'asyncomplete_min_chars', 1)
|
||||
|
||||
let g:asyncomplete_auto_completeopt = get(g:, 'asyncomplete_auto_completeopt', 1)
|
||||
let g:asyncomplete_auto_popup = get(g:, 'asyncomplete_auto_popup', 1)
|
||||
|
||||
Reference in New Issue
Block a user