Skip to content

📝 CodeRabbit Chat: Implement requested code changes#258

Open
coderabbitai[bot] wants to merge 5 commits into
mainfrom
coderabbitai/chat/590b15d
Open

📝 CodeRabbit Chat: Implement requested code changes#258
coderabbitai[bot] wants to merge 5 commits into
mainfrom
coderabbitai/chat/590b15d

Conversation

@coderabbitai
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot commented Apr 9, 2026

Code changes was requested by @leynos.

The following files were modified:

  • src/parser/ast/mod.rs

Summary by Sourcery

Enhancements:

  • Simplify identifier span lookup in the AST by replacing manual looping and control flow with iterator-based combinators for clearer, more concise logic.

leynos and others added 5 commits April 8, 2026 15:18
This introduces an optional `name_span` field on symbols, capturing the exact identifier token span when available. The semantic model builder and AST nodes now extract and store precise name spans for top-level declarations (relations, functions, types) and for rule-local bindings (head bindings, assignments, for-loop patterns).

The unused-variable lint and diagnostics have been updated to use these precise spans where possible for improved diagnostic highlighting.

Also includes new semantic-model tests verifying that the precise identifier spans are captured and differ from the coarser span previously used.

Co-authored-by: devboxerhub[bot] <devboxerhub[bot]@users.noreply.github.com>
… function

Refactor collect_program_declarations by removing inlined closure and
pattern matching, replacing it with a new helper method
program_declaration_spec. This improves code readability and modularity
without changing behavior.

Co-authored-by: devboxerhub[bot] <devboxerhub[bot]@users.noreply.github.com>
…tic model

This change augments the RuleHead AST with span information for the head atom and its bindings. It introduces functionality in the parser to collect and store identifier-token spans for bindings introduced by the head atom. The semantic model builder now uses these spans to accurately track declaration name spans for rule head bindings.

Enhancements include:
- New functions to find identifier spans within given spans for precise range matching.
- Collection of binding spans in parsed rule heads excluding non-bindings like those following dots or certain punctuations.
- Usage of binding spans in semantic symbol declarations for improved source mapping.
- Additional tests to verify correct capturing and handling of name spans for rule head bindings.

This feature improves diagnostic accuracy and tooling support by providing detailed source location information for rule head bindings.

Co-authored-by: devboxerhub[bot] <devboxerhub[bot]@users.noreply.github.com>
Nested bodies recurse through `collect_rule_term`, but the `VariableUseContext::new(...)` path no longer retains CST handles for those inner terms. Passing `None` deliberately prevents nested bindings from claiming precise `name_span`s we cannot source faithfully.

Co-authored-by: devboxerhub[bot] <devboxerhub[bot]@users.noreply.github.com>
@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai Bot commented Apr 9, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Refactors the AST identifier span search helper to use iterator combinators (find_map, then_some, and then) instead of an explicit loop and manual control flow, preserving behavior while simplifying the code in the AST parser module.

File-Level Changes

Change Details Files
Refactor identifier span search to use iterator combinators while preserving semantics.
  • Replace the explicit for loop over children_with_tokens with find_map on the iterator to return the first matching span directly.
  • For identifier tokens, compute the token span and use span_contains(...).then_some(token_span) instead of an if plus early return.
  • For child nodes, gate recursion with `ranges_overlap(...).then(

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@coderabbitai
Copy link
Copy Markdown
Contributor Author

coderabbitai Bot commented Apr 9, 2026

Important

Review skipped

This PR was authored by the user configured for CodeRabbit reviews. CodeRabbit does not review PRs authored by this user. It's recommended to use a dedicated user account to post CodeRabbit review feedback.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 31014122-001f-443b-8677-67be6b505fa2

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

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

Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 1 issue, and left some high level feedback:

  • In the NodeOrToken::Node arm, consider replacing ranges_overlap(...).then(|| find_identifier_span_in_range(...)).flatten() with if ranges_overlap(...) { find_identifier_span_in_range(...) } else { None } (or and_then) to avoid the intermediate Option<Option<_>> and improve readability.
  • The NodeOrToken::Token(_) => None arm could be simplified by using a wildcard match arm (e.g., _ => None) if there are no other variants to handle, making the match slightly more concise.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In the `NodeOrToken::Node` arm, consider replacing `ranges_overlap(...).then(|| find_identifier_span_in_range(...)).flatten()` with `if ranges_overlap(...) { find_identifier_span_in_range(...) } else { None }` (or `and_then`) to avoid the intermediate `Option<Option<_>>` and improve readability.
- The `NodeOrToken::Token(_) => None` arm could be simplified by using a wildcard match arm (e.g., `_ => None`) if there are no other variants to handle, making the match slightly more concise.

## Individual Comments

### Comment 1
<location path="src/parser/ast/mod.rs" line_range="37" />
<code_context>
-                }
-            }
-            NodeOrToken::Token(_) => {}
+    syntax.children_with_tokens().find_map(|child| match child {
+        NodeOrToken::Token(token)
+            if token.kind() == SyntaxKind::T_IDENT && token.text() == name =>
</code_context>
<issue_to_address>
**suggestion (review_instructions):** This new `match` expression has three branches and should be extracted into a separate predicate/helper function to comply with the conditional branching guideline.

The closure passed to `find_map` contains a `match` with three arms. Per the instruction to move conditionals with more than two branches into a predicate function, consider extracting this logic into a small helper (e.g. `fn identifier_span_for_child(...) -> Option<Span>`), and then call that from `find_map` instead of inlining the full `match` here. That keeps the branching logic isolated and the main function simpler.

<details>
<summary>Review instructions:</summary>

**Path patterns:** `**/*.rs`

**Instructions:**
Move conditionals with >2 branches into a predicate function.

</details>
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread src/parser/ast/mod.rs
}
}
NodeOrToken::Token(_) => {}
syntax.children_with_tokens().find_map(|child| match child {
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.

suggestion (review_instructions): This new match expression has three branches and should be extracted into a separate predicate/helper function to comply with the conditional branching guideline.

The closure passed to find_map contains a match with three arms. Per the instruction to move conditionals with more than two branches into a predicate function, consider extracting this logic into a small helper (e.g. fn identifier_span_for_child(...) -> Option<Span>), and then call that from find_map instead of inlining the full match here. That keeps the branching logic isolated and the main function simpler.

Review instructions:

Path patterns: **/*.rs

Instructions:
Move conditionals with >2 branches into a predicate function.

@devboxerhub devboxerhub Bot force-pushed the add-symbol-name-span-5p0bo1 branch from 590b15d to 03a0ad5 Compare April 9, 2026 14:30
Base automatically changed from add-symbol-name-span-5p0bo1 to main April 11, 2026 14:50
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.

1 participant