Skip to content

Conversation

rgoldberg
Copy link
Contributor

Improve zsh completion script generation.

There are many issues with script generation. Some of them are documented in #679 & its comments.

This PR is for a first batch of zsh completion script fixes.

Each commit should note the fix(es) that it contains.

If you want documentation of the fixes directly in the GitHub issue #726 and/or in this PR without having to look at the commit messages, I can include info from the commit messages here and/or in the issue description.

If you want the this PR split up, parts removed or changed, etc., please let me know, and I'll make the requisite changes.

After this PR is merged, I will sequentially create an issue & submit a PR each for initial bash & fish fixes, then one or more PRs for cross-shell changes, then I will resume working on more fixes.

Resolve #726

Checklist

  • I've added at least one test that validates that my change is working, if appropriate
  • I've followed the code style of the rest of the project
  • I've read the Contribution Guidelines
  • I've updated the documentation if necessary

@natecook1000
Copy link
Member

@swift-ci Please test

Copy link
Member

@natecook1000 natecook1000 left a comment

Choose a reason for hiding this comment

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

Thanks so much for this awesome work, @rgoldberg! From testing it looks flawless, just have a few minor notes/questions below.

@rgoldberg
Copy link
Contributor Author

rgoldberg commented Feb 13, 2025

@natecook1000 Thanks for the feedback. Do you want me to update things via new commits, or by fixing existing commits & force pushing? I assume the former, since it seems like SAP squashes PRs, but I wanted to check with you first.

I will push new commits with fixes so I can resolve conversations here with code having been submitted. If you want me to redo existing commits then force push to keep the PR commit history cleaner, let me know; if so, I'll move the changes from the new commits to the original commits, then force push.

@rgoldberg
Copy link
Contributor Author

rgoldberg commented Feb 14, 2025

@natecook1000 I've submitted fixes in new commits for the conversations that I've resolved. Waiting for your instructions on the open conversations. Thanks for all the feedback & help.

@rgoldberg
Copy link
Contributor Author

Rebased on the new main as there is a simple conflict that needed to be resolved.

@natecook1000
Copy link
Member

Feel free to handle commits/updating however's most comfortable for you – we'll squash on merge, so the in-process commits aren't terribly important.

Simplify zsh indent generation.

Signed-off-by: Ross Goldberg <484615+rgoldberg@users.noreply.github.com>
Signed-off-by: Ross Goldberg <484615+rgoldberg@users.noreply.github.com>
Brace & quote parameter uses.

Use [@] for quoted array output.

Signed-off-by: Ross Goldberg <484615+rgoldberg@users.noreply.github.com>
Signed-off-by: Ross Goldberg <484615+rgoldberg@users.noreply.github.com>
4 consecutive single quotes were obviously intended to be 2 escaped single quotes, but that isn't zsh syntax.

Use 2 double quotes instead.

Signed-off-by: Ross Goldberg <484615+rgoldberg@users.noreply.github.com>
Signed-off-by: Ross Goldberg <484615+rgoldberg@users.noreply.github.com>
Remove trailing spaces from InstallingCompletionScripts.md.

Signed-off-by: Ross Goldberg <484615+rgoldberg@users.noreply.github.com>
Signed-off-by: Ross Goldberg <484615+rgoldberg@users.noreply.github.com>
Signed-off-by: Ross Goldberg <484615+rgoldberg@users.noreply.github.com>
Signed-off-by: Ross Goldberg <484615+rgoldberg@users.noreply.github.com>
If someone already escapes single quotes from the String, this will cause an issue, but no one should be required to go to the trouble to manually escape single quotes in their script, especially since the requirement isn't documented or normal.

Signed-off-by: Ross Goldberg <484615+rgoldberg@users.noreply.github.com>
If a Swift custom completion function returns an empty [String], if the user tries to complete it, refuse to complete instead of inserting a blank space into the command line.

If a Swift custom completion function returns a [String] including a Swift empty String or including a String with a description but with a blank completion (e.g., ":description"), if that completion is selected, complete to a zsh empty string '' instead of inserting a blank space into the command line.

