fix(zsh): escape colons in completion insert strings#670
Conversation
_describe parses candidate:description in both the display and the insert array, so colons in insert strings must be escaped like the display column already is. Without this, completing a value containing colons (e.g. a mise task named chezmoi:brew:dump) truncates at the first colon, and with -U the next <Tab> replaces text the user already typed past the colon.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: ⛔ Files ignored due to path filters (4)
📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThe PR fixes Zsh completion parsing by escaping colon characters ( ChangesZsh Completion Colon Escaping
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
Greptile SummaryThis PR fixes a zsh completion regression where values containing colons (e.g.
Confidence Score: 5/5Safe to merge — the change is a one-line fix in a single shared template, all snapshots and the pre-rendered asset are updated consistently, and the author verified the fix with a zpty harness against real colon-containing task names. The fix is minimal and targeted: one string-substitution expression in one template function that is the single source of truth for the completion loop. All generated artifacts (snapshots, pre-rendered _usage script) are consistently updated. For values without colons the substitution is a no-op, so there is no regression risk for existing users. For values with colons the : escaping is the documented way to pass literal colons through _describe's candidate:description parser. No files require special attention. Important Files Changed
Reviews (2): Last reviewed commit: "Merge branch 'main' into fix/zsh-colon-i..." | Re-trigger Greptile |
|
This PR currently has failing checks. If this continues for 7 days, it will be closed automatically. This is warning day 1 of 7. Please update the PR when you have a chance. Feel free to reopen or create a new PR if it is closed and you'd like to continue working on it. This comment was generated by an automated workflow. |
This PR is failing due to a public key issue in Codecov, which I can't do anything about. |
Problem
Completing values that contain colons — e.g. a mise task named
chezmoi:brew:dump— truncates at the first colon:The backend output is correct — display column escaped, insert column raw:
But zsh's
_describeparsescandidate:descriptionin both arrays it receives, so every insert string collapses to candidatechezmoiwithbrew:dumptreated as its description. Completion then inserts the truncated value, and because matches are added with-U(replace the current word), the next<TAB>destroys what the user already typed past the colon.Fix
Escape colons in the insert strings in the zsh completion loop, mirroring the escaping the display column already gets:
inserts+=("${insert//:/\\:}")Verified with a zpty completion harness against mise task names:
mise run chez<TAB>mise run chezmoimise run chezmoi:mise run chezmoi:b<TAB>mise run chezmoi(revert!)mise run chezmoi:brew:mise run chezmoi:c<TAB>mise run chezmoi(revert!)mise run chezmoi:cleanupRelated to but distinct from #558 / the v3.x
_describemigration — that covered the display side; this is the insert side.Changes
lib/src/complete/zsh.rs— escape colons inrender_completion_loop(covers both the per-bin script and the shebang-fallback handler), plus a doc comment explaining whycargo insta test --acceptcli/assets/completions/_usagere-rendered viamise run rendercargo test --all --all-featuresandmise run lintpass.Summary by CodeRabbit