apple / swift-argument-parser

Straightforward, type-safe argument parsing for Swift
Apache License 2.0
3.3k stars 311 forks source link

Zsh completion missing for arguments in an option group with custom completion #646

Closed CraigSiemens closed 1 month ago

CraigSiemens commented 2 months ago

Zsh completions are not shown for arguments that are added to a command using an @OptionGroup and that have a custom completion kind.

ArgumentParser version: main Swift version:

swift-driver version: 1.90.11.1 Apple Swift version 5.10 (swiftlang-5.10.0.13 clang-1500.3.9.4)
Target: arm64-apple-macosx14.0

Checklist

Steps to Reproduce

  1. Create a command with an option group with an arguments with a custom completion kind.

    import ArgumentParser
    
    struct ArgOptionGroup: ParsableArguments {
        @Argument(completion: .custom { _ in
            ["1-argInOptionGroup", "2-argInOptionGroup", "3-argInOptionGroup"]
        })
        var argInOptionGroup: String
    }
    
    @main
    struct CompletionExample: ParsableCommand {
        @Argument(completion: .custom { _ in
            ["1-argInCommand", "2-argInCommand", "3-argInCommand"]
        })
        var argInCommand: String
    
        @OptionGroup var optionGroup: ArgOptionGroup
    }
  2. Install the completions in your terminal and load them, steps will vary per environment, for me the steps are.

    1. swift build
    2. Install the completions.
      ./completion-example --generate-completion-script zsh > ~/.oh-my-zsh/completions/_completion-example
    3. Open a new terminal to load the new completions.
  3. Type ./completion-example (note the trailing space)

  4. Press tab to accept the first completion

  5. Press space.

  6. Type 1 (the first character of one of the arguments.

Expected behavior

It should suggest completions for the argument from the option group, as it did for the argument in the command (step 3).

Actual behavior

It doesn't show any completions for the arguments in the option group (step 4). When starting to type any of the options that should be suggested (step 5), it prints that there are no matches (probably from zsh-autosuggestions).