Fix zsh compadd shim dropping descriptions from _describe's clustered -ld - #15313
Draft
warp-agent-staging[bot] wants to merge 1 commit into
Draft
Fix zsh compadd shim dropping descriptions from _describe's clustered -ld#15313warp-agent-staging[bot] wants to merge 1 commit into
warp-agent-staging[bot] wants to merge 1 commit into
Conversation
… -ld The completions `compadd` shim located the description array with an exact match on `-d`, but `_describe` never passes that flag on its own -- it passes it clustered with other short flags, as `-ld`. The lookup therefore found nothing, no description array was resolved, and every match produced via `_describe` came back with an empty description. `_arguments`-based option descriptions, which do pass `-d` unclustered, were unaffected, which is why some completions had descriptions and others silently did not. Match any flag token of a leading `-`, zero or more letters and a trailing `d` instead of requiring an exact `-d`, and keep using `(I)` rather than `(i)`: `(i)` returns one past the end instead of 0 when nothing matches, which would make the presence test true on every call. The search is also restricted to the leading flags-only prefix the neighboring `-O`/`-A`/`-D` check already uses, so a completion candidate that happens to look like a flag -- a literal `-d` or `-ld`, as `ls` and `find` offer -- is never mistaken for the flag itself. Fixes CORE-3795.
Contributor
Author
|
This PR was generated with Warp. Comment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Summary
The zsh completions
compaddshim silently drops every description that comes from_describe.app/assets/bundled/bootstrap/zsh_body.shlocated the description array with an exact-match index lookup,$@[(I)-d]._describenever passes that flag on its own — it passes it clustered with other short flags, as-ld. The lookup therefore returned 0, no description array was resolved, and every match produced through_describecame back with an empty description._arguments-based option descriptions, which do pass-dunclustered, were unaffected. That is why the bug is easy to miss: some completions have descriptions and others silently do not.Fix
Match any flag token consisting of a leading
-, zero or more letters and a trailingd, instead of requiring an exact-d.Two details worth calling out:
(I), not(i).${@[(i)pattern]}returns$# + 1rather than 0 when nothing matches, which would make the test true on everycompaddcall and resolve an empty array name.-/--— exactly as the neighboring-O/-A/-Dcheck already does. Without that, the lookup scans the candidate words too, so a completion candidate that happens to look like a flag (a literal-dor-ld, aslsandfindoffer) would be taken as the description flag and the following candidate expanded as an array name.Verification
Verified in a real zsh 5.9:
git chpreviously yielded matches with empty descriptions, and now yieldscheckout→ "checkout branch or paths to working tree",cherry-pick→ "apply changes introduced by some existing commits", and so on for all eight matches. Also checked against argument lists with no-dat all, with a plain-d, with a clustered-ld, and with candidates that themselves look like flags.The affected code is reachable only behind
FeatureFlag::NativeShellCompletions, which is off on every channel, so there is no user-visible impact today. It is worth fixing before that flag is promoted, and it is independent of any change to how completions are triggered.Stack
This is the first PR of a two-PR stack and should merge first:
compaddshim description fix (CORE-3795)#15294 depends on this fix, since its zsh path relies on descriptions being resolved correctly.