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

Rework provider argument parsing in Rust #982

Merged
merged 19 commits into from
Jul 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

## [unreleased]

### Removed

- Remove a bunch of deprecated flags: `g:clap_maple_delay`, `g:clap_dispatcher_drop_cache`, `g:clap_default_external_filter`, `g:clap_builtin_fuzzy_filter_threshold`, `g:clap_cache_threshold`, `g:clap_force_matchfuzzy`, `g:clap_force_python`. They are unused now and I believe most of them are hardly really used by users.

### Changed

- `++opt` and `+opt` have been replaced with `--opt value`/`--opt=value` and `--opt` in a consistent way. Ref to #981 for upgrade guide.

## [0.44] 2023-05-27

Expand All @@ -14,6 +21,7 @@
## [0.40] 2023-01-27

## [0.39] 2023-01-13

## [0.38] 2023-01-08

### Added
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

196 changes: 0 additions & 196 deletions PROVIDER.md

This file was deleted.

28 changes: 8 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,10 @@ Vim-clap is a modern generic performant finder using the `floating_win` of neovi
- [x] ~~Pure vimscript~~.
- Pin to some early version of vim-clap if you prefer the pure vimscript plugin.
- [x] ~~Work out of the box, without any extra dependency~~.
- The Rust binary is required to have a decent user experience.
- The Rust binary is now a must-have to make everything work smoothly.
- [x] Blazingly fast thanks to the powerful Rust backend.
- [x] Extensible, easy to add new providers.
- [x] Consistent command interface with [clap-rs/clap](https://github.com/clap-rs/clap)
- [x] Support writing new providers in both Vimscript and Rust.
- [x] Support [the search syntax borrowed from fzf](https://github.com/junegunn/fzf#search-syntax) and more.
- [x] Flexible UI layout.
- [ ] Support searching by multiple providers simultaneously.
Expand Down Expand Up @@ -105,19 +106,6 @@ Vim-clap is utterly easy to use, just type, press Ctrl-J/K to locate the wanted

The paradigm is `Clap [provider_id_or_alias] {provider_args}`, where the `provider_id_or_alias` is obviously either the name or alias of provider. Technically the `provider_id` can be anything that can be used a key of a Dict, but I recommend you using an _identifier_ like name as the provider id, and use the alias rule if you prefer a special name.

<details>
<summary>cache is no longer necessary since v0.37.</summary>

You can use `+no-cache` option to disable/refresh the cache, e.g., `:Clap files +no-cache ~` for searching files under the home directory without cache, the shortcut for `+no-cache` option:

- `:Clap!! [provider_id_or_alias] {provider_args}`, e.g, `:Clap!! files ~`.
- `:Clap [provider_id_or_alias][!] {provider_args}`, e.g, `:Clap files! ~`. (Recommended)

Note the `*` in the spinner, it tells you are using the cache, use `g:clap_forerunner_status_sign` to configure it.

<img width="561" alt="cache spinner" src="https://user-images.githubusercontent.com/8850248/78767291-fafe3e00-79bc-11ea-91a8-e17518e7a1b2.png">
</details>

#### Providers

| Command | List | Requirement |
Expand Down Expand Up @@ -156,7 +144,6 @@ Note the `*` in the spinner, it tells you are using the cache, use `g:clap_forer
| `Clap proj_tags` | Tags in the current project | **[maple][maple]** and **[universal-ctags][universal-ctags]** (`+json`) |
| `Clap recent_files` | Persistent ordered history of recent files | **[maple][maple]** |

[fd]: https://github.com/sharkdp/fd
[rg]: https://github.com/BurntSushi/ripgrep
[git]: https://github.com/git/git
[maple]: https://github.com/liuchengxu/vim-clap/blob/master/INSTALL.md#maple-binary
Expand All @@ -165,10 +152,10 @@ Note the `*` in the spinner, it tells you are using the cache, use `g:clap_forer
- The command with a superscript `!` means that it is not yet implemented or not tested.
- The command with a superscript `+` means that it supports multi-selection via <kbd>Tab</kbd>.
- `:Clap grep`
- Use `:Clap grep ++query=<cword>` to grep the word under cursor.
- Use `:Clap grep ++query=@visual` to grep the visual selection.
- Use `:Clap grep --query=<cword>` to grep the word under cursor.
- Use `:Clap grep --query=@visual` to grep the visual selection.
- `cwd` will be searched by default, specify the extra paths in the end to search multiple directories.
- `:Clap grep ~/.vim/plugged/ale` with `cwd` is `~/.vim/plugged/vim-clap` will both search vim-clap and ale.
- `:Clap grep --path ~/.vim/plugged/ale` with `cwd` is `~/.vim/plugged/vim-clap` will both search vim-clap and ale.

[Send a pull request](https://github.com/liuchengxu/vim-clap/pulls) if you want to get your provider listed here.

Expand Down Expand Up @@ -316,7 +303,8 @@ User config file is loaded from:

```toml
[matcher]
# There are four sort keys for results: score, begin, end, length, you can specify how the records are sorted using `tiebreak`.
# There are four sort keys for results: score, begin, end, length,
# you can specify how the records are sorted using `tiebreak`.
tiebreak = "score,-begin,-end,-length"
```

Expand Down
44 changes: 2 additions & 42 deletions autoload/clap.vim
Original file line number Diff line number Diff line change
Expand Up @@ -297,41 +297,6 @@ function! clap#for(provider_id_or_alias) abort
call clap#indicator#render()
endfunction

function! s:parse_opts(args) abort
let idx = 0
let g:clap.provider.raw_args = a:args
" TODO: Switch the argument parsing to CLI interface?
let g:clap.provider.args = []
for arg in a:args
if arg ==# '--'
let g:clap.context.query = join(a:args[idx+1 :], ' ')
break
endif
if arg =~? '^++\w*=\w*'
let matched = matchlist(arg, '^++\(\w*\)=\(\S*\)')
let [k, v] = [matched[1], matched[2]]
if has_key(g:clap.context, k)
let g:clap.context[k] .= ' '.v
else
let g:clap.context[k] = v
endif
elseif arg =~? '^+\w*'
let opt = arg[1:]
let g:clap.context[opt] = v:true
else
call add(g:clap.provider.args, arg)
endif
let idx += 1
endfor
if has_key(g:clap.context, 'query')
if g:clap.context.query ==# '@visual'
let g:clap.context.query = clap#util#get_visual_selection()
else
let g:clap.context.query = clap#util#expand(g:clap.context.query)
endif
endif
endfunction

function! clap#(bang, ...) abort
if !exists('g:clap')
call clap#init#()
Expand Down Expand Up @@ -370,18 +335,13 @@ function! clap#(bang, ...) abort
if a:1 ==# '!'
let g:clap.context['no-cache'] = v:true
let provider_id_or_alias = a:2
call s:parse_opts(a:000[2:])
let g:clap.provider.args = a:000[2:]
else
let provider_id_or_alias = a:1
call s:parse_opts(a:000[1:])
let g:clap.provider.args = a:000[1:]
endif
endif

if provider_id_or_alias =~# '!$'
let g:clap.context['no-cache'] = v:true
let provider_id_or_alias = provider_id_or_alias[:-2]
endif

call clap#for(provider_id_or_alias)
endfunction

Expand Down
Loading