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

ZSH Completion Script incorrect #5789

Closed
MarcoEidinger opened this issue Oct 3, 2022 · 7 comments · Fixed by #5852
Closed

ZSH Completion Script incorrect #5789

MarcoEidinger opened this issue Oct 3, 2022 · 7 comments · Fixed by #5852
Labels

Comments

@MarcoEidinger
Copy link
Contributor

Description

Trying to use auto-completion for swift package (or other SwiftPM commands) relying on completion script generated with swift package completion-tool generate-zsh-script

Expected behavior

Code completion appears

Actual behavior

Getting parsing error when trying code completion

Code Completion Error

Steps to reproduce

Run the commands as noted in https://github.com/apple/swift-package-manager/blob/main/Documentation/Usage.md#using-shell-completion-scripts

mkdir ~/.zsh
swift package completion-tool generate-zsh-script > ~/.zsh/_swift
echo -e "fpath=(~/.zsh \$fpath)\n" >> ~/.zshrc
compinit

Then open new terminal and try auto-complete (TAB) for swift package

Swift Package Manager version/commit hash

Swift 5.6.1 (Xcode 13.4.1)

Swift & OS version (output of swift --version && uname -a)

swift-driver version: 1.45.2 Apple Swift version 5.6.1 (swiftlang-5.6.0.323.66 clang-1316.0.20.12)
Target: arm64-apple-macosx12.0

@tomerd
Copy link
Member

tomerd commented Oct 7, 2022

@bitjammer is this something you are familiar with?

@neonichu
Copy link
Member

neonichu commented Oct 7, 2022

We're just calling ParsableArguments.completionScript(for:) from argument parser for this, btw.

@rauhul
Copy link
Contributor

rauhul commented Oct 9, 2022

If you could reduce this to a small reproducer and open an issue in apple/swift-argument-parser we can take a look!

@MarcoEidinger
Copy link
Contributor Author

It appears that using an empty string as a value for commandName in DefaultCommand causes the issue.

In my small reproducer (https://github.com/MarcoEidinger/spm-issue-5789-repo) I find no issues when using commandName: nil,

@rauhul please advise if you see this as issue for apple/swift-argument-parser and I should create an issue there OR if you think that SPM shall change their implementation

FYI @neonichu

@rauhul
Copy link
Contributor

rauhul commented Oct 28, 2022

Looks like a sap bug imo, though the quick solution for spm is changing the default to nil. I can probably fix the sap issue tomorrow morning, but filing an issue would be good regardless!

Thanks a ton for tracking down the bug 💛

@MarcoEidinger
Copy link
Contributor Author

I created PR to change SPM for an easy solution.

SPM is using swift-argument-parser@1.0.3

@rauhul further testing reveals that this particular issue is solved in swift-argument-parser@1.1.4 due to apple/swift-argument-parser#443 which filters out subcommands that shall not be displayed which would be the case for SPM's DefaultCommand

extension SwiftPackageTool {
    // This command is the default when no other subcommand is passed. It is not shown in the help and is never invoked directly.
    struct DefaultCommand: SwiftCommand {
        static let configuration = CommandConfiguration(
            commandName: "",
            shouldDisplay: false) // <====!!!!!!!!!!!
         }
     }
}

Hence I won't file an issue in swift-argument-parser

@rauhul
Copy link
Contributor

rauhul commented Oct 28, 2022

I think this is still reveals a bug in sap as we should never generate illegal completion scripts.

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

Successfully merging a pull request may close this issue.

4 participants