Repository navigation
Fix zsh/fish completions emitting invalid Windows-style option switches - #55466
Conversation
|
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. |
…starting with '/') Co-authored-by: marcpopMSFT <[email protected]>
|
@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. |
…Names contract method Co-authored-by: baronfel <[email protected]>
Done in commit
Done in commit |
… a default interface implementation Co-authored-by: baronfel <[email protected]>
Addressed in the latest commit — details in the inline thread replies above. |
|
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. |
There was a problem hiding this comment.
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. |
|
Actually, thinking about this more we should consider making this change in dotnet/command-line-api itself, then migrating to use that here. |
…Windows-style aliases Co-authored-by: baronfel <[email protected]>
|
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 |
|
🤖 @baronfel, could you review the fish filtering in The new This can make the walker interpret an option value as a subcommand. For a command with a single-value Previously, the walker recognized Could we keep |
|
@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? |
|
@copilot can you try to apply the change @marcpopMSFT mentioned in #55466 (comment)? |
Co-authored-by: baronfel <[email protected]>
Head branch was pushed to by a user without write access
Implemented in |
dotnet completions script zshwas emitting Windows-style option aliases (e.g./v,/verbosity) as_argumentsspecs, which zsh rejects with:This broke path completions for any command that inherits the verbosity option (e.g.
dotnet build <TAB>).Changes
ZshShellProvider.cs: Filteroption.Names()to only emit names starting with-when generating flag and value option specsFishShellProvider.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/vand/verbosityentries from the dotnet CLI zsh snapshot; added newWindowsStyleAliasesAreFilteredOutsnapshot tests for both shellsThe root cause:
CommonOptions.CreateVerbosityOption()registers/vand/verbosityas aliases for Windows MSBuild compatibility. Previously all aliases were forwarded verbatim to Unix shell completion specs.