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

Filter and order completions based on input and importance for native completions #5058

Closed
ModProg opened this issue Jul 31, 2023 · 12 comments
Closed
Labels
A-completion Area: completion generator C-enhancement Category: Raise on the bar on expectations E-easy Call for participation: Experience needed to fix: Easy / not much

Comments

@ModProg
Copy link
Contributor

ModProg commented Jul 31, 2023

While there are some shell specific behaviors for options, e.g. for zsh and fish:

In zsh, options are completed if at least one - is present.

In fish options are completed if the exact number of dashes is present, i.e. one - for a short option and two -- for a long option.

This had an initial implementation at #5057.

We believe that with the additional knowledge available, clap can do better.

Filtering

On an empty current token, complete:

  • If subcommands or positionals are present
    • Subcommands
    • Positional arguments
    • Required pptions (prefer long)
  • else
    • All options (prefer long)

On a single - complete all options, prefer short options where available.

On a double -- complete long options, this would happen either way, so not really a feature. If escaping makes sense (positionals exist), then include just --

In general, aliases are hidden, and only shown if they are the only name of an argument matching the current input.

In all cases, aliases should only show up if the main argument is not being shown

Sorting

Either

  • Alphabetical
  • Display order

Customization

In the future, it could make sense to make both filtering and sorting customizable by the developer.

@ModProg

This comment was marked as outdated.

@epage
Copy link
Member

epage commented Jul 31, 2023

I wonder if we should generalize this to all shells.

In particular, I think it is useful to guess the reason and decide how we want to move forward more generally based on that reason.

My guess is to not flood the screen, overwhelming the user, but try to provide more targeted information. I think that is a worthwhile cause and should be applied to all shells uniformly.

This also gets me thinking of more concrete semantics

  • Only show required options, arguments, and subcommands for an empty string
    • Maybe we relax this for positional arguments and subcommands much like usage strings
    • Another reason to relax it for those cases is there isn't a general prefix for them
  • Only show one way of referencing any item in any completion
    • e.g. if someone has written enough that only the alias applies, show the alias
    • Prefer long over short
    • Prefer normal name over alias

Thoughts?

@epage
Copy link
Member

epage commented Jul 31, 2023

Another way of putting this is: can we provide a richer experience with the extra semantic information we have?

@ModProg
Copy link
Contributor Author

ModProg commented Jul 31, 2023

Probably, e.g. if someone is currently in the process of rebasing, it would be a good idea to complete --continue and --abort right away as that are the most likely next steps.

We could even go as far as having some form of score users can give options at a later stage, promoting them to be shown earlier.

But it is probably a good idea to e.g. not flood the screen with aliases.

On long vs short that is probably more difficult to decide, and could be shell dependent to, e.g., match the single dash -> short options behavior in fish.

@epage
Copy link
Member

epage commented Jul 31, 2023

On long vs short that is probably more difficult to decide, and could be shell dependent to, e.g., match the single dash -> short options behavior in fish.

At least for a blank screen, I think showing longs for required arguments would be better since that will be more descriptive (in case the descriptions from #5056 aren't sufficient)

But for - I can see preferring shorts. Should we still show a long if it is required and doesn't have a short?

@ModProg
Copy link
Contributor Author

ModProg commented Jul 31, 2023

On long vs short that is probably more difficult to decide, and could be shell dependent to, e.g., match the single dash -> short options behavior in fish.

At least for a blank screen, I think showing longs for required arguments would be better since that will be more descriptive (in case the descriptions from #5056 aren't sufficient)

But for - I can see preferring shorts. Should we still show a long if it is required and doesn't have a short?

yeah, I think preferring short, but falling back to long makes total sense.

Also, fish has a feature where it shows the long flags, for short flags, i.e. it completes the short flag, but shows the long flag as a hint, while we cannot currently use that exact feature for completions, we could emulate something like that i.e. showing the long flag as a fallback for missing descriptions or as a prefix for descriptions of short flags.

@ModProg
Copy link
Contributor Author

ModProg commented Jul 31, 2023

Oh and it also does exactly what you proposed concerning completing long flags if they do not have a short flag. Something I totally missed in my attempt at implementing this hastily.
grafik

@epage
Copy link
Member

epage commented Jul 31, 2023

Unless I'm missing something, we've come to a consensus and this is ready to move forward?

@epage epage added A-completion Area: completion generator C-enhancement Category: Raise on the bar on expectations labels Jul 31, 2023
@ModProg ModProg changed the title Dynamic Completions: Show options conditioned on presence of dashes Dynamic Completions: Filter and order completions based on input and importance Aug 1, 2023
@ModProg
Copy link
Contributor Author

ModProg commented Aug 1, 2023

@epage I updated the description

@epage
Copy link
Member

epage commented Aug 1, 2023

Made some minor tweaks. Good to go!

@epage epage added the E-easy Call for participation: Experience needed to fix: Easy / not much label Aug 1, 2023
@epage epage changed the title Dynamic Completions: Filter and order completions based on input and importance Filter and order completions based on input and importance for native completions Jul 19, 2024
@epage
Copy link
Member

epage commented Jul 19, 2024

With #3951 nearly done, I've reviewed the plan for this again and made a couple of tweaks.

@epage
Copy link
Member

epage commented Sep 20, 2024

I think we've got this covered between

While we don't hide optional flags. I'm a bit mixed on that. If there is interest in moving forward on that, we likely should have a dedicated issue exploring the trade offs.

@epage epage closed this as completed Sep 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-completion Area: completion generator C-enhancement Category: Raise on the bar on expectations E-easy Call for participation: Experience needed to fix: Easy / not much
Projects
None yet
Development

No branches or pull requests

2 participants