Refactor architecture modules for cargo and rust-analyzer tools#2
Conversation
|
Warning Review limit reached
Your plan currently allows 1 review/hour. Refill in 44 minutes and 50 seconds. Your organization has run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After more review capacity refills, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than trial, open-source, and free plans. In all cases, review capacity refills continuously over time. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (7)
📝 WalkthroughWalkthroughThis PR executes a multi-phase architecture cleanup that reorganizes the codebase into focused module subsystems. The ChangesArchitecture Cleanup Refactor
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/cargo/process.rs`:
- Around line 51-60: When any early return or error occurs (e.g., the Err branch
of tokio::time::timeout around child.wait() or early returns inside
collect_task_outputs), currently spawned reader tasks are left running; modify
the error paths to always abort or join those background tasks before returning.
Specifically, in the timeout match around child.wait() ensure you abort/await
the spawned stdout/stderr reader JoinHandles (the reader tasks created earlier)
in the Ok(Err(error)) and Err(_) branches so they don't detach; likewise update
collect_task_outputs to cancel the sibling task and await its JoinHandle on any
stream error or early return. Ensure you call handle.abort() and then
handle.await().ok() (or otherwise await/join) for the unique JoinHandle
variables so no background tasks remain running.
In `@src/server/response.rs`:
- Around line 62-79: envelope_text currently only enforces
DEFAULT_MAX_TOTAL_OUTPUT_BYTES before truncation; after replacing
envelope.result it reserializes once and returns without guaranteeing the cap.
Modify envelope_text (function handling ToolEnvelope) so that after the second
serde_json::to_string_pretty(&envelope) you check text.len() again and, if it
still exceeds DEFAULT_MAX_TOTAL_OUTPUT_BYTES, further reduce payloads (e.g.,
replace envelope.result with a minimal sentinel message, clear or truncate
envelope.notes and envelope.input) while keeping envelope.truncated = true, then
reserialize in a loop or retry until text.len() <=
DEFAULT_MAX_TOTAL_OUTPUT_BYTES; ensure you use the same error-safe
unwrap_or_else fallback for serialization.
In `@src/server/state.rs`:
- Around line 22-27: The ensure_client method currently returns &mut
RustAnalyzerClient from ServerState which forces callers to hold the ServerState
mutex for the entire async round-trip; refactor by extracting the client field
into its own lock/handle (e.g., replace the single client
Option<RustAnalyzerClient> inside ServerState with a separate
Arc<Mutex<Option<ClientHandle>>> or an Arc<ClientHandle> that can be cloned) and
change ensure_client to return a cloned, owned handle (not a &mut reference) or
a future-safe proxy that performs async operations without holding the global
ServerState mutex; keep workspace/config fields on the original ServerState and
add new accessor methods to read them separately so callers acquire the smaller
lock only to spawn or swap the client (identify code referencing ensure_client,
ServerState::client, and RustAnalyzerClient::spawn to implement the split).
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 13cf0f01-eb51-435a-a885-3f95ead5424b
📒 Files selected for processing (22)
docs/superpowers/plans/2026-05-23-architecture-cleanup.mddocs/superpowers/specs/2026-05-23-architecture-cleanup-design.mdsrc/cargo/args.rssrc/cargo/mod.rssrc/cargo/output.rssrc/cargo/params.rssrc/cargo/process.rssrc/cargo/tools.rssrc/lib.rssrc/ra/completion.rssrc/ra/diagnostics.rssrc/ra/edits.rssrc/ra/locate.rssrc/ra/mod.rssrc/ra/navigation.rssrc/ra/params.rssrc/ra/symbols.rssrc/server/mod.rssrc/server/response.rssrc/server/state.rssrc/tools.rstests/cargo_tests.rs
📜 Review details
🧰 Additional context used
🪛 LanguageTool
docs/superpowers/specs/2026-05-23-architecture-cleanup-design.md
[style] ~19-~19: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ... and metadata parsing. - src/tools.rs mixes tool parameter structs, defaults, and r...
(ENGLISH_WORD_REPEAT_BEGINNING_RULE)
[style] ~129-~129: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ...there is a concrete reason to rename. - Keep existing CLI flags: --workspace, `--d...
(ENGLISH_WORD_REPEAT_BEGINNING_RULE)
[style] ~130-~130: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ...go-tools, --help, and --version`. - Keep stdout reserved for MCP protocol messag...
(ENGLISH_WORD_REPEAT_BEGINNING_RULE)
[style] ~131-~131: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ...erved for MCP protocol messages only. - Keep path containment and bounded-output saf...
(ENGLISH_WORD_REPEAT_BEGINNING_RULE)
[style] ~132-~132: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ...ontainment and bounded-output safety. - Keep cargo tools fixed and structured, not f...
(ENGLISH_WORD_REPEAT_BEGINNING_RULE)
[style] ~133-~133: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ...shell or arbitrary cargo passthrough. - Keep all important current behavior covered ...
(ENGLISH_WORD_REPEAT_BEGINNING_RULE)
[style] ~163-~163: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ...d disabled failures. - cargo_metadata still avoids duplicating parsed metadata JSON...
(ENGLISH_WORD_REPEAT_BEGINNING_RULE)
[style] ~171-~171: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ...generic plugin or registry framework. - Do not convert the rmcp macro routing mode...
(ENGLISH_WORD_REPEAT_BEGINNING_RULE)
[style] ~172-~172: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ...uting model into a custom dispatcher. - Do not add write/apply file-editing tools....
(ENGLISH_WORD_REPEAT_BEGINNING_RULE)
[style] ~173-~173: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ...t add write/apply file-editing tools. - Do not turn cargo tools into free-form com...
(ENGLISH_WORD_REPEAT_BEGINNING_RULE)
🔇 Additional comments (20)
src/cargo/params.rs (1)
1-87: LGTM!src/cargo/output.rs (1)
1-72: LGTM!src/ra/params.rs (1)
1-102: LGTM!src/tools.rs (1)
1-16: LGTM!src/lib.rs (1)
4-4: LGTM!tests/cargo_tests.rs (1)
9-13: LGTM!Also applies to: 15-252, 270-277
docs/superpowers/specs/2026-05-23-architecture-cleanup-design.md (1)
1-174: LGTM!docs/superpowers/plans/2026-05-23-architecture-cleanup.md (1)
1-1309: LGTM!src/cargo/args.rs (1)
4-8: LGTM!Also applies to: 19-27
src/cargo/tools.rs (1)
1-126: LGTM!src/cargo/mod.rs (1)
1-10: LGTM!src/ra/locate.rs (1)
1-62: LGTM!src/ra/navigation.rs (1)
1-22: LGTM!src/ra/completion.rs (1)
1-27: LGTM!src/ra/diagnostics.rs (1)
1-25: LGTM!src/ra/edits.rs (1)
1-23: LGTM!src/ra/symbols.rs (1)
1-5: LGTM!src/ra/mod.rs (1)
1-7: LGTM!src/server/state.rs (1)
3-19: LGTM!Also applies to: 29-71
src/server/mod.rs (1)
1-3: LGTM!Also applies to: 6-35, 62-63, 74-75, 83-84, 93-94, 107-111, 125-126, 134-135, 139-140, 147-148, 159-160, 167-168, 192-193, 201-202, 206-207, 214-215, 229-230, 237-238, 259-260, 268-269, 273-274, 281-282, 301-302, 307-308, 334-335, 348-349, 357-358, 361-363, 370-371, 382-383, 390-391, 402-403, 411-412, 415-417, 424-425, 439-440, 466-467, 475-476, 479-483, 490-491, 502-503, 522-523, 531-532, 535-540, 547-548, 568-569, 588-589, 597-598, 601-602, 609-610, 621-622, 630-631, 657-658, 660-662, 669-670, 715-726, 733-744, 751-762, 769-780, 787-798
Summary
rahelper modules while keeping rmcp tool wrappers onRaMcpServer.Test Plan
cargo fmt --checkcargo test --locked --allcargo clippy --locked --all-targets --all-features -- -D warningscargo build --release --locked.\target\release\rust-analyzer-mcp.exe --versionSummary by CodeRabbit
Release Notes
Documentation
Refactor