diff --git a/README.md b/README.md index aaf620856..2fb9dd43c 100644 --- a/README.md +++ b/README.md @@ -88,13 +88,7 @@ Vim-clap is a modern generic interactive finder and dispatcher, based on the new #### `Rust` -If you have installed Rust on your system, specifically, `cargo` executable exists, you can build the extra tools for a performant and nicer vim-clap using one single command `:call clap#helper#build_all()`. - -Notes: [Python dynamic module](https://github.com/liuchengxu/vim-clap#python-dynamic-module) needs to be compiled using Rust nightly, ensure you have installed it: - -```bash -$ rustup toolchain install nightly -``` +If you have installed Rust on your system, specifically, `cargo` executable exists, you can build the extra tools for a performant and nicer vim-clap using this single command `:call clap#helper#build_all()`. ##### `maple` binary @@ -107,6 +101,8 @@ $ rustup toolchain install nightly To install `maple` you can use the helper function and run `:call clap#helper#build_maple()`, or install it manually: ```bash + cd path/to/vim-clap + # Compile the release build cargo build --release @@ -116,7 +112,15 @@ To install `maple` you can use the helper function and run `:call clap#helper#bu ##### Python dynamic module -Use `:call clap#helper#build_rust_ext()` to install the Python dynamic module written in Rust for 10x faster fuzzy filter than the Python one. Refer to the post [Make Vim Python plugin 10x faster using Rust](http://liuchengxu.org/posts/speed-up-vim-python-plugin-using-rust/) for the whole story. +If you don't have `+python`, you can safely skip this section, it's totally fine, vim-clap can still work very well with only `maple` binary installed. This Python dynamic module is mainly for saving the async job when the data set is small. + +[Python dynamic module](https://github.com/liuchengxu/vim-clap#python-dynamic-module) needs to be compiled using Rust nightly, ensure you have installed it if you want to run the helper function successfully: + +```bash +$ rustup toolchain install nightly +``` + +Then use `:call clap#helper#build_python_dynamic_module()` to install the Python dynamic module written in Rust for 10x faster fuzzy filter than the Python one. Refer to the post [Make Vim Python plugin 10x faster using Rust](http://liuchengxu.org/posts/speed-up-vim-python-plugin-using-rust/) for the whole story. ## Installation diff --git a/autoload/clap/helper.vim b/autoload/clap/helper.vim index 71ed5432a..b21c30054 100644 --- a/autoload/clap/helper.vim +++ b/autoload/clap/helper.vim @@ -102,11 +102,32 @@ else let s:rust_ext_cwd = fnamemodify(g:clap#autoload_dir, ':h').'/pythonx/clap' endif -function! clap#helper#build_rust_ext() abort +function! s:has_rust_nightly(show_warning) abort + call system('cargo +nightly --help') + if v:shell_error + if a:show_warning + call clap#helper#echo_warn('Rust nightly is required, try running `rustup toolchain install nightly` in the command line and then rerun this function.') + else + call clap#helper#echo_info('Rust nightly is required, skip building the Python dynamic module.') + endif + return v:false + endif + return v:true +endfunction + +function! clap#helper#build_python_dynamic_module() abort + if !has('python3') + call clap#helper#echo_info('+python3 is required, skip building the Python dynamic module.') + return + endif + if executable('cargo') - call s:run_term(s:rust_ext_cmd, s:rust_ext_cwd, 'build Rust extension successfully') + if !s:has_rust_nightly(v:true) + return + endif + call s:run_term(s:rust_ext_cmd, s:rust_ext_cwd, 'build Python dynamic module successfully') else - call clap#helper#echo_error('Can not build Rust extension in that cargo is not found.') + call clap#helper#echo_error('Can not build Python dynamic module in that cargo is not found.') endif endfunction @@ -114,23 +135,28 @@ function! clap#helper#build_maple() abort if executable('cargo') let cmd = 'cargo build --release' let cwd = fnamemodify(g:clap#autoload_dir, ':h') - call s:run_term(cmd, cwd, 'build maple successfully') + call s:run_term(cmd, cwd, 'build maple binary successfully') else - call clap#helper#echo_error('Can not build maple in that cargo is not found.') + call clap#helper#echo_error('Can not build maple binary in that cargo is not found.') endif endfunction function! clap#helper#build_all(...) abort if executable('cargo') - let cwd = fnamemodify(g:clap#autoload_dir, ':h') - if has('win32') - let cmd = printf('cargo build --release && cd /d %s && %s', s:rust_ext_cwd, s:rust_ext_cmd) + " If Rust nightly and +python3 is unavailable, build the maple only. + if has('python3') && s:has_rust_nightly(v:false) + let cwd = fnamemodify(g:clap#autoload_dir, ':h') + if has('win32') + let cmd = printf('cargo build --release && cd /d %s && %s', s:rust_ext_cwd, s:rust_ext_cmd) + else + let cmd = 'make' + endif + call s:run_term(cmd, cwd, 'build maple binary and Python dynamic module successfully') else - let cmd = 'make' + call clap#helper#build_maple() endif - call s:run_term(cmd, cwd, 'build maple and Rust extension successfully') else - call clap#helper#echo_warn('cargo not found, skipped building maple and the Rust extension.') + call clap#helper#echo_warn('cargo not found, skipped building maple binary and Python dynamic module.') endif endfunction