Skip to content

fix(cli): put tasks first in zsh dynamic completions - #31350

Merged
nathanwhit merged 1 commit into
denoland:mainfrom
nathanwhit:zsh-completions-tasks-first
Nov 20, 2025
Merged

nathanwhit merged 1 commit into
denoland:mainfrom
nathanwhit:zsh-completions-tasks-first

Conversation

@nathanwhit

Copy link
Copy Markdown
Member

It's kind of annoying because it requires copying some code from clap, but it's the only solution I could find

@coderabbitai

coderabbitai Bot commented Nov 19, 2025 •

Copy link
Copy Markdown

Walkthrough

The pull request adds the shlex crate as a workspace dependency and registers it in the CLI crate. Additionally, a new ZshCompleterUnsorted struct is introduced that implements the EnvCompleter trait to provide dynamic shell completion for zsh while preserving completion order. This new completer is then registered with clap_complete::CompleteEnv alongside existing shell completers (Bash, Elvish, Fish, PowerShell).

Sequence Diagram

sequenceDiagram
    participant User
    participant CLI
    participant CompleteEnv
    participant ZshCompleterUnsorted
    participant Zsh
    
    User->>CLI: Request shell completion
    CLI->>CompleteEnv: with_factory([Bash, Elvish, Fish, PowerShell, ZshCompleterUnsorted])
    alt Zsh Shell Detected
        CompleteEnv->>ZshCompleterUnsorted: is() check
        ZshCompleterUnsorted-->>CompleteEnv: true
        CompleteEnv->>ZshCompleterUnsorted: write_registration()
        ZshCompleterUnsorted-->>Zsh: Registration script (preserves order)
        CompleteEnv->>ZshCompleterUnsorted: write_complete()
        ZshCompleterUnsorted-->>Zsh: Completion candidates
    else Other Shell
        CompleteEnv->>CompleteEnv: Use standard completer
    end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • New dependency addition is mechanical and straightforward
  • ZshCompleterUnsorted struct is a standard trait implementation with no complex logic
  • Changes are localized to dependency declarations and one completion registry update
  • No control flow modifications beyond registering the new completer in the factory list

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: implementing custom zsh completion handling to prioritize tasks in the dynamic completion list.
Description check ✅ Passed The description relates to the changeset by acknowledging the implementation approach (copying clap code), though it lacks detail about the actual changes.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d8bab83 and bca624f.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (3)
  • Cargo.toml (1 hunks)
  • cli/Cargo.toml (1 hunks)
  • cli/args/flags.rs (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (10)
  • GitHub Check: test debug macos-aarch64
  • GitHub Check: test debug linux-x86_64
  • GitHub Check: test debug linux-aarch64
  • GitHub Check: test release linux-x86_64
  • GitHub Check: test debug windows-x86_64
  • GitHub Check: test debug macos-x86_64
  • GitHub Check: build libs
  • GitHub Check: lint debug windows-x86_64
  • GitHub Check: lint debug linux-x86_64
  • GitHub Check: lint debug macos-x86_64
🔇 Additional comments (5)
cli/Cargo.toml (2)

171-171: Workspace dependency reference is correctly configured.

The shlex dependency is properly referenced using the workspace pattern, consistent with other workspace members in the cli package.


1-196: Missing implementation file from review context.

The AI summary indicates that cli/args/flags.rs contains the primary implementation changes (ZshCompleterUnsorted struct, EnvCompleter trait implementation), but this file was not provided for review.

The dependency declarations in both Cargo.toml files appear correct, but the functional implementation and the mentioned code duplication from clap cannot be assessed without reviewing the actual implementation file.

Please provide cli/args/flags.rs (or the appropriate flags file where ZshCompleterUnsorted is implemented) for a complete review of this change.

Cargo.toml (1)

249-249: Shlex 1.3.0 is compatible and current—no changes needed.

Verification confirms that shlex 1.3.0 is compatible with clap 4.5.47 (shlex is used as a dev-dependency in clap itself), and shlex 1.3.0 is the latest available version. The dependency addition to workspace.dependencies is correctly placed and versioned.

Note: clap_complete 4.5.60 is the latest version (current is 4.5.57), though that's a separate upgrade decision.

cli/args/flags.rs (2)

29-30: Imports for dynamic completion look correct

EnvCompleter and Shells are used below in ZshCompleterUnsorted and handle_shell_completion_with_args; imports are minimal and appropriate.


6339-6416: Custom zsh EnvCompleter correctly preserves completion order

The ZshCompleterUnsorted implementation looks sound:

  • name() / is() consistently identify "zsh", so it will be selected for zsh dynamic completions.
  • write_registration:
    • Uses shlex::try_quote for bin and completer, matching clap’s approach and keeping the generated script shell-safe.
    • Placeholder replacement for NAME, COMPLETER, BIN, and VAR yields the expected zsh function with <var>="zsh" and the right command invocation.
    • _describe -V 'values' completions -o nosort should preserve the original candidate order as intended.
  • write_complete delegates to clap_complete::env::Zsh.write_complete, so only the registration script behavior is customized.
  • Shells(&[..., &ZshCompleterUnsorted]) wires this in for zsh only, without affecting other shells.

Overall this is a targeted, low‑risk change that achieves ordered zsh dynamic completions.

Tip

📝 Customizable high-level summaries are now available in beta!

You can now customize how CodeRabbit generates the high-level summary in your pull requests — including its content, structure, tone, and formatting.

  • Provide your own instructions using the high_level_summary_instructions setting.
  • Format the summary however you like (bullet lists, tables, multi-section layouts, contributor stats, etc.).
  • Use high_level_summary_in_walkthrough to move the summary from the description to the walkthrough section.

Example instruction:

"Divide the high-level summary into five sections:

  1. 📝 Description — Summarize the main change in 50–60 words, explaining what was done.
  2. 📓 References — List relevant issues, discussions, documentation, or related PRs.
  3. 📦 Dependencies & Requirements — Mention any new/updated dependencies, environment variable changes, or configuration updates.
  4. 📊 Contributor Summary — Include a Markdown table showing contributions:
    | Contributor | Lines Added | Lines Removed | Files Changed |
  5. ✔️ Additional Notes — Add any extra reviewer context.
    Keep each section concise (under 200 words) and use bullet or numbered lists for clarity."

Note: This feature is currently in beta for Pro-tier users, and pricing will be announced later.


Comment @coderabbitai help to get the list of available commands and usage tips.

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 PR fixes zsh dynamic completions to preserve the order of completion suggestions (putting tasks first) by implementing a custom zsh completer that uses the -o nosort flag.

  • Adds ZshCompleterUnsorted struct implementing EnvCompleter trait with custom zsh script generation
  • Configures CompleteEnv to use custom shells list including the new zsh completer
  • Adds shlex dependency for proper shell escaping

Reviewed Changes

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

File Description
cli/args/flags.rs Implements custom zsh completer with -o nosort flag and updates shell completion configuration
cli/Cargo.toml Adds shlex dependency to workspace members
Cargo.toml Adds shlex 1.3.0 to workspace dependencies
Cargo.lock Updates lock file with shlex dependency

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread cli/args/flags.rs Resolved
Comment thread cli/args/flags.rs Resolved
@nathanwhit
nathanwhit enabled auto-merge (squash) November 19, 2025 20:30
@nathanwhit
nathanwhit merged commit 931a5c7 into denoland:main Nov 20, 2025
bartlomieju pushed a commit that referenced this pull request Jan 22, 2026
It's kind of annoying because it requires copying some code from clap,
but it's the only solution I could find
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.

3 participants