Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pick the dynamic filter from #353 #364

Merged
merged 55 commits into from
Apr 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
1ba2b2c
Pick dyn filter code
liuchengxu Mar 29, 2020
4a15231
Replaced f64 scoring with i32.
ImmemorConsultrixContrarie Mar 25, 2020
a4bb575
Make it compile
liuchengxu Mar 29, 2020
12a8d47
Intergate with vim initially
liuchengxu Mar 29, 2020
6782304
Change ITEMS_TO_SHOW to 100
liuchengxu Mar 29, 2020
595daba
Split filter sync/async
liuchengxu Mar 29, 2020
1906bee
Move to filter/async/dyn.vim
liuchengxu Mar 29, 2020
e6c28fc
Split out print_top_items()
liuchengxu Mar 30, 2020
3393700
.
liuchengxu Mar 30, 2020
7d40877
Split out select_top_items_to_show()
liuchengxu Mar 30, 2020
894e9a5
Extract find_bast_score_idx() and try_notify_top_results()
liuchengxu Mar 30, 2020
7b7a2e1
Fix vint
liuchengxu Mar 30, 2020
d7bdfea
Pass enable_icon to try_notify_top_results()
liuchengxu Mar 30, 2020
f7bb807
Fix sorting glitch in top scores
liuchengxu Mar 30, 2020
f3b0300
Pass --enable-icon in vimscript
liuchengxu Mar 30, 2020
0522228
Update CHANGELOG
liuchengxu Mar 30, 2020
29b88b5
Support neovim too
liuchengxu Mar 30, 2020
7970cc1
Process truncated_map in vim
liuchengxu Mar 30, 2020
aece025
Introduce Source::Exec
liuchengxu Mar 31, 2020
b849ba1
Commit state.vim
liuchengxu Mar 31, 2020
a8fdd39
Fix vint
liuchengxu Mar 31, 2020
c6f5ba6
Split out clap#state#handle_message()
liuchengxu Mar 31, 2020
e1a2f2a
Pass cmd into clap#filter#async#start(cmd)
liuchengxu Mar 31, 2020
742732a
Try using dyn filter on grep provider
liuchengxu Mar 31, 2020
4aea5c7
.
liuchengxu Mar 31, 2020
7bd0eba
Nits
liuchengxu Mar 31, 2020
d817dde
Merge branch 'master' of https://github.com/liuchengxu/vim-clap into …
liuchengxu Mar 31, 2020
e4bb2c7
Use vim job's native api
liuchengxu Apr 1, 2020
eec7f1d
Merge branch 'master' of https://github.com/liuchengxu/vim-clap into …
liuchengxu Apr 1, 2020
5ba6eb7
Add enable_dyn to default-features in fuzzy_filter
liuchengxu Apr 1, 2020
72c1561
Merge branch 'master' of https://github.com/liuchengxu/vim-clap into …
liuchengxu Apr 1, 2020
1be30c8
Nits
liuchengxu Apr 2, 2020
0fb5979
Use systemlist()
liuchengxu Apr 2, 2020
6b14021
Merge branch 'master' of https://github.com/liuchengxu/vim-clap into …
liuchengxu Apr 2, 2020
cde7b0e
Merge branch 'master' of https://github.com/liuchengxu/vim-clap into …
liuchengxu Apr 2, 2020
d436afe
Only when using maple
liuchengxu Apr 2, 2020
6cf6197
Split out job/stdio.vim
liuchengxu Apr 2, 2020
820ac95
Clean up dyn.vim
liuchengxu Apr 2, 2020
5d8f729
Remove rpc.vim
liuchengxu Apr 2, 2020
c0cc692
Add job/stdio.vim
liuchengxu Apr 2, 2020
9938aa1
Fix switching between files and history provider
liuchengxu Apr 3, 2020
c0fae09
Merge branch 'master' of https://github.com/liuchengxu/vim-clap into …
liuchengxu Apr 3, 2020
a72ee23
Check if has g:__clap_forerunner_tempfile
liuchengxu Apr 3, 2020
c2e1d11
Clear g:__clap_provider_cwd on exit
liuchengxu Apr 3, 2020
c715aa4
Add clap#state#refresh_matches_count_on_forerunner_done()
liuchengxu Apr 3, 2020
0c940a7
Fix vint
liuchengxu Apr 3, 2020
5a57f0d
.
liuchengxu Apr 3, 2020
f8a3184
Make maple.vim run filter --sync
liuchengxu Apr 3, 2020
be5b05b
.
liuchengxu Apr 3, 2020
266ab2a
.
liuchengxu Apr 3, 2020
adbbd28
Reset g:__clap_provider_cwd on start
liuchengxu Apr 3, 2020
ac771aa
.
liuchengxu Apr 3, 2020
8525cd0
Put s:clear_state() before setting provider source_type
liuchengxu Apr 3, 2020
b47fbb1
Extract clap#state#clear_pre() and clap#state#clear_post()
liuchengxu Apr 4, 2020
bd77cba
.
liuchengxu Apr 4, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ CHANGELOG
- Print a note about Rust nightly is requred for building the Python dynamic module.
- Refine the syntax of `Clap lines` with `ClapLinesBufname` and `ClapLinesNumber` group added.
- [perf] Use const table instead of `lazy_static` for the icons, [more info](https://github.com/liuchengxu/vim-clap/pull/354#discussion_r395975392). Thanks to @ImmemorConsultrixContrarie .
- [perf] Major improvement :tada: support the filter dynamic support, contribution by @ImmemorConsultrixContrarie. ([#364](https://github.com/liuchengxu/vim-clap/pull/364))

### Fixed

Expand Down
52 changes: 6 additions & 46 deletions autoload/clap.vim
Original file line number Diff line number Diff line change
Expand Up @@ -145,22 +145,6 @@ function! clap#_init() abort
call g:clap.display.setbufvar('&filetype', '')
endfunction

function! s:unlet_vars(vars) abort
for var in a:vars
if exists(var)
execute 'unlet' var
endif
endfor
endfunction

function! s:remove_provider_tmp_vars(vars) abort
for var in a:vars
if has_key(g:clap.provider, var)
call remove(g:clap.provider, var)
endif
endfor
endfunction

function! clap#_exit() abort
call g:clap.provider.jobstop()
call clap#forerunner#stop()
Expand All @@ -178,20 +162,10 @@ function! clap#_exit() abort
call g:clap.input.clear()
call g:clap.display.clear()

call s:remove_provider_tmp_vars([
\ 'args',
\ 'source_tempfile',
\ 'should_switch_to_async',
\ ])

call s:unlet_vars([
\ 'g:__clap_fuzzy_matched_indices',
\ 'g:__clap_forerunner_result',
\ 'g:__clap_lines_truncated_map',
\ ])

call clap#sign#reset()

call clap#state#clear_post()

call map(g:clap.tmps, 'delete(v:val)')
let g:clap.tmps = []
endfunction
Expand Down Expand Up @@ -268,7 +242,7 @@ function! s:try_register_is_ok(provider_id) abort
try
let registration_info = g:clap#provider#{provider_id}#
catch /^Vim\%((\a\+)\)\=:E121/
call clap#helper#echo_error('Fail to load the provider: '.provider_id)
call clap#helper#echo_error('Fail to load provider: '.provider_id.', E:'.v:exception)
return v:false
endtry
endif
Expand All @@ -283,21 +257,6 @@ function! s:try_register_is_ok(provider_id) abort
return s:validate_provider(registration_info)
endfunction

function! s:clear_state() abort
call s:unlet_vars([
\ 'g:__clap_provider_cwd',
\ 'g:__clap_raw_source',
\ 'g:__clap_initial_source_size',
\ ])

if exists('g:__clap_forerunner_tempfile')
if filereadable(g:__clap_forerunner_tempfile)
call delete(g:__clap_forerunner_tempfile)
endif
unlet g:__clap_forerunner_tempfile
endif
endfunction

function! clap#for(provider_id_or_alias) abort
if has_key(s:provider_alias, a:provider_id_or_alias)
let provider_id = s:provider_alias[a:provider_id_or_alias]
Expand All @@ -314,6 +273,9 @@ function! clap#for(provider_id_or_alias) abort
return
endif

call clap#state#clear_pre()

" g:__clap_provider_cwd can be set during this process, so this needs to be executed after s:clear_state()
if has_key(g:clap.provider._(), 'source')
if has_key(g:clap.provider._(), 'source_type')
let g:clap.provider.source_type = g:clap.provider._().source_type
Expand All @@ -323,8 +285,6 @@ function! clap#for(provider_id_or_alias) abort
endif
endif

call s:clear_state()

call clap#handler#init()

call g:clap.open_win()
Expand Down
25 changes: 4 additions & 21 deletions autoload/clap/api.vim
Original file line number Diff line number Diff line change
Expand Up @@ -442,25 +442,6 @@ function! s:init_provider() abort
return cmd
endfunction

" Return the cached source tmp file,
" otherwise write the source list into a temp file and then return it.
function! s:into_source_tmp_file(source_list) abort
if has_key(g:clap.provider, 'source_tempfile')
let tmp = g:clap.provider.source_tempfile
return tmp
else
let tmp = tempname()
if writefile(a:source_list, tmp) == 0
call add(g:clap.tmps, tmp)
let g:clap.provider.source_tempfile = tmp
return tmp
else
call g:clap.abort('Fail to write source to a temp file')
return ''
endif
endif
endfunction

function! provider.source_async_or_default() abort
if has_key(self._(), 'source_async')
return self._().source_async()
Expand All @@ -472,7 +453,9 @@ function! s:init_provider() abort
return s:wrap_async_cmd(Source)
elseif self.source_type == g:__t_func_string
return s:wrap_async_cmd(Source())
elseif self.source_type == g:__t_list
endif

if self.source_type == g:__t_list
let lines = copy(Source)
" This optimization has been moved to on_typed_async_impl()
" elseif self.id ==# 'blines'
Expand All @@ -484,7 +467,7 @@ function! s:init_provider() abort

let ext_filter_cmd = clap#filter#async#external#get_cmd_or_default()

let tmp = s:into_source_tmp_file(lines)
let tmp = clap#state#into_tempfile(lines)
let cmd = s:read_from_file_or_pipe(ext_filter_cmd, tmp)

return cmd
Expand Down
43 changes: 43 additions & 0 deletions autoload/clap/filter/async/dyn.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
" Author: liuchengxu <xuliuchengxlc@gmail.com>
" Description: Dynamic update version of maple filter.

let s:save_cpo = &cpoptions
set cpoptions&vim

function! s:handle_message(msg) abort
if !g:clap.display.win_is_valid()
\ || g:clap.input.get() !=# s:last_query
return
endif

call clap#state#handle_message(a:msg)
endfunction

function! clap#filter#async#dyn#start_directly(maple_cmd) abort
let s:last_query = g:clap.input.get()
call clap#job#stdio#start_service(function('s:handle_message'), a:maple_cmd)
endfunction

function! clap#filter#async#dyn#start(cmd) abort
let s:last_query = g:clap.input.get()
call clap#job#stdio#start_dyn_filter_service(function('s:handle_message'), a:cmd)
endfunction

function! clap#filter#async#dyn#from_tempfile(tempfile) abort
let s:last_query = g:clap.input.get()
if g:clap_enable_icon && index(['files', 'git_files'], g:clap.provider.id) > -1
let enable_icon_opt = '--enable-icon'
else
let enable_icon_opt = ''
endif
let filter_cmd = printf('%s --number 100 --winwidth %d filter "%s" --input %s',
\ enable_icon_opt,
\ winwidth(g:clap.display.winid),
\ g:clap.input.get(),
\ a:tempfile
\ )
call clap#job#stdio#start_service(function('s:handle_message'), clap#maple#build_cmd(filter_cmd))
endfunction

let &cpoptions = s:save_cpo
unlet s:save_cpo
2 changes: 1 addition & 1 deletion autoload/clap/filter/async/external.vim
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ endfunction

function! s:cmd_of(ext_filter) abort
if a:ext_filter ==# 'maple'
return clap#maple#filter_subcommand(g:clap.input.get())
return clap#maple#sync_filter_subcommand(g:clap.input.get())
else
return printf(s:ext_cmd[a:ext_filter], g:clap.input.get())
endif
Expand Down
2 changes: 1 addition & 1 deletion autoload/clap/forerunner.vim
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function! s:on_complete_common(lines, initial_size) abort
endif

let g:clap.display.initial_size = a:initial_size
call clap#state#refresh_matches_count(string(a:initial_size))
call clap#state#refresh_matches_count_on_forerunner_done()

let g:__clap_current_forerunner_status = g:clap_forerunner_status_sign.done
call clap#spinner#refresh()
Expand Down
28 changes: 21 additions & 7 deletions autoload/clap/impl.vim
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,27 @@ function! s:on_typed_async_impl() abort
let source_file = expand('#'.g:clap.start.bufnr.':p')
let blines_cmd = clap#maple#blines_subcommand(g:clap.input.get())
let maple_cmd = printf('%s %s', blines_cmd, source_file)
call clap#rooter#run(function('clap#maple#job_start'), maple_cmd)
else
let cmd = g:clap.provider.source_async_or_default()
call clap#filter#async#dyn#start_directly(maple_cmd)
return
endif

if clap#filter#async#external#using_maple()
call clap#rooter#run(function('clap#maple#job_start'), cmd)
else
call clap#rooter#run(function('clap#dispatcher#job_start'), cmd)
if clap#filter#async#external#using_maple()
if exists('g:__clap_forerunner_tempfile')
call clap#filter#async#dyn#from_tempfile(g:__clap_forerunner_tempfile)
return
endif
if g:clap.provider.source_type == g:__t_string
call clap#filter#async#dyn#start(g:clap.provider._().source)
return
elseif g:clap.provider.source_type == g:__t_func_string
call clap#filter#async#dyn#start(g:clap.provider._().source())
return
endif
let cmd = g:clap.provider.source_async_or_default()
call clap#rooter#run(function('clap#maple#job_start'), cmd)
else
let cmd = g:clap.provider.source_async_or_default()
call clap#rooter#run(function('clap#dispatcher#job_start'), cmd)
endif

call clap#spinner#set_busy()
Expand Down Expand Up @@ -173,10 +185,12 @@ function! clap#impl#on_typed() abort
call s:on_typed_async_impl()
return
endif

if exists('g:__clap_forerunner_result')
call s:on_typed_sync_impl()
return
endif

if g:clap.provider.can_async() &&
\ (get(g:clap.context, 'async') is v:true || s:should_switch_to_async())
call s:on_typed_async_impl()
Expand Down
12 changes: 9 additions & 3 deletions autoload/clap/maple.vim
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,12 @@ function! s:on_complete() abort
return
endif

let decoded = json_decode(s:chunks[0])
try
let decoded = json_decode(s:chunks[0])
catch
echoerr '[maple]decoded on_complete:'.string(s:chunks)
return
endtry
if has_key(decoded, 'error')
call g:clap.display.set_lines([
\ 'The external job runs into some issue:',
Expand Down Expand Up @@ -196,14 +201,15 @@ function! clap#maple#forerunner_exec_subcommand(cmd) abort
return printf('%s %s %s', s:maple_bin, global_opt, subcommand)
endfunction

function! clap#maple#filter_subcommand(query) abort
" Returns the filtered results after the input stream is complete.
function! clap#maple#sync_filter_subcommand(query) abort
let global_opt = '--number '.g:clap.display.preload_capacity.' --winwidth '.winwidth(g:clap.display.winid)

if g:clap.provider.id ==# 'files' && g:clap_enable_icon
let global_opt .= ' --enable-icon'
endif

let cmd = printf('%s %s filter "%s"', s:maple_bin, global_opt, a:query)
let cmd = printf('%s %s filter "%s" --sync', s:maple_bin, global_opt, a:query)

return cmd
endfunction
Expand Down
74 changes: 74 additions & 0 deletions autoload/clap/state.vim
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ set cpoptions&vim
" may run into some erratic read-only error.
function! clap#state#refresh_matches_count(cnt_str) abort
let l:matches_cnt = a:cnt_str
let s:current_matches = a:cnt_str

if get(g:clap.display, 'initial_size', -1) > 0
let l:matches_cnt .= '/'.g:clap.display.initial_size
Expand All @@ -17,6 +18,12 @@ function! clap#state#refresh_matches_count(cnt_str) abort
call clap#sign#reset_to_first_line()
endfunction

function! clap#state#refresh_matches_count_on_forerunner_done() abort
if exists('s:current_matches')
call clap#indicator#set_matches(printf('[%s/%s]', s:current_matches, g:clap.display.initial_size))
endif
endfunction

function! clap#state#handle_message(msg) abort
let decoded = json_decode(a:msg)

Expand All @@ -41,5 +48,72 @@ function! clap#state#handle_message(msg) abort
endif
endfunction

" Returns the cached source tmp file.
"
" Write the providers whose `source` is list-style into a tempfile.
function! clap#state#into_tempfile(source_list) abort
if has_key(g:clap.provider, 'source_tempfile')
let tmp = g:clap.provider.source_tempfile
return tmp
else
let tmp = tempname()
if writefile(a:source_list, tmp) == 0
call add(g:clap.tmps, tmp)
let g:clap.provider.source_tempfile = tmp
return tmp
else
call g:clap.abort('Fail to write source to a temp file')
return ''
endif
endif
endfunction

function! s:unlet_vars(vars) abort
for var in a:vars
if exists(var)
execute 'unlet' var
endif
endfor
endfunction

function! s:remove_provider_tmp_vars(vars) abort
for var in a:vars
if has_key(g:clap.provider, var)
call remove(g:clap.provider, var)
endif
endfor
endfunction

" Clear the previous temp state when invoking a new provider.
function! clap#state#clear_pre() abort
call s:unlet_vars([
\ 'g:__clap_raw_source',
\ 'g:__clap_provider_cwd',
\ 'g:__clap_initial_source_size',
\ ])

if exists('g:__clap_forerunner_tempfile')
if filereadable(g:__clap_forerunner_tempfile)
call delete(g:__clap_forerunner_tempfile)
endif
unlet g:__clap_forerunner_tempfile
endif
endfunction

" Clear temp state on clap#_exit()
function! clap#state#clear_post() abort
call s:remove_provider_tmp_vars([
\ 'args',
\ 'source_tempfile',
\ 'should_switch_to_async',
\ ])

call s:unlet_vars([
\ 'g:__clap_fuzzy_matched_indices',
\ 'g:__clap_forerunner_result',
\ 'g:__clap_lines_truncated_map',
\ ])
endfunction

let &cpoptions = s:save_cpo
unlet s:save_cpo
Loading