Disambiguating between an empty [String] & a [String] with one empty String element requires that an extra value be appended to the output of the Swift custom function, which is then removed by the completion script.

Signed-off-by: Ross Goldberg <484615+rgoldberg@users.noreply.github.com>
Signed-off-by: Ross Goldberg <484615+rgoldberg@users.noreply.github.com>
Signed-off-by: Ross Goldberg <484615+rgoldberg@users.noreply.github.com>
Signed-off-by: Ross Goldberg <484615+rgoldberg@users.noreply.github.com>
Signed-off-by: Ross Goldberg <484615+rgoldberg@users.noreply.github.com>
Signed-off-by: Ross Goldberg <484615+rgoldberg@users.noreply.github.com>
Signed-off-by: Ross Goldberg <484615+rgoldberg@users.noreply.github.com>
Disable history ! in zsh completion scripts.

Signed-off-by: Ross Goldberg <484615+rgoldberg@users.noreply.github.com>
…ift.

Signed-off-by: Ross Goldberg <484615+rgoldberg@users.noreply.github.com>
…nsion.

Signed-off-by: Ross Goldberg <484615+rgoldberg@users.noreply.github.com>
Move from ArgumentDefinition extension to [ParsableCommand.Type] extension.

Signed-off-by: Ross Goldberg <484615+rgoldberg@users.noreply.github.com>
…ells.

Signed-off-by: Ross Goldberg <484615+rgoldberg@users.noreply.github.com>
Function names are globally scoped.

Without namespacing, if 2 programs use different versions of Swift Argument Parser, one could overwrite the other's different version of the same helper function.

Renamed functions from *_completion to *_complete, as they complete, not return a completion.

Signed-off-by: Ross Goldberg <484615+rgoldberg@users.noreply.github.com>
Signed-off-by: Ross Goldberg <484615+rgoldberg@users.noreply.github.com>
Signed-off-by: Ross Goldberg <484615+rgoldberg@users.noreply.github.com>
Signed-off-by: Ross Goldberg <484615+rgoldberg@users.noreply.github.com>
Signed-off-by: Ross Goldberg <484615+rgoldberg@users.noreply.github.com>
Allows list completions to contain spaces.

Resolve apple#726

Signed-off-by: Ross Goldberg <484615+rgoldberg@users.noreply.github.com>
Signed-off-by: Ross Goldberg <484615+rgoldberg@users.noreply.github.com>
Redid a comment as a DocC.

Signed-off-by: Ross Goldberg <484615+rgoldberg@users.noreply.github.com>
Document why & how this pseudo-completion is used.

Do not trim whitespace in testing, as that breaks with the space pseudo-completion.

Testing should be as exact as possible; trimming whitespace makes it less exact.

Signed-off-by: Ross Goldberg <484615+rgoldberg@users.noreply.github.com>
…commands.

Force unwrap first in ZshCompletionsGenerator.swift.

Signed-off-by: Ross Goldberg <484615+rgoldberg@users.noreply.github.com>
@rgoldberg
Copy link
Contributor Author

@natecook1000 I've finished all the fixes. Please note that I cannot move the members from the extension Sequence to the extension […] because in some not-yet submitted commits for bash completion script generation, I need one of the members in extension Sequence, so I should leave both in case we need the other there in the future, too.

I've also rebased on main.

Copy link
Member

@natecook1000 natecook1000 left a comment

Choose a reason for hiding this comment

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

Code changes look great! Just a little bit of cleanup, then we're good to merge 🎉

@rgoldberg
Copy link
Contributor Author

@natecook1000 Just replied to your 2 comments.

@natecook1000 natecook1000 enabled auto-merge (squash) February 15, 2025 18:52
@natecook1000
Copy link
Member

@swift-ci Please test
@swift-ci Please test

@natecook1000 natecook1000 merged commit f2eda39 into apple:main Feb 15, 2025
22 checks passed
@rgoldberg rgoldberg deleted the 726-zsh-completion branch February 15, 2025 19:00
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.

Improve zsh completion script generation
3 participants