Skip to content

fix(parse): report next implicit clause argument - #1372

Merged
jdx merged 1 commit into
jdx:mainfrom
3w36zj6:feature/parse-next-implicit-clause-argument
Sep 3, 2026
Merged

fix(parse): report next implicit clause argument#1372
jdx merged 1 commit into
jdx:mainfrom
3w36zj6:feature/parse-next-implicit-clause-argument

Conversation

@3w36zj6

@3w36zj6 3w36zj6 commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Summary

  • report the next implicit clause argument when a partial parse stops
  • restore choices and custom completions for that argument on a bare command
  • add a regression test for the parser's stopping position

Problem

The parser tracks next_arg_idx against active_args, which selects clause.args for commands
with a clause. However, record_stop resolved that index against cmd.args directly. Because a
command cannot declare both top-level arguments and a clause, cmd.args is empty for clause
commands.

As a result, parsing a bare command with an implicit clause incorrectly returned
ParseOutput::next_arg as None, even though the clause's first argument was ready to accept a
value. Completion relies on next_arg, so it could not offer the argument's choices or invoke its
custom completer.

Fix

Resolve the stopping position through active_args, matching the collection used by
next_arg_idx throughout parsing. Ordinary command arguments retain the existing behavior, while
clause commands now return the corresponding argument from clause.args. Update the cursor comment
to describe both cases and cover the implicit-clause case with a focused regression test.

Testing

  • cargo test -p usage-lib --all-features a_partial_parse_reports_the_next_implicit_clause_argument
  • cargo test -p usage-lib --all-features parse::tests
  • mise run lint
  • mise run lint-fix

Summary by CodeRabbit

  • Bug Fixes
    • Improved partial command parsing for commands with clauses.
    • The reported next positional argument now correctly reflects the active clause context, helping users receive more accurate parsing and completion behavior.

@coderabbitai

coderabbitai Bot commented Sep 3, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Central YAML (base), Organization UI (inherited)

Review profile: CHILL

Plan: Team

Run ID: 7615a69a-5cf2-4a81-9c62-c16a17409f64

📥 Commits

Reviewing files that changed from the base of the PR and between 4d51490 and ec01ee4.

📒 Files selected for processing (1)
  • lib/src/parse.rs

Included review availability: Your plan provides up to 4 included reviews per hour; 3 remain after this review.


📝 Walkthrough

Walkthrough

The parser now derives next_arg from active positional arguments. For clause-based commands, partial parsing reports the next clause argument. A regression test covers this behavior.

Changes

Clause-aware parsing

Layer / File(s) Summary
Active argument cursor and regression coverage
lib/src/parse.rs
record_stop now uses active_args(&out.cmd) for next_arg. The Phase 2 comment describes the active positional arguments. A test verifies that partial parsing reports tool@version for a tools clause.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to ec01e

Partial parsing now reports the active implicit clause argument, restoring its available choices and custom completions. The focused regression coverage supports merge readiness with no outstanding risk.

Suggested reviewers: jdx, jambalaya56562

Poem

A rabbit hops through clauses bright
The next tool waits in plain sight
The cursor follows where args flow
A test confirms the path below
Parse the words, then onward go

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 1 files.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: reporting the next implicit clause argument during parsing.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@3w36zj6
3w36zj6 marked this pull request as ready for review September 3, 2026 17:37
@jdx
jdx merged commit 4cdd785 into jdx:main Sep 3, 2026
10 checks passed
@3w36zj6
3w36zj6 deleted the feature/parse-next-implicit-clause-argument branch September 4, 2026 13:27
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.

2 participants