deno-cliffy icon indicating copy to clipboard operation
deno-cliffy copied to clipboard

[draft] add token argument to ICompleteHandler

Open marcushultman opened this issue 3 years ago • 3 comments

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

marcushultman avatar Jul 03 '21 15:07 marcushultman

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%) :arrow_down:
command/type.ts 100.00% <ø> (ø)
command/types/child_command.ts 25.00% <0.00%> (ø)
command/completions/complete.ts 35.13% <14.28%> (-44.87%) :arrow_down:
command/completions/_fish_completions_generator.ts 89.60% <100.00%> (+1.74%) :arrow_up:
command/types/command.ts 71.42% <100.00%> (ø)
command/completions/bash.ts 52.17% <0.00%> (-26.09%) :arrow_down:
flags/_utils.ts 85.50% <0.00%> (-8.70%) :arrow_down:
prompt/number.ts 70.12% <0.00%> (-4.55%) :arrow_down:
prompt/input.ts 90.19% <0.00%> (-3.93%) :arrow_down:
... 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.

codecov[bot] avatar Jul 03 '21 15:07 codecov[bot]

@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.

marcushultman avatar Jul 03 '21 15:07 marcushultman

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 }.

c4spar avatar Jul 03 '21 20:07 c4spar