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

[draft] add token argument to ICompleteHandler #238

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

marcushultman
Copy link
Contributor

@marcushultman marcushultman commented Jul 3, 2021

Sometimes you want to provide completion alternatives based on the
commandline buffer. This adds token (string) to both option- and
argument completion, containing the partially written word to complete.

This draft implements it as a breaking change - there are alternatives:

  • Add a new function completeWord.
  • Append as optional argument after the optional parent in existing handler.
  • Put the data into existing argument (command or parent).

Initially I've only solved it for fish shell this far

@codecov
Copy link

codecov bot commented Jul 3, 2021

Codecov Report

Merging #238 (280ceca) into main (f3103b9) will decrease coverage by 0.98%.
The diff coverage is 49.05%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #238      +/-   ##
==========================================
- Coverage   74.78%   73.79%   -0.99%     
==========================================
  Files          81       81              
  Lines        6218     6247      +29     
  Branches     1060     1049      -11     
==========================================
- Hits         4650     4610      -40     
- Misses       1555     1613      +58     
- Partials       13       24      +11     
Impacted Files Coverage Δ
command/command.ts 82.05% <0.00%> (-0.67%) ⬇️
command/type.ts 100.00% <ø> (ø)
command/types/child_command.ts 25.00% <0.00%> (ø)
command/completions/complete.ts 35.13% <14.28%> (-44.87%) ⬇️
command/completions/_fish_completions_generator.ts 89.60% <100.00%> (+1.74%) ⬆️
command/types/command.ts 71.42% <100.00%> (ø)
command/completions/bash.ts 52.17% <0.00%> (-26.09%) ⬇️
flags/_utils.ts 85.50% <0.00%> (-8.70%) ⬇️
prompt/number.ts 70.12% <0.00%> (-4.55%) ⬇️
prompt/input.ts 90.19% <0.00%> (-3.93%) ⬇️
... and 13 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f3103b9...280ceca. Read the comment docs.

@marcushultman
Copy link
Contributor Author

@c4spar What do you think about this? I think the feature itself is pretty solid - it really unlocks the full potential of completion. But it should probably not break the API, so there needs to be another solution there.

Sometimes you want to provide completion alternatives based on the
commandline buffer. This adds `token` (string) to both option- and
argument completion, containing the partially written word to complete.
@c4spar
Copy link
Owner

c4spar commented Jul 3, 2021

Hey @marcushultman, cool thx for this draft!

If I understand it correctly, then token would be the last value entered, for example if I do vr run [tab tab] then token would be "run", right?

This is definitely a feature I would like to add. I also thought about adding some more values, like an array with all tokens, cursor position, etc... but we should keep it consistent for all shells.

I think I would either add an object as 3rd argument { token: string } , then we can easily add more values to the object in the future, or we could just pass only one argument to the complete method { cmd: command, parent?: command, token: string }.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants