Skip to content

Include hidden arguments in shell completion scripts#900

Open
pintaste wants to merge 4 commits into
apple:mainfrom
pintaste:fix/hidden-args-in-completion
Open

Include hidden arguments in shell completion scripts#900
pintaste wants to merge 4 commits into
apple:mainfrom
pintaste:fix/hidden-args-in-completion

Conversation

@pintaste

Copy link
Copy Markdown

Summary

Arguments marked with .hidden visibility are currently excluded from shell completion scripts, along with .private arguments. However, hidden arguments are still part of the public API — they're just deprioritized in help output. Only .private arguments should be excluded from completions.

This PR updates the completion script generation so that:

  • Hidden arguments (.hidden) are included in tab completions (bash, fish, zsh)
  • Private arguments (.private) remain excluded from completions
  • Help output is unchanged — hidden args still don't appear in --help

Changes

  • DumpHelpGenerator.swift: Added includeHiddenArguments parameter to ToolInfoV0.init(commandStack:) and CommandInfoV0.init(commandStack:). When true, sets shouldDisplay = true for .hidden arguments (in addition to .default ones), so completion scripts include them.
  • CompletionsGenerator.swift: Pass includeHiddenArguments: true when building ToolInfoV0 for completion script generation.
  • Updated existing completion snapshots to include the hidden --verbose flag from the Base test command and the hidden --test-* flags from the math example.
  • Added testHiddenAndPrivate_Bash/Fish/Zsh test cases verifying hidden args appear in completions and private args don't.

Testing

swift test --filter "CompletionScriptTests"

All 9 completion tests pass (including 3 new ones).

Fixes #733

Arguments marked with `.hidden` visibility are part of the public API —
they're just deprioritized in help output. Only `.private` arguments
should be excluded from completions.

Passes `includeHiddenArguments: true` when building `ToolInfoV0` for
completion script generation, so hidden args appear in bash, fish, and
zsh completions while private args remain excluded.

Adds tests for all three shells verifying hidden args are present and
private args are absent.
@pintaste pintaste force-pushed the fix/hidden-args-in-completion branch from 75901e6 to 073ea5c Compare May 25, 2026 11:15
@kiwigitops

Copy link
Copy Markdown

I think there are still generated-script regressions in the snapshots after the separator fix. Several bash and fish fixtures now contain actual line breaks inside shell constructs that previously emitted escaped newline sequences, for example in testMathBashCompletionScript().bash, testBase_Bash().bash, and the printf/file-completion expression in testBase_Fish().fish.

There is also an escaping change in shellEscapeForSingleQuotedString: the replacement now drops one backslash from the single-quote escape sequence. That seems unrelated to including hidden arguments and looks like it can under-escape generated completion descriptions such as the escaped-command snapshots.

The previous commit introduced `'\''` which contains `\'`, an invalid
escape sequence in Swift 6.2 — causing swift-format and the Swift
compiler to fail with cascade parse errors from that line onward.

Restore the correct `'\\''` (escaped backslash + two single quotes),
which is the standard shell technique for embedding a literal single
quote inside a single-quoted string.

Regenerate completion snapshots: the invalid escape caused `$'\n'`
sequences in generated bash scripts to appear as literal newlines in the
previously-recorded snapshots; they are now correctly `$'\n'` again.
@kiwigitops

Copy link
Copy Markdown

Thanks, the latest commit restores the $'\n' snapshot sequences and the shellEscapeForSingleQuotedString escape. That addresses the generated-script regression I was worried about.

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.

Include hidden args in completion scripts

2 participants