Skip to content

Fix zsh/fish completions emitting invalid Windows-style option switches - #55466

Merged
baronfel merged 9 commits into
mainfrom
copilot/fix-zsh-autocompletions-script
Oct 6, 2026
Merged

baronfel merged 9 commits into
mainfrom
copilot/fix-zsh-autocompletions-script

Conversation

Copilot AI commented Jul 24, 2026 •

Copy link
Copy Markdown
Contributor

dotnet completions script zsh was emitting Windows-style option aliases (e.g. /v, /verbosity) as _arguments specs, which zsh rejects with:

_arguments:comparguments:327: invalid argument: /v=[Set the MSBuild verbosity level...

This broke path completions for any command that inherits the verbosity option (e.g. dotnet build <TAB>).

Changes

  • ZshShellProvider.cs: Filter option.Names() to only emit names starting with - when generating flag and value option specs
  • FishShellProvider.cs: Same filter applied across state walker case patterns, option value completion switches, and completion candidate output — fish also has no concept of /-prefixed switches
  • Snapshot updates: Removed /v and /verbosity entries from the dotnet CLI zsh snapshot; added new WindowsStyleAliasesAreFilteredOut snapshot tests for both shells

The root cause: CommonOptions.CreateVerbosityOption() registers /v and /verbosity as aliases for Windows MSBuild compatibility. Previously all aliases were forwarded verbatim to Unix shell completion specs.

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
3 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI changed the title [WIP] Fix invalid option switches in zsh autocompletions script Fix zsh/fish completions emitting invalid Windows-style option switches Jul 24, 2026
Copilot AI requested a review from marcpopMSFT July 24, 2026 21:56
@baronfel

Copy link
Copy Markdown
Member

@copilot instead of filtering each list, create a helper for each shell provider that is part of the IShellProvider contract that can be used to sanitize option names, and ensure that each provider uses that sanitized name helper to determine the set of options to generate completion items for.

Copilot AI commented Jul 25, 2026 •

Copy link
Copy Markdown
Contributor Author

@copilot instead of filtering each list, create a helper for each shell provider that is part of the IShellProvider contract that can be used to sanitize option names, and ensure that each provider us...

Done in commit $(git rev-parse --short HEAD). Added SanitizeOptionNames(IEnumerable<string> names) to the IShellProvider interface with a default implementation that filters to --prefixed names. Updated all four providers (ZshShellProvider, FishShellProvider, BashShellProvider, PowerShellShellProvider) to propagate the provider instance through their static helper chains and call provider.SanitizeOptionNames(option.Names()) instead of the inline .Where(n => n.StartsWith('-')) predicates. All 25 tests still pass.

@copilot instead of filtering each list, create a helper for each shell provider that is part of the IShellProvider contract that can be used to sanitize option names, and ensure that each provider us...

Done in commit 40e33ab. Added SanitizeOptionNames(IEnumerable<string> names) to the IShellProvider interface with a default implementation that filters to --prefixed names. Updated all four providers (ZshShellProvider, FishShellProvider, BashShellProvider, PowerShellShellProvider) to propagate the provider instance through their static helper chains and call provider.SanitizeOptionNames(option.Names()) instead of the inline .Where(n => n.StartsWith('-')) predicates. All 25 tests still pass.

Copilot AI requested a review from baronfel July 25, 2026 17:59

@baronfel baronfel left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@copilot some things to address

… a default interface implementation

Co-authored-by: baronfel <[email protected]>

Copilot AI commented Jul 25, 2026

Copy link
Copy Markdown
Contributor Author

@copilot some things to address

Addressed in the latest commit — details in the inline thread replies above.

Copilot AI requested a review from baronfel July 25, 2026 18:15
@baronfel
baronfel marked this pull request as ready for review July 25, 2026 18:28
Copilot AI review requested due to automatic review settings July 25, 2026 18:28
@baronfel
baronfel requested a review from a team as a code owner July 25, 2026 18:28
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
2 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This pull request fixes Unix shell completion script generation (zsh/fish) by filtering out Windows-style option aliases (e.g., /v, /verbosity) that are invalid in those shells’ completion grammars, resolving the zsh _arguments failure reported in #55416.

Changes:

  • Filter option aliases so only -/---prefixed names are emitted into zsh and fish completion specs.
  • Add snapshot-based regression tests for “Windows-style aliases are filtered out” and update the dotnet CLI zsh snapshot accordingly.
  • Introduce an IShellProvider.SanitizeOptionNames(...) API and implement it across shell providers.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
test/System.CommandLine.StaticCompletions.Tests/ZshShellProviderTests.cs Adds a new regression test ensuring /-prefixed aliases do not appear in zsh scripts.
test/System.CommandLine.StaticCompletions.Tests/snapshots/zsh/ZshShellProviderTests.WindowsStyleAliasesAreFilteredOut.verified.zsh New verified zsh snapshot for the regression test.
test/System.CommandLine.StaticCompletions.Tests/FishShellProviderTests.cs Replaces an existing test with a new regression test for filtering /-prefixed aliases.
test/System.CommandLine.StaticCompletions.Tests/snapshots/fish/FishShellProviderTests.WindowsStyleAliasesAreFilteredOut.verified.fish New verified fish snapshot for the regression test.
test/dotnet.Tests/CompletionTests/snapshots/zsh/DotnetCliSnapshotTests.VerifyCompletions.verified.zsh Updates CLI zsh snapshot to remove /v and /verbosity.
src/System.CommandLine.StaticCompletions/shells/ZshShellProvider.cs Filters option names to --prefixed when emitting _arguments specs.
src/System.CommandLine.StaticCompletions/shells/FishShellProvider.cs Filters option names to --prefixed across state walking, value completion, and candidate output.
src/System.CommandLine.StaticCompletions/shells/ShellProvider.cs Adds SanitizeOptionNames to the IShellProvider interface.
src/System.CommandLine.StaticCompletions/shells/BashShellProvider.cs Applies alias sanitization in option handler generation and refactors option handler emission.
src/System.CommandLine.StaticCompletions/shells/PowershellShellProvider.cs Applies alias sanitization to generated option-name completions.
src/System.CommandLine.StaticCompletions/shells/NuShellShellProvider.cs Implements SanitizeOptionNames for NuShell provider.

@baronfel

Copy link
Copy Markdown
Member

Actually, thinking about this more we should consider making this change in dotnet/command-line-api itself, then migrating to use that here.

@baronfel

Copy link
Copy Markdown
Member

When this is merged we should port it over to dotnet/command-line-api, so that when we reconcile the static completions there and delete dotnet's local copy we don't lose any features.

@marcpopMSFT

marcpopMSFT commented Oct 2, 2026 •

Copy link
Copy Markdown
Member

🤖 @baronfel, could you review the fish filtering in WriteStateWalker? I think it needs to distinguish aliases offered as suggestions from aliases recognized in already-typed input.

The new SanitizeOptionNames calls in the single-value and multi-value walker branches remove slash aliases from the generated case patterns. Unlike zsh's _arguments option-spec grammar, fish accepts /verbosity as a literal case pattern, and the CLI parser still accepts the alias.

This can make the walker interpret an option value as a subcommand. For a command with a single-value --verbosity//verbosity option and a subcommand named quiet:

mycommand /verbosity quiet <TAB>

Previously, the walker recognized /verbosity and skipped its value. With this filtering, it fails to recognize the option and instead enters the quiet subcommand's completion state. I reproduced the lost root-command suggestions in fish 3.3.1 using a synthetic command tree; restoring /verbosity only in the walker restored the correct context. I have not established an equivalent name/value collision in the current dotnet command tree.

Could we keep o.Names() in both walker branches, independently of filtering the aliases offered as completion candidates, and add a regression test where a slash-prefixed option consumes a value that matches a subcommand name?

@baronfel

baronfel commented Oct 5, 2026

Copy link
Copy Markdown
Member

@marcpopMSFT that finding makes sense to me, I agree it's an issue and the agent should reimplement the fix with that in mind.

@copilot can you apply this change to fix the fish command/argument matching?

@baronfel

baronfel commented Oct 6, 2026

Copy link
Copy Markdown
Member

@copilot can you try to apply the change @marcpopMSFT mentioned in #55466 (comment)?

auto-merge was automatically disabled October 6, 2026 00:12

Head branch was pushed to by a user without write access

Copilot AI commented Oct 6, 2026

Copy link
Copy Markdown
Contributor Author

@copilot can you try to apply the change @marcpopMSFT mentioned in #55466 (comment)?

Implemented in 5ce7ab90. Fish now recognizes all aliases in state-walker case patterns while continuing to filter slash-prefixed completion suggestions. Added regression coverage where /verbosity consumes quiet, which is also a subcommand.

@baronfel baronfel left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@marcpopMSFT this LGTM now!

@baronfel
baronfel enabled auto-merge October 6, 2026 22:56
@baronfel
baronfel merged commit fbf921a into main Oct 6, 2026
23 checks passed
@baronfel
baronfel deleted the copilot/fix-zsh-autocompletions-script branch October 6, 2026 23:17
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Oct 7, 2026
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.

zsh autocompletions script emits invalid option switches

5 participants