Conversation
Make fields private, add constructor and getters, and update parser tests.
Reviewer's GuideEncapsulates the internal span lists in ParsedSpans by making the fields private, introducing a constructor and read-only getter methods, and updating parser logic and tests to use the new API. Class diagram for encapsulated ParsedSpansclassDiagram
class ParsedSpans {
- imports: Vec<Span>
- typedefs: Vec<Span>
- relations: Vec<Span>
- indexes: Vec<Span>
- functions: Vec<Span>
- rules: Vec<Span>
+ new(imports: Vec<Span>, typedefs: Vec<Span>, relations: Vec<Span>, indexes: Vec<Span>, functions: Vec<Span>, rules: Vec<Span>)
+ imports() &[Span]
+ typedefs() &[Span]
+ relations() &[Span]
+ indexes() &[Span]
+ functions() &[Span]
+ rules() &[Span]
- assert_sorted()
}
class Span
ParsedSpans --> Span : contains Vec<>
File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
Warning Rate limit exceeded@leynos has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 5 minutes and 46 seconds before requesting another review. ⌛ How to resolve this issue?After the wait time has elapsed, 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 the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📒 Files selected for processing (1)
Summary by CodeRabbit
WalkthroughThe Changes
Sequence Diagram(s)sequenceDiagram
participant Caller
participant ParsedSpans
Caller->>ParsedSpans: new(imports, typedefs, relations, indexes, functions, rules)
ParsedSpans-->>ParsedSpans: Debug assertions (sorted, non-overlapping)
ParsedSpans-->>Caller: ParsedSpans instance
Caller->>ParsedSpans: imports()/typedefs()/relations()/...
ParsedSpans-->>Caller: &[Span] for requested category
Possibly related issues
Possibly related PRs
Poem
✨ Finishing Touches
🧪 Generate unit tests
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Hey @leynos - I've reviewed your changes - here's some feedback:
- There are still direct field accesses like
spans.importsin build_green_tree; please replace all of them with the new accessor methods (e.g.spans.imports()). - Since
ParsedSpans::newdocuments that its inputs must be sorted and non-overlapping, consider adding debug assertions inside new so any violations are caught immediately.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- There are still direct field accesses like `spans.imports` in build_green_tree; please replace all of them with the new accessor methods (e.g. `spans.imports()`).
- Since `ParsedSpans::new` documents that its inputs must be sorted and non-overlapping, consider adding debug assertions inside new so any violations are caught immediately.
## Individual Comments
### Comment 1
<location> `src/parser/mod.rs:201` </location>
<code_context>
+///
+/// Instances are constructed via [`ParsedSpans::new`] to guarantee the
+/// internal lists remain sorted and non-overlapping.
+#[non_exhaustive]
#[derive(Debug, Default, Clone, PartialEq)]
pub struct ParsedSpans {
</code_context>
<issue_to_address>
The module is missing a `//!` comment at the top as required by the review instructions.
Please add a `//!` module-level comment at the very top of the file to describe the module's purpose, as per the review instructions.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Actionable comments posted: 2
♻️ Duplicate comments (1)
src/parser/mod.rs (1)
1-8: Module documentation properly addresses past review feedback.The
//!module-level comment has been added as required by the coding guidelines and past review feedback. The documentation clearly explains the module's purpose and capabilities.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (1)
src/parser/mod.rs(6 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
`**/*.rs`: Comment why, not what. Explain assumptions, edge cases, trade-offs, o...
**/*.rs: Comment why, not what. Explain assumptions, edge cases, trade-offs, or complexity. Don't echo the obvious.
Comments must use en-GB-oxendict spelling and grammar.
Function documentation must include clear examples.
Name things precisely. Use clear, descriptive variable and function names. For booleans, prefer names with is, has, or should.
Each file should encapsulate a coherent module. Group related code (e.g., models + utilities + fixtures) close together.
Group by feature, not layer. Colocate views, logic, fixtures, and helpers related to a domain concept rather than splitting by type.
Every module must begin with a module level (//! ) comment explaining the module's purpose and utility.
Document public APIs using Rustdoc comments (///) so documentation can be generated with cargo doc.
Place function attributes after doc comments.
Do not use return in single-line functions.
Prefer immutable data and avoid unnecessary mut bindings.
Handle errors with the Result type instead of panicking where feasible.
Avoid unsafe code unless absolutely necessary and document any usage clearly.
Clippy warnings MUST be disallowed.
Lints must not be silenced except as a last resort.
Lint rule suppressions must be tightly scoped and include a clear reason.
Prefer expect over allow.
Use predicate functions for conditional criteria with more than two branches.
Where a function is too long, extract meaningfully named helper functions adhering to separation of concerns and CQRS.
Where a function has too many parameters, group related parameters in meaningfully named structs.
Where a function is returning a large error consider using Arc to reduce the amount of data returned.
Prefer .expect() over .unwrap().
📄 Source: CodeRabbit Inference Engine (AGENTS.md)
List of files the instruction was applied to:
src/parser/mod.rs
`**/*.rs`: * Seek to keep the cyclomatic complexity of functions no more than 12...
**/*.rs: * Seek to keep the cyclomatic complexity of functions no more than 12.
Adhere to single responsibility and CQRS
Place function attributes after doc comments.
Do not use
returnin single-line functions.Move conditionals with >2 branches into a predicate function.
Avoid
unsafeunless absolutely necessary.Every module must begin with a
//!doc comment that explains the module's purpose and utility.Comments must use en-GB-oxendict spelling and grammar.
Lints must not be silenced except as a last resort.
#[allow]is forbidden.- Only narrowly scoped
#[expect(lint, reason = "...")]is allowed.- No lint groups, no blanket or file-wide suppression.
- Include
FIXME:with link if a fix is expected.Use
rstestfixtures for shared setup and to avoid repetition between tests.Replace duplicated tests with
#[rstest(...)]parameterised cases.Prefer
mockallfor mocks/stubs.Prefer
.expect()over.unwrap()Ensure that any API or behavioural changes are reflected in the documentation in
docs/Ensure that any completed roadmap steps are recorded in the appropriate roadmap in
docs/
⚙️ Source: CodeRabbit Configuration File
List of files the instruction was applied to:
src/parser/mod.rs
🔇 Additional comments (3)
src/parser/mod.rs (3)
198-216: Well-implemented encapsulation design.The changes properly encapsulate the
ParsedSpansstructure by making fields private and adding#[non_exhaustive]. The updated documentation correctly references the new constructor, ensuring users understand the new API requirements.
254-289: Excellent accessor method design.The accessor methods follow a consistent pattern with proper documentation and
#[must_use]attributes. Returning&[Span]provides efficient read-only access whilst maintaining encapsulation.
372-379: Comprehensive and correct API migration.All usage sites have been properly updated to use the new constructor and accessor methods. The migration maintains the same semantics whilst enforcing proper encapsulation principles.
Also applies to: 929-934
Summary
Testing
make lintmake testhttps://chatgpt.com/codex/tasks/task_e_686c40c935208322a1081c4a820c2463
Summary by Sourcery
Encapsulate the internal span lists of
ParsedSpansby making its fields private and introducing a public constructor and read-only accessors, and update the parser implementation and tests to use the new API.Enhancements:
ParsedSpansspan vectors private and add aParsedSpans::newconstructorimports(),typedefs(), etc.) for each span categoryDocumentation:
ParsedSpansdocumentation to reference the new constructor and invariantsTests:
ParsedSpansvianewand to use the accessor methods in assertions