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

Add support for completing --flag value<TAB>, -fbar<TAB>, -f=bar<TAB> and -f bar<TAB> #5533

Closed
wants to merge 3 commits into from

Conversation

shannmu
Copy link
Contributor

@shannmu shannmu commented Jun 14, 2024

Related issues:

In this PR, I modified some logic in the complete function:

  • Added CompletionState to record the current parsing state during completion parsing. When completion is triggered with target_cursor equal to cursor, the completion function will be chosen based on the CompletionState.
  • Modified the priority handling in the complete function for arg over subcommand, optional long flag, escape, negative number, optional short flag, stdio, and empty.
  • Modified the priority handling in complete_arg for arg, with the same priority as above.

There are some TODOs in this PR that I will implement later, including:

  • Long flag, short flag, and alias completion for subcommand
  • Support for args_conflicts_with_subcommands
  • Support for subcommand_precedence_over_arg
  • Support for multicall

@shannmu shannmu force-pushed the cargo_completions branch from 097482c to a9f4b5a Compare June 14, 2024 10:07
@shannmu
Copy link
Contributor Author

shannmu commented Jun 14, 2024

The current code hasn't been tested a lot. I've just done some quick tests using the dynamic program from the tests.
Also, for the CI, I'll rebase onto clap's master branch later and modify the commit message and a few other things to meet the CI requirements.

@@ -0,0 +1,5 @@
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert this. I don't want to get into the business of having the config files for every users editor in my repos

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(in git, you can configure a user-wide ignore and place these here for yourself)

/// Complete the given command
/// NOTE: borrow the idea from Parser.rs::ParseState to record the state during completion.s
#[derive(Debug, PartialEq, Eq, Clone)]
enum CompletionState {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's call this ParseState to be more specific (and match clap's parser)

/// Complete the given command
/// NOTE: borrow the idea from Parser.rs::ParseState to record the state during completion.s
#[derive(Debug, PartialEq, Eq, Clone)]
enum CompletionState {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: we generally put implementation details for logic after the logic (so move this after complete)

@shannmu
Copy link
Contributor Author

shannmu commented Jun 17, 2024

I need to split this PR into smaller PRs for easier discussion and review. How should I handle the situation where one resulting PR might be based on another PR?

@shannmu shannmu force-pushed the cargo_completions branch from 54581a0 to 4f03598 Compare June 18, 2024 06:26
@epage
Copy link
Member

epage commented Jun 19, 2024

I need to split this PR into smaller PRs for easier discussion and review. How should I handle the situation where one resulting PR might be based on another PR?

Either hold off on the follow up PRs or put them up, note the dependency, and rebase once the other PR is merged.

@shannmu shannmu closed this Jun 29, 2024
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.

2 participants