From fc2530cd80d67bc05d88bd666889390baf6046d4 Mon Sep 17 00:00:00 2001 From: thecontinium Date: Tue, 31 Mar 2020 21:29:32 +0100 Subject: [PATCH 01/22] search on iskeyword & refresh words when starting --- autoload/asyncomplete/sources/buffer.vim | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/autoload/asyncomplete/sources/buffer.vim b/autoload/asyncomplete/sources/buffer.vim index 20ab961..d9a5c9e 100644 --- a/autoload/asyncomplete/sources/buffer.vim +++ b/autoload/asyncomplete/sources/buffer.vim @@ -26,7 +26,7 @@ endfunction function! asyncomplete#sources#buffer#get_source_options(opts) return extend({ - \ 'events': ['BufWinEnter'], + \ 'events': ['VimEnter', 'BufWinEnter'], \ 'on_event': function('s:on_event'), \}, a:opts) endfunction @@ -50,10 +50,7 @@ endfunction let s:last_ctx = {} function! s:on_event(opt, ctx, event) abort if s:should_ignore(a:opt) | return | endif - - if a:event == 'BufWinEnter' - call s:refresh_keywords() - endif + call s:refresh_keywords() endfunction function! s:refresh_keywords() abort @@ -61,7 +58,7 @@ function! s:refresh_keywords() abort let s:words = {} endif let l:text = join(getline(1, '$'), "\n") - for l:word in split(l:text, '\W\+') + for l:word in split(l:text, '\k\+') if len(l:word) > 1 let s:words[l:word] = 1 endif @@ -70,7 +67,7 @@ function! s:refresh_keywords() abort endfunction function! s:refresh_keyword_incremental(typed) abort - let l:words = split(a:typed, '\W\+') + let l:words = split(a:typed, '\k\+') for l:word in l:words if len(l:word) > 1 From f62493160cabda4b5d622c3f9965b991b088f8fa Mon Sep 17 00:00:00 2001 From: thecontinium Date: Tue, 31 Mar 2020 21:52:01 +0100 Subject: [PATCH 02/22] search on iskeyword & refresh words when starting --- autoload/asyncomplete/sources/buffer.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/autoload/asyncomplete/sources/buffer.vim b/autoload/asyncomplete/sources/buffer.vim index d9a5c9e..9529a20 100644 --- a/autoload/asyncomplete/sources/buffer.vim +++ b/autoload/asyncomplete/sources/buffer.vim @@ -15,7 +15,7 @@ function! asyncomplete#sources#buffer#completor(opt, ctx) let l:col = a:ctx['col'] - let l:kw = matchstr(l:typed, '\w\+$') + let l:kw = matchstr(l:typed, '\k@!\+') let l:kwlen = len(l:kw) let l:matches = map(keys(s:words),'{"word":v:val,"dup":1,"icase":1,"menu": "[buffer]"}') @@ -58,7 +58,7 @@ function! s:refresh_keywords() abort let s:words = {} endif let l:text = join(getline(1, '$'), "\n") - for l:word in split(l:text, '\k\+') + for l:word in split(l:text, '\k@!\+') if len(l:word) > 1 let s:words[l:word] = 1 endif From 50786e77b88d6bae7b81e51c22472f64c9f15fd3 Mon Sep 17 00:00:00 2001 From: thecontinium Date: Wed, 1 Apr 2020 13:39:18 +0100 Subject: [PATCH 03/22] changed regex --- autoload/asyncomplete/sources/buffer.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/autoload/asyncomplete/sources/buffer.vim b/autoload/asyncomplete/sources/buffer.vim index 9529a20..7944c91 100644 --- a/autoload/asyncomplete/sources/buffer.vim +++ b/autoload/asyncomplete/sources/buffer.vim @@ -15,7 +15,7 @@ function! asyncomplete#sources#buffer#completor(opt, ctx) let l:col = a:ctx['col'] - let l:kw = matchstr(l:typed, '\k@!\+') + let l:kw = matchstr(l:typed, '\k\@!') let l:kwlen = len(l:kw) let l:matches = map(keys(s:words),'{"word":v:val,"dup":1,"icase":1,"menu": "[buffer]"}') @@ -58,7 +58,7 @@ function! s:refresh_keywords() abort let s:words = {} endif let l:text = join(getline(1, '$'), "\n") - for l:word in split(l:text, '\k@!\+') + for l:word in split(l:text, '\k\@!') if len(l:word) > 1 let s:words[l:word] = 1 endif From d390b3f2b958ed20f1b8e5fb61b8f74a91ce946c Mon Sep 17 00:00:00 2001 From: thecontinium Date: Wed, 1 Apr 2020 13:43:42 +0100 Subject: [PATCH 04/22] all regex --- autoload/asyncomplete/sources/buffer.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autoload/asyncomplete/sources/buffer.vim b/autoload/asyncomplete/sources/buffer.vim index 7944c91..cdf7cc3 100644 --- a/autoload/asyncomplete/sources/buffer.vim +++ b/autoload/asyncomplete/sources/buffer.vim @@ -67,7 +67,7 @@ function! s:refresh_keywords() abort endfunction function! s:refresh_keyword_incremental(typed) abort - let l:words = split(a:typed, '\k\+') + let l:words = split(a:typed, '\k\@!') for l:word in l:words if len(l:word) > 1 From 3fc1a17599398e08ea9a1c23b3288d16eaedc4ee Mon Sep 17 00:00:00 2001 From: thecontinium Date: Wed, 1 Apr 2020 14:02:19 +0100 Subject: [PATCH 05/22] added global regex option --- autoload/asyncomplete/sources/buffer.vim | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/autoload/asyncomplete/sources/buffer.vim b/autoload/asyncomplete/sources/buffer.vim index cdf7cc3..97c6fff 100644 --- a/autoload/asyncomplete/sources/buffer.vim +++ b/autoload/asyncomplete/sources/buffer.vim @@ -1,6 +1,7 @@ let s:words = {} let s:last_word = '' let g:asyncomplete_buffer_clear_cache = get(g:, 'asyncomplete_buffer_clear_cache', 1) +let g:asyncomplete_buffer_split_regex = get(g:, 'asyncomplete_buffer_split_regex', '\W\+') function! asyncomplete#sources#buffer#completor(opt, ctx) let l:typed = a:ctx['typed'] @@ -58,7 +59,7 @@ function! s:refresh_keywords() abort let s:words = {} endif let l:text = join(getline(1, '$'), "\n") - for l:word in split(l:text, '\k\@!') + for l:word in split(l:text, g:asyncomplete_buffer_split_regex) if len(l:word) > 1 let s:words[l:word] = 1 endif @@ -67,8 +68,7 @@ function! s:refresh_keywords() abort endfunction function! s:refresh_keyword_incremental(typed) abort - let l:words = split(a:typed, '\k\@!') - + let l:words = split(a:typed, g:asyncomplete_buffer_split_regex) for l:word in l:words if len(l:word) > 1 let s:words[l:word] = 1 From a1c7abc8015cecc0988f86447fa3c0a14572cdf0 Mon Sep 17 00:00:00 2001 From: thecontinium Date: Wed, 1 Apr 2020 14:08:50 +0100 Subject: [PATCH 06/22] added custom regex --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index db37587..71e2cbc 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,13 @@ Clear buffer word cache on events (default: `1`) let g:asyncomplete_buffer_clear_cache = 1 ``` +Custom regex to dedide how to identify non word characters (defaults: '\W\+') +```vim +let g:asyncomplete_buffer_split_regex = get(g:, 'asyncomplete_buffer_split_regex', '\W\+') +``` + + + ### Credits All the credit goes to the following projects * [https://github.com/roxma/nvim-complete-manager](https://github.com/roxma/nvim-complete-manager) From 9cd01338a2d989aa04d3c068e7aac9a1a08580f7 Mon Sep 17 00:00:00 2001 From: thecontinium Date: Wed, 1 Apr 2020 14:39:18 +0100 Subject: [PATCH 07/22] added word and non word regex --- autoload/asyncomplete/sources/buffer.vim | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/autoload/asyncomplete/sources/buffer.vim b/autoload/asyncomplete/sources/buffer.vim index 97c6fff..db6ef5b 100644 --- a/autoload/asyncomplete/sources/buffer.vim +++ b/autoload/asyncomplete/sources/buffer.vim @@ -1,7 +1,8 @@ let s:words = {} let s:last_word = '' let g:asyncomplete_buffer_clear_cache = get(g:, 'asyncomplete_buffer_clear_cache', 1) -let g:asyncomplete_buffer_split_regex = get(g:, 'asyncomplete_buffer_split_regex', '\W\+') +let g:asyncomplete_buffer_identify_non_words_regex = get(g:, 'asyncomplete_buffer_identify_non_workds_regex', '\W\+') +let g:asyncomplete_buffer_identify_words_regex = get(g:, 'asyncomplete_buffer_identify_words_regex', '\w\+$') function! asyncomplete#sources#buffer#completor(opt, ctx) let l:typed = a:ctx['typed'] @@ -16,7 +17,7 @@ function! asyncomplete#sources#buffer#completor(opt, ctx) let l:col = a:ctx['col'] - let l:kw = matchstr(l:typed, '\k\@!') + let l:kw = matchstr(l:typed, g:asyncomplete_buffer_identify_words_regex) let l:kwlen = len(l:kw) let l:matches = map(keys(s:words),'{"word":v:val,"dup":1,"icase":1,"menu": "[buffer]"}') From dbcbfdc9ab809bb204bdc5e4e411a344fdd91523 Mon Sep 17 00:00:00 2001 From: thecontinium Date: Wed, 1 Apr 2020 14:47:36 +0100 Subject: [PATCH 08/22] corrected name of non word regex --- autoload/asyncomplete/sources/buffer.vim | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/autoload/asyncomplete/sources/buffer.vim b/autoload/asyncomplete/sources/buffer.vim index db6ef5b..f208111 100644 --- a/autoload/asyncomplete/sources/buffer.vim +++ b/autoload/asyncomplete/sources/buffer.vim @@ -1,7 +1,7 @@ let s:words = {} let s:last_word = '' let g:asyncomplete_buffer_clear_cache = get(g:, 'asyncomplete_buffer_clear_cache', 1) -let g:asyncomplete_buffer_identify_non_words_regex = get(g:, 'asyncomplete_buffer_identify_non_workds_regex', '\W\+') +let g:asyncomplete_buffer_identify_non_words_regex = get(g:, 'asyncomplete_buffer_identify_non_words_regex', '\W\+') let g:asyncomplete_buffer_identify_words_regex = get(g:, 'asyncomplete_buffer_identify_words_regex', '\w\+$') function! asyncomplete#sources#buffer#completor(opt, ctx) @@ -60,7 +60,7 @@ function! s:refresh_keywords() abort let s:words = {} endif let l:text = join(getline(1, '$'), "\n") - for l:word in split(l:text, g:asyncomplete_buffer_split_regex) + for l:word in split(l:text, g:asyncomplete_buffer_identify_non_words_regex) if len(l:word) > 1 let s:words[l:word] = 1 endif @@ -69,7 +69,7 @@ function! s:refresh_keywords() abort endfunction function! s:refresh_keyword_incremental(typed) abort - let l:words = split(a:typed, g:asyncomplete_buffer_split_regex) + let l:words = split(a:typed,g:asyncomplete_buffer_identify_non_words_regex) for l:word in l:words if len(l:word) > 1 let s:words[l:word] = 1 From b5318014641f73fe79255b5ef2278edfe1dda3ac Mon Sep 17 00:00:00 2001 From: thecontinium Date: Wed, 1 Apr 2020 18:59:50 +0100 Subject: [PATCH 09/22] use one regex --- autoload/asyncomplete/sources/buffer.vim | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/autoload/asyncomplete/sources/buffer.vim b/autoload/asyncomplete/sources/buffer.vim index f208111..66846ca 100644 --- a/autoload/asyncomplete/sources/buffer.vim +++ b/autoload/asyncomplete/sources/buffer.vim @@ -2,7 +2,7 @@ let s:words = {} let s:last_word = '' let g:asyncomplete_buffer_clear_cache = get(g:, 'asyncomplete_buffer_clear_cache', 1) let g:asyncomplete_buffer_identify_non_words_regex = get(g:, 'asyncomplete_buffer_identify_non_words_regex', '\W\+') -let g:asyncomplete_buffer_identify_words_regex = get(g:, 'asyncomplete_buffer_identify_words_regex', '\w\+$') +let g:asyncomplete_buffer_identify_words_regex = get(g:, 'asyncomplete_buffer_identify_words_regex', '\w\+') function! asyncomplete#sources#buffer#completor(opt, ctx) let l:typed = a:ctx['typed'] @@ -17,7 +17,7 @@ function! asyncomplete#sources#buffer#completor(opt, ctx) let l:col = a:ctx['col'] - let l:kw = matchstr(l:typed, g:asyncomplete_buffer_identify_words_regex) + let l:kw = matchstr(l:typed, g:asyncomplete_buffer_identify_words_regex.'$') let l:kwlen = len(l:kw) let l:matches = map(keys(s:words),'{"word":v:val,"dup":1,"icase":1,"menu": "[buffer]"}') @@ -60,7 +60,7 @@ function! s:refresh_keywords() abort let s:words = {} endif let l:text = join(getline(1, '$'), "\n") - for l:word in split(l:text, g:asyncomplete_buffer_identify_non_words_regex) + for l:word in map(split(l:text, g:asyncomplete_buffer_identify_words_regex.'\zs'),matchstr(v:val,g:asyncomplete_buffer_identify_words_regex)) if len(l:word) > 1 let s:words[l:word] = 1 endif @@ -69,7 +69,7 @@ function! s:refresh_keywords() abort endfunction function! s:refresh_keyword_incremental(typed) abort - let l:words = split(a:typed,g:asyncomplete_buffer_identify_non_words_regex) + let l:words = map(split(a:typed, g:asyncomplete_buffer_identify_words_regex.'\zs'),matchstr(v:val,g:asyncomplete_buffer_identify_words_regex)) for l:word in l:words if len(l:word) > 1 let s:words[l:word] = 1 From da83b6d4a78cc6b096b99673f9137decbbe5cc2e Mon Sep 17 00:00:00 2001 From: thecontinium Date: Wed, 1 Apr 2020 19:10:42 +0100 Subject: [PATCH 10/22] corrected map function --- autoload/asyncomplete/sources/buffer.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/autoload/asyncomplete/sources/buffer.vim b/autoload/asyncomplete/sources/buffer.vim index 66846ca..c25b76f 100644 --- a/autoload/asyncomplete/sources/buffer.vim +++ b/autoload/asyncomplete/sources/buffer.vim @@ -60,7 +60,7 @@ function! s:refresh_keywords() abort let s:words = {} endif let l:text = join(getline(1, '$'), "\n") - for l:word in map(split(l:text, g:asyncomplete_buffer_identify_words_regex.'\zs'),matchstr(v:val,g:asyncomplete_buffer_identify_words_regex)) + for l:word in map(split(l:text, g:asyncomplete_buffer_identify_words_regex.'\zs'),'matchstr(v:val,g:asyncomplete_buffer_identify_words_regex)') if len(l:word) > 1 let s:words[l:word] = 1 endif @@ -69,7 +69,7 @@ function! s:refresh_keywords() abort endfunction function! s:refresh_keyword_incremental(typed) abort - let l:words = map(split(a:typed, g:asyncomplete_buffer_identify_words_regex.'\zs'),matchstr(v:val,g:asyncomplete_buffer_identify_words_regex)) + let l:words = map(split(a:typed, g:asyncomplete_buffer_identify_words_regex.'\zs'),'matchstr(v:val,g:asyncomplete_buffer_identify_words_regex)') for l:word in l:words if len(l:word) > 1 let s:words[l:word] = 1 From 80f5a26844c10b558925614861a14ebdb459c34e Mon Sep 17 00:00:00 2001 From: thecontinium Date: Thu, 2 Apr 2020 12:12:26 +0100 Subject: [PATCH 11/22] add some more logging --- autoload/asyncomplete/sources/buffer.vim | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/autoload/asyncomplete/sources/buffer.vim b/autoload/asyncomplete/sources/buffer.vim index c25b76f..39cba23 100644 --- a/autoload/asyncomplete/sources/buffer.vim +++ b/autoload/asyncomplete/sources/buffer.vim @@ -1,8 +1,7 @@ let s:words = {} let s:last_word = '' let g:asyncomplete_buffer_clear_cache = get(g:, 'asyncomplete_buffer_clear_cache', 1) -let g:asyncomplete_buffer_identify_non_words_regex = get(g:, 'asyncomplete_buffer_identify_non_words_regex', '\W\+') -let g:asyncomplete_buffer_identify_words_regex = get(g:, 'asyncomplete_buffer_identify_words_regex', '\w\+') +let g:asyncomplete_buffer_identify_words_regex = get(g:, 'asyncomplete_buffer_identify_words_regex', '\w\+') function! asyncomplete#sources#buffer#completor(opt, ctx) let l:typed = a:ctx['typed'] @@ -69,7 +68,9 @@ function! s:refresh_keywords() abort endfunction function! s:refresh_keyword_incremental(typed) abort + call asyncomplete#log('asyncomplete#sources#buffer', 'typed words ', a:typed) let l:words = map(split(a:typed, g:asyncomplete_buffer_identify_words_regex.'\zs'),'matchstr(v:val,g:asyncomplete_buffer_identify_words_regex)') + call asyncomplete#log('asyncomplete#sources#buffer', 'refreshing words with ', l:words) for l:word in l:words if len(l:word) > 1 let s:words[l:word] = 1 From a8d6a9f7e303c75d49c27864fa2c5891fed386dc Mon Sep 17 00:00:00 2001 From: thecontinium Date: Thu, 2 Apr 2020 18:20:42 +0100 Subject: [PATCH 12/22] try adding with 1 char --- autoload/asyncomplete/sources/buffer.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/autoload/asyncomplete/sources/buffer.vim b/autoload/asyncomplete/sources/buffer.vim index 39cba23..1e42882 100644 --- a/autoload/asyncomplete/sources/buffer.vim +++ b/autoload/asyncomplete/sources/buffer.vim @@ -72,8 +72,8 @@ function! s:refresh_keyword_incremental(typed) abort let l:words = map(split(a:typed, g:asyncomplete_buffer_identify_words_regex.'\zs'),'matchstr(v:val,g:asyncomplete_buffer_identify_words_regex)') call asyncomplete#log('asyncomplete#sources#buffer', 'refreshing words with ', l:words) for l:word in l:words - if len(l:word) > 1 + " if len(l:word) > 1 let s:words[l:word] = 1 - endif + " endif endfor endfunction From b0e0565dd87b20bbdde10858b0aca291be2a6603 Mon Sep 17 00:00:00 2001 From: thecontinium Date: Thu, 2 Apr 2020 18:53:06 +0100 Subject: [PATCH 13/22] partial --- autoload/asyncomplete/sources/buffer.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autoload/asyncomplete/sources/buffer.vim b/autoload/asyncomplete/sources/buffer.vim index 1e42882..49ad62f 100644 --- a/autoload/asyncomplete/sources/buffer.vim +++ b/autoload/asyncomplete/sources/buffer.vim @@ -22,7 +22,7 @@ function! asyncomplete#sources#buffer#completor(opt, ctx) let l:matches = map(keys(s:words),'{"word":v:val,"dup":1,"icase":1,"menu": "[buffer]"}') let l:startcol = l:col - l:kwlen - call asyncomplete#complete(a:opt['name'], a:ctx, l:startcol, l:matches) + call asyncomplete#complete(a:opt['name'], a:ctx, l:startcol, l:matches, 1) endfunction function! asyncomplete#sources#buffer#get_source_options(opts) From d4fd68fa4352b24b27c0246e8b72af6676468b8b Mon Sep 17 00:00:00 2001 From: thecontinium Date: Thu, 2 Apr 2020 21:42:11 +0100 Subject: [PATCH 14/22] x --- autoload/asyncomplete/sources/buffer.vim | 1 + 1 file changed, 1 insertion(+) diff --git a/autoload/asyncomplete/sources/buffer.vim b/autoload/asyncomplete/sources/buffer.vim index 49ad62f..93e59aa 100644 --- a/autoload/asyncomplete/sources/buffer.vim +++ b/autoload/asyncomplete/sources/buffer.vim @@ -4,6 +4,7 @@ let g:asyncomplete_buffer_clear_cache = get(g:, 'asyncomplete_buffer_clear_cache let g:asyncomplete_buffer_identify_words_regex = get(g:, 'asyncomplete_buffer_identify_words_regex', '\w\+') function! asyncomplete#sources#buffer#completor(opt, ctx) + call asyncomplete#log('asyncomplete#buffer ctx', a:ctx) let l:typed = a:ctx['typed'] call s:refresh_keyword_incremental(l:typed) From a208440e12738abf73ba1df0c5778939874bb5bd Mon Sep 17 00:00:00 2001 From: thecontinium Date: Fri, 3 Apr 2020 15:28:47 +0100 Subject: [PATCH 15/22] add a line at a time --- autoload/asyncomplete/sources/buffer.vim | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/autoload/asyncomplete/sources/buffer.vim b/autoload/asyncomplete/sources/buffer.vim index 93e59aa..8edc365 100644 --- a/autoload/asyncomplete/sources/buffer.vim +++ b/autoload/asyncomplete/sources/buffer.vim @@ -49,7 +49,6 @@ function! s:should_ignore(opt) abort return 0 endfunction -let s:last_ctx = {} function! s:on_event(opt, ctx, event) abort if s:should_ignore(a:opt) | return | endif call s:refresh_keywords() @@ -68,13 +67,19 @@ function! s:refresh_keywords() abort call asyncomplete#log('asyncomplete#buffer', 's:refresh_keywords() complete') endfunction + +let s:last_typed = '' function! s:refresh_keyword_incremental(typed) abort call asyncomplete#log('asyncomplete#sources#buffer', 'typed words ', a:typed) - let l:words = map(split(a:typed, g:asyncomplete_buffer_identify_words_regex.'\zs'),'matchstr(v:val,g:asyncomplete_buffer_identify_words_regex)') - call asyncomplete#log('asyncomplete#sources#buffer', 'refreshing words with ', l:words) - for l:word in l:words - " if len(l:word) > 1 - let s:words[l:word] = 1 - " endif - endfor + if (len(a:typed) == 1) + let l:words = map(split(s:last_typed, g:asyncomplete_buffer_identify_words_regex.'\zs'),'matchstr(v:val,g:asyncomplete_buffer_identify_words_regex)') + call asyncomplete#log('asyncomplete#sources#buffer', 'refreshing words with ', l:words) + for l:word in l:words + if len(l:word) > 1 + let s:words[l:word] = 1 + endif + endfor + else + let s:last_typed = a:typed + endif endfunction From 5d77b99dea7b79fb15b28a48fa52aae85f1482aa Mon Sep 17 00:00:00 2001 From: thecontinium Date: Fri, 3 Apr 2020 15:56:54 +0100 Subject: [PATCH 16/22] changed to TextChangedI --- autoload/asyncomplete/sources/buffer.vim | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/autoload/asyncomplete/sources/buffer.vim b/autoload/asyncomplete/sources/buffer.vim index 8edc365..09ff62f 100644 --- a/autoload/asyncomplete/sources/buffer.vim +++ b/autoload/asyncomplete/sources/buffer.vim @@ -5,9 +5,6 @@ let g:asyncomplete_buffer_identify_words_regex = get(g:, 'asyncomplete_buffer_id function! asyncomplete#sources#buffer#completor(opt, ctx) call asyncomplete#log('asyncomplete#buffer ctx', a:ctx) - let l:typed = a:ctx['typed'] - - call s:refresh_keyword_incremental(l:typed) if empty(s:words) return @@ -23,12 +20,12 @@ function! asyncomplete#sources#buffer#completor(opt, ctx) let l:matches = map(keys(s:words),'{"word":v:val,"dup":1,"icase":1,"menu": "[buffer]"}') let l:startcol = l:col - l:kwlen - call asyncomplete#complete(a:opt['name'], a:ctx, l:startcol, l:matches, 1) + call asyncomplete#complete(a:opt['name'], a:ctx, l:startcol, l:matches) endfunction function! asyncomplete#sources#buffer#get_source_options(opts) return extend({ - \ 'events': ['VimEnter', 'BufWinEnter'], + \ 'events': ['TextChangedI', 'VimEnter', 'BufWinEnter'], \ 'on_event': function('s:on_event'), \}, a:opts) endfunction @@ -50,8 +47,13 @@ function! s:should_ignore(opt) abort endfunction function! s:on_event(opt, ctx, event) abort - if s:should_ignore(a:opt) | return | endif - call s:refresh_keywords() + if (a:event ==# 'TextChangedI') + let l:typed = a:ctx['typed'] + call s:refresh_keyword_incremental(l:typed) + else + if s:should_ignore(a:opt) | return | endif + call s:refresh_keywords() + endif endfunction function! s:refresh_keywords() abort From a58c3856effca94ea89c9f1d608e35de76489f50 Mon Sep 17 00:00:00 2001 From: thecontinium Date: Fri, 3 Apr 2020 16:03:10 +0100 Subject: [PATCH 17/22] . --- autoload/asyncomplete/sources/buffer.vim | 1 + 1 file changed, 1 insertion(+) diff --git a/autoload/asyncomplete/sources/buffer.vim b/autoload/asyncomplete/sources/buffer.vim index 09ff62f..e3be584 100644 --- a/autoload/asyncomplete/sources/buffer.vim +++ b/autoload/asyncomplete/sources/buffer.vim @@ -14,6 +14,7 @@ function! asyncomplete#sources#buffer#completor(opt, ctx) let l:col = a:ctx['col'] + let l:typed = a:ctx['typed'] let l:kw = matchstr(l:typed, g:asyncomplete_buffer_identify_words_regex.'$') let l:kwlen = len(l:kw) From 5784499f5c6ab2a2eda576dda49f6ae931e5e858 Mon Sep 17 00:00:00 2001 From: thecontinium Date: Fri, 3 Apr 2020 16:46:06 +0100 Subject: [PATCH 18/22] reverted to working model --- autoload/asyncomplete/sources/buffer.vim | 58 ++++++++++++------------ 1 file changed, 30 insertions(+), 28 deletions(-) diff --git a/autoload/asyncomplete/sources/buffer.vim b/autoload/asyncomplete/sources/buffer.vim index e3be584..28703b9 100644 --- a/autoload/asyncomplete/sources/buffer.vim +++ b/autoload/asyncomplete/sources/buffer.vim @@ -11,14 +11,22 @@ function! asyncomplete#sources#buffer#completor(opt, ctx) endif let l:matches = [] - let l:col = a:ctx['col'] - let l:typed = a:ctx['typed'] - let l:kw = matchstr(l:typed, g:asyncomplete_buffer_identify_words_regex.'$') + + let l:kw = matchstr(l:typed, '\w\+$') let l:kwlen = len(l:kw) - let l:matches = map(keys(s:words),'{"word":v:val,"dup":1,"icase":1,"menu": "[buffer]"}') + if l:kwlen < 1 + return + endif + + let l:words = keys(s:words) + if !empty(s:last_word) && l:kw !=? s:last_word && !has_key(s:words, s:last_word) + let l:words += [s:last_word] + endif + + let l:matches = map(l:words,'{"word":v:val,"dup":1,"icase":1,"menu": "[buffer]"}') let l:startcol = l:col - l:kwlen call asyncomplete#complete(a:opt['name'], a:ctx, l:startcol, l:matches) @@ -26,12 +34,13 @@ endfunction function! asyncomplete#sources#buffer#get_source_options(opts) return extend({ - \ 'events': ['TextChangedI', 'VimEnter', 'BufWinEnter'], + \ 'events': ['CursorHold','CursorHoldI','BufWinEnter','BufWritePost','TextChangedI'], \ 'on_event': function('s:on_event'), \}, a:opts) endfunction -function! s:should_ignore(opt) abort +let s:last_ctx = {} +function! s:on_event(opt, ctx, event) abort let l:max_buffer_size = 5000000 " 5mb if has_key(a:opt, 'config') && has_key(a:opt['config'], 'max_buffer_size') let l:max_buffer_size = a:opt['config']['max_buffer_size'] @@ -40,19 +49,17 @@ function! s:should_ignore(opt) abort let l:buffer_size = line2byte(line('$') + 1) if l:buffer_size > l:max_buffer_size call asyncomplete#log('asyncomplete#sources#buffer', 'ignoring buffer autocomplete due to large size', expand('%:p'), l:buffer_size) - return 1 + return endif endif - return 0 -endfunction - -function! s:on_event(opt, ctx, event) abort - if (a:event ==# 'TextChangedI') - let l:typed = a:ctx['typed'] - call s:refresh_keyword_incremental(l:typed) + if a:event == 'TextChangedI' + call s:refresh_keyword_incr(a:ctx['typed']) else - if s:should_ignore(a:opt) | return | endif + if s:last_ctx == a:ctx + return + endif + let s:last_ctx = a:ctx call s:refresh_keywords() endif endfunction @@ -67,22 +74,17 @@ function! s:refresh_keywords() abort let s:words[l:word] = 1 endif endfor - call asyncomplete#log('asyncomplete#buffer', 's:refresh_keywords() complete') endfunction - -let s:last_typed = '' -function! s:refresh_keyword_incremental(typed) abort - call asyncomplete#log('asyncomplete#sources#buffer', 'typed words ', a:typed) - if (len(a:typed) == 1) - let l:words = map(split(s:last_typed, g:asyncomplete_buffer_identify_words_regex.'\zs'),'matchstr(v:val,g:asyncomplete_buffer_identify_words_regex)') - call asyncomplete#log('asyncomplete#sources#buffer', 'refreshing words with ', l:words) - for l:word in l:words - if len(l:word) > 1 +function! s:refresh_keyword_incr(typed) abort + let l:words = split(a:typed, '\W\+') + if len(l:words) > 1 + for l:word in l:words[:len(l:words)-2] let s:words[l:word] = 1 - endif endfor - else - let s:last_typed = a:typed + endif + if len(l:words) > 0 + let l:new_last_word = l:words[len(l:words)-1:][0] + let s:last_word = l:new_last_word endif endfunction From 8b1e5282881f2c8b63ab138891be804b373a7a86 Mon Sep 17 00:00:00 2001 From: thecontinium Date: Fri, 3 Apr 2020 16:58:55 +0100 Subject: [PATCH 19/22] . --- autoload/asyncomplete/sources/buffer.vim | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/autoload/asyncomplete/sources/buffer.vim b/autoload/asyncomplete/sources/buffer.vim index 28703b9..d4c0c3d 100644 --- a/autoload/asyncomplete/sources/buffer.vim +++ b/autoload/asyncomplete/sources/buffer.vim @@ -14,7 +14,7 @@ function! asyncomplete#sources#buffer#completor(opt, ctx) let l:col = a:ctx['col'] let l:typed = a:ctx['typed'] - let l:kw = matchstr(l:typed, '\w\+$') + let l:kw = matchstr(l:typed, g:asyncomplete_buffer_identify_words_regex .'$') let l:kwlen = len(l:kw) if l:kwlen < 1 @@ -69,7 +69,7 @@ function! s:refresh_keywords() abort let s:words = {} endif let l:text = join(getline(1, '$'), "\n") - for l:word in map(split(l:text, g:asyncomplete_buffer_identify_words_regex.'\zs'),'matchstr(v:val,g:asyncomplete_buffer_identify_words_regex)') + for l:word in s:split_words(l:text) if len(l:word) > 1 let s:words[l:word] = 1 endif @@ -77,7 +77,7 @@ function! s:refresh_keywords() abort endfunction function! s:refresh_keyword_incr(typed) abort - let l:words = split(a:typed, '\W\+') + let l:words = s:split_words(a:typed) if len(l:words) > 1 for l:word in l:words[:len(l:words)-2] let s:words[l:word] = 1 @@ -88,3 +88,7 @@ function! s:refresh_keyword_incr(typed) abort let s:last_word = l:new_last_word endif endfunction + +function! s:split_words(text) + return map(split(a:text, g:asyncomplete_buffer_identify_words_regex.'\zs'),'matchstr(v:val,g:asyncomplete_buffer_identify_words_regex)') +endfunction From 41d5741524bbe071a45d658bff7e2d24de2d0d0c Mon Sep 17 00:00:00 2001 From: thecontinium Date: Fri, 3 Apr 2020 17:06:32 +0100 Subject: [PATCH 20/22] . --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 71e2cbc..30f148b 100644 --- a/README.md +++ b/README.md @@ -32,9 +32,10 @@ Clear buffer word cache on events (default: `1`) let g:asyncomplete_buffer_clear_cache = 1 ``` -Custom regex to dedide how to identify non word characters (defaults: '\W\+') +Custom regex to dedide how to identify word characters (defaults: '\w\+') ```vim -let g:asyncomplete_buffer_split_regex = get(g:, 'asyncomplete_buffer_split_regex', '\W\+') +let g:asyncomplete_buffer_identify_words_regex = '\w\+' +let g:asyncomplete_buffer_identify_words_regex = '\k\+' (uses iskeyword) ``` From 4958c6b7d20038710b7dd6ae3dab206db179c56a Mon Sep 17 00:00:00 2001 From: thecontinium Date: Fri, 3 Apr 2020 17:19:17 +0100 Subject: [PATCH 21/22] . --- autoload/asyncomplete/sources/buffer.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/autoload/asyncomplete/sources/buffer.vim b/autoload/asyncomplete/sources/buffer.vim index d4c0c3d..cff03d9 100644 --- a/autoload/asyncomplete/sources/buffer.vim +++ b/autoload/asyncomplete/sources/buffer.vim @@ -34,7 +34,7 @@ endfunction function! asyncomplete#sources#buffer#get_source_options(opts) return extend({ - \ 'events': ['CursorHold','CursorHoldI','BufWinEnter','BufWritePost','TextChangedI'], + \ 'events': ['CursorHold','CursorHoldI','BufWinEnter','BufWritePost','TextChangedI'], \ 'on_event': function('s:on_event'), \}, a:opts) endfunction @@ -53,7 +53,7 @@ function! s:on_event(opt, ctx, event) abort endif endif - if a:event == 'TextChangedI' + if a:event ==# 'TextChangedI' call s:refresh_keyword_incr(a:ctx['typed']) else if s:last_ctx == a:ctx From 09eee0a720fb9026c94bbd8e525fcdb165521f89 Mon Sep 17 00:00:00 2001 From: the continium Date: Wed, 22 Apr 2020 10:57:09 +0100 Subject: [PATCH 22/22] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 30f148b..9146e2e 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ Clear buffer word cache on events (default: `1`) let g:asyncomplete_buffer_clear_cache = 1 ``` -Custom regex to dedide how to identify word characters (defaults: '\w\+') +Custom regex to dedide how to identify word characters (defaults: `\w\+`) ```vim let g:asyncomplete_buffer_identify_words_regex = '\w\+' let g:asyncomplete_buffer_identify_words_regex = '\k\+' (uses iskeyword)