diff --git a/Cargo.lock b/Cargo.lock index b3f6cce52..8f38f66d4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -80,9 +80,10 @@ dependencies = [ [[package]] name = "crossbeam-queue" -version = "0.2.0" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ + "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", "crossbeam-utils 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -152,7 +153,7 @@ dependencies = [ "bytecount 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "extracted_fzy 0.1.0", "fuzzy-matcher 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "rayon 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "rayon 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.44 (registry+https://github.com/rust-lang/crates.io-index)", "structopt 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -202,21 +203,21 @@ dependencies = [ [[package]] name = "rayon" -version = "1.2.1" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "crossbeam-deque 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", "either 1.5.3 (registry+https://github.com/rust-lang/crates.io-index)", - "rayon-core 1.6.1 (registry+https://github.com/rust-lang/crates.io-index)", + "rayon-core 1.7.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "rayon-core" -version = "1.6.1" +version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "crossbeam-deque 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", - "crossbeam-queue 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "crossbeam-queue 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "crossbeam-utils 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "num_cpus 1.11.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -370,7 +371,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5067f5bb2d80ef5d68b4c87db81601f0b75bca627bc2ef76b141d7b846a3c6d9" "checksum crossbeam-deque 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c3aa945d63861bfe624b55d153a39684da1e8c0bc8fba932f7ee3a3c16cea3ca" "checksum crossbeam-epoch 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5064ebdbf05ce3cb95e45c8b086f72263f4166b29b97f6baff7ef7fe047b55ac" -"checksum crossbeam-queue 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "dfd6515864a82d2f877b42813d4553292c6659498c9a2aa31bab5a15243c2700" +"checksum crossbeam-queue 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c695eeca1e7173472a32221542ae469b3e9aac3a4fc81f7696bcad82029493db" "checksum crossbeam-utils 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ce446db02cdc3165b94ae73111e570793400d0794e46125cc4056c81cbb039f4" "checksum either 1.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "bb1f6b1ce1c140482ea30ddd3335fc0024ac7ee112895426e0a629a6c20adfe3" "checksum fuzzy-matcher 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4d860c6f043a7f367ffcbdb5833c36f7dc85fa8bc6e7898e2530f643ec90f9f3" @@ -384,8 +385,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum proc-macro-error 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "aeccfe4d5d8ea175d5f0e4a2ad0637e0f4121d63bd99d356fb1f39ab2e7c6097" "checksum proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "9c9e470a8dc4aeae2dee2f335e8f533e2d4b347e1434e5671afc49b054592f27" "checksum quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "053a8c8bcc71fcce321828dc897a98ab9760bef03a4fc36693c231e5b3216cfe" -"checksum rayon 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "43739f8831493b276363637423d3622d4bd6394ab6f0a9c4a552e208aeb7fddd" -"checksum rayon-core 1.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f8bf17de6f23b05473c437eb958b9c850bfc8af0961fe17b4cc92d5a627b4791" +"checksum rayon 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "db6ce3297f9c85e16621bb8cca38a06779ffc31bb8184e1be4bed2be4678a098" +"checksum rayon-core 1.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "08a89b46efaf957e52b18062fb2f4660f8b8a4dde1807ca002690868ef2c85a9" "checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" "checksum ryu 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "bfa8506c1de11c9c4e4c38863ccbe02a305c8188e85a05a784c9e11e1c3910c8" "checksum scopeguard 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b42e15e59b18a828bbf5c58ea01debb36b9b096346de35d941dcb89009f24a0d" diff --git a/autoload/clap.vim b/autoload/clap.vim index dad1b6a91..7e167c4ae 100644 --- a/autoload/clap.vim +++ b/autoload/clap.vim @@ -264,11 +264,11 @@ function! s:clear_state() abort \ 'g:__clap_initial_source_size', \ ]) - if exists('g:__clap_forerunner_tmp_file') - if filereadable(g:__clap_forerunner_tmp_file) - call delete(g:__clap_forerunner_tmp_file) + if exists('g:__clap_forerunner_tempfile') + if filereadable(g:__clap_forerunner_tempfile) + call delete(g:__clap_forerunner_tempfile) endif - unlet g:__clap_forerunner_tmp_file + unlet g:__clap_forerunner_tempfile endif endfunction diff --git a/autoload/clap/api.vim b/autoload/clap/api.vim index 964a22482..d6ed7ba8e 100644 --- a/autoload/clap/api.vim +++ b/autoload/clap/api.vim @@ -413,8 +413,8 @@ function! s:init_provider() abort " Pipe the source into the external filter function! s:wrap_async_cmd(source_cmd) abort let ext_filter_cmd = clap#filter#get_external_cmd_or_default() - if exists('g:__clap_forerunner_tmp_file') - let cmd = s:read_from_file_or_pipe(ext_filter_cmd, g:__clap_forerunner_tmp_file) + if exists('g:__clap_forerunner_tempfile') + let cmd = s:read_from_file_or_pipe(ext_filter_cmd, g:__clap_forerunner_tempfile) else " FIXME Does it work well in Windows? " Run the source command and pipe into the external filter. diff --git a/autoload/clap/forerunner.vim b/autoload/clap/forerunner.vim index 7d77adce1..ec1791c4b 100644 --- a/autoload/clap/forerunner.vim +++ b/autoload/clap/forerunner.vim @@ -34,12 +34,31 @@ function! s:on_complete() abort else let tmp = tempname() if writefile(s:chunks, tmp) == 0 - let g:__clap_forerunner_tmp_file = tmp + let g:__clap_forerunner_tempfile = tmp endif unlet s:chunks endif endfunction +function! s:on_complete_maple() abort + if !empty(s:chunks) + let decoded = json_decode(s:chunks[0]) + + if empty(g:clap.input.get()) + call g:clap.display.set_lines_lazy(decoded.lines) + endif + + let g:clap.display.initial_size = decoded.total + call clap#impl#refresh_matches_count(string(decoded.total)) + + if has_key(decoded, 'tempfile') + let g:__clap_forerunner_tempfile = decoded.tempfile + else + let g:__clap_forerunner_result = decoded.lines + endif + endif +endfunction + function! s:on_event(job_id, data, event) abort " We only process the job that was spawned last time. if a:job_id == s:job_id @@ -56,28 +75,83 @@ function! s:on_event(job_id, data, event) abort endif endfunction +function! s:on_event_maple(job_id, data, event) abort + " We only process the job that was spawned last time. + if a:job_id == s:job_id + if a:event ==# 'stdout' + if len(a:data) > 1 + " Second last is the real last one for neovim. + call extend(s:chunks, a:data[:-2]) + endif + elseif a:event ==# 'stderr' + " Ignore the error + else + call s:on_complete_maple() + endif + endif +endfunction + function! s:close_cb(channel) abort if clap#job#vim8_job_id_of(a:channel) == s:job_id " https://github.com/vim/vim/issues/5143 - let s:chunks = split(ch_readraw(a:channel), "\n") - call s:on_complete() + if ch_canread(a:channel) + let s:chunks = split(ch_readraw(a:channel), "\n") + call s:on_complete() + endif + endif +endfunction + +function! s:close_cb_maple(channel) abort + if clap#job#vim8_job_id_of(a:channel) == s:job_id + if ch_canread(a:channel) + let s:chunks = split(ch_readraw(a:channel), "\n") + call s:on_complete_maple() + endif endif endfunction if has('nvim') + function! s:start_maple(cmd) abort + let s:job_id = clap#job#start_buffered(a:cmd, function('s:on_event_maple')) + endfunction + function! s:start_forerunner(cmd) abort let s:job_id = clap#job#start_buffered(a:cmd, function('s:on_event')) endfunction else + function! s:start_maple(cmd) abort + let s:job_id = clap#job#start_buffered(a:cmd, function('s:close_cb_maple')) + endfunction + function! s:start_forerunner(cmd) abort let s:job_id = clap#job#start_buffered(a:cmd, function('s:close_cb')) endfunction endif -function! clap#forerunner#start(cmd) abort - let s:chunks = [] - call clap#rooter#run(function('s:start_forerunner'), a:cmd) -endfunction +if clap#maple#is_available() + let s:empty_filter_cmd = printf(clap#maple#filter_cmd_fmt(), '') + + function! s:into_maple_cmd(cmd) abort + let cmd_dir = clap#rooter#working_dir() + let cmd = printf('%s --cmd "%s" --cmd-dir "%s" --output-threshold %d', + \ s:empty_filter_cmd, + \ a:cmd, + \ cmd_dir, + \ s:builtin_fuzzy_filter_threshold, + \ ) + return cmd + endfunction + + function! clap#forerunner#start(cmd) abort + let s:chunks = [] + call s:start_maple(s:into_maple_cmd(a:cmd)) + endfunction +else + function! clap#forerunner#start(cmd) abort + let s:chunks = [] + call clap#rooter#run(function('s:start_forerunner'), a:cmd) + endfunction +endif function! clap#forerunner#stop() abort if s:job_id > 0 diff --git a/autoload/clap/rooter.vim b/autoload/clap/rooter.vim index 4679a2a4d..a4d81a075 100644 --- a/autoload/clap/rooter.vim +++ b/autoload/clap/rooter.vim @@ -27,6 +27,22 @@ function! clap#rooter#try_set_cwd() abort endif endfunction +function! clap#rooter#working_dir() abort + if exists('g:__clap_provider_cwd') + let dir = g:__clap_provider_cwd + elseif clap#should_use_raw_cwd() + let dir = getcwd() + else + let git_root = clap#util#find_git_root(g:clap.start.bufnr) + if empty(git_root) + let dir = expand('#'.g:clap.start.bufnr.':p:h') + else + let dir = git_root + endif + endif + return dir +endfunction + function! s:run_from_target_dir(target_dir, Run, run_args) abort let save_cwd = getcwd() try diff --git a/src/main.rs b/src/main.rs index 6689612ac..776bc0487 100644 --- a/src/main.rs +++ b/src/main.rs @@ -90,8 +90,14 @@ impl Maple { .collect::>(); let mut cmd = Command::new(args[0].clone()); - if let Some(ref cmd_dir) = self.cmd_dir { - cmd.current_dir(cmd_dir); + if let Some(cmd_dir) = self.cmd_dir.clone() { + if cmd_dir.is_dir() { + cmd.current_dir(cmd_dir); + } else { + let mut cmd_dir = cmd_dir; + cmd_dir.pop(); + cmd.current_dir(cmd_dir); + } } cmd.args(&args[1..]);