Skip to content

Outline extractor execution#2729

Merged
HerringtonDarkholme merged 1 commit into
mainfrom
outline-extractor-execution
Jun 19, 2026
Merged

Outline extractor execution#2729
HerringtonDarkholme merged 1 commit into
mainfrom
outline-extractor-execution

Conversation

@HerringtonDarkholme

@HerringtonDarkholme HerringtonDarkholme commented Jun 18, 2026

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • Bug Fixes

    • Fixed code outline extraction to properly skip nested items after a match, preventing duplicate nested structures from appearing in outlines.
    • Improved member extraction to respect scope boundaries, ensuring members are only captured from within their intended parent context.
  • Improvements

    • Enhanced outline extraction with two-phase traversal for more accurate code structure detection and scoped member identification.

@coderabbitai

coderabbitai Bot commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d888e622-6303-4046-a327-62ef085ca977

📥 Commits

Reviewing files that changed from the base of the PR and between 0011822 and 3c16ebc.

📒 Files selected for processing (2)
  • crates/outline/src/combined_extractor.rs
  • crates/outline/src/extractor.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • crates/outline/src/extractor.rs

📝 Walkthrough

Walkthrough

Two files in the crates/outline crate are updated. extractor.rs adds OutlinePredicate::evaluate, match_node/extract methods to ItemExtractor and MemberExtractor, and ExtractorCommon entry-building helpers. combined_extractor.rs implements CombinedExtractors::extract (explicit-stack pre-order traversal that stops descending after an item match) and CombinedMemberExtractors::extract (scoped traversal within a matched item node).

Changes

Outline Extraction Implementation

Layer / File(s) Summary
Extractor match/extract methods and predicate evaluation
crates/outline/src/extractor.rs
Updates imports; adds OutlinePredicate::evaluate resolving literal and rule-based predicates; adds match_node/extract to ItemExtractor (builds OutlineItem, evaluates is_import/is_exported) and MemberExtractor (builds OutlineMember, evaluates is_public); extends ExtractorCommon with extract_entry, render_template, default_signature, and source_range; adds test for predicate metavariable reuse.
Two-phase item+member traversal in CombinedExtractors
crates/outline/src/combined_extractor.rs
Updates module docs and imports; implements CombinedExtractors::extract with an explicit stack that skips descendants after an item match and delegates to scoped member extraction; implements CombinedMemberExtractors::extract for child-only traversal; adds tests verifying non-descent into nested items and member scoping.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐇 Hop through the tree, one node at a time,
When an item is found, I stop on a dime.
Members stay cozy inside their parent's scope,
No stray nested nodes allowed to elope.
The stack unwinds clean — what a marvelous climb! 🌿

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 26.02% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Outline extractor execution' directly aligns with the main objective of the changeset, which implements the execution logic for outline extraction by adding extract methods to both CombinedExtractors and CombinedMemberExtractors, alongside supporting infrastructure in the extractor runtime module.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch outline-extractor-execution

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 and usage tips.

@codecov

codecov Bot commented Jun 18, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 99.54955% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 86.90%. Comparing base (dc525b0) to head (3c16ebc).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
crates/outline/src/extractor.rs 99.09% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2729      +/-   ##
==========================================
+ Coverage   86.74%   86.90%   +0.16%     
==========================================
  Files         121      121              
  Lines       20761    20985     +224     
==========================================
+ Hits        18009    18238     +229     
+ Misses       2752     2747       -5     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 2

🤖 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 `@crates/cli/src/outline.rs`:
- Line 271: The mpsc::channel() call creating the tx and rx pair is unbounded,
allowing workers to enqueue OutlineFile values faster than they can be consumed,
causing potential memory bloat on large trees. Replace the unbounded
mpsc::channel() with mpsc::channel(capacity) using an appropriate bounded
capacity value (e.g., 1000 or similar) to provide backpressure and prevent
unbounded queue growth. This ensures that when the queue reaches capacity,
senders will block until the receiver consumes items.

In `@crates/outline/src/default_rules/typescript.yml`:
- Around line 355-366: The ts-class-constructor rule hardcodes isPublic: true,
which incorrectly marks private and protected constructors as public. Replace
the hardcoded isPublic property with a modifier-based visibility check that
mirrors the pattern used for methods elsewhere in the file, specifically the
approach that examines the modifier context to determine if a constructor is
private, protected, or public. Also add test cases covering private and
protected constructor scenarios to ensure the modifier-based detection works
correctly.
🪄 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: CHILL

Plan: Pro

Run ID: 4f0c3b77-e62e-479d-a9f9-93844e99ba32

📥 Commits

Reviewing files that changed from the base of the PR and between 0a56719 and e59f900.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (17)
  • crates/cli/Cargo.toml
  • crates/cli/src/lib.rs
  • crates/cli/src/outline.rs
  • crates/outline/src/combined_extractor.rs
  • crates/outline/src/default_rule.rs
  • crates/outline/src/default_rules/go.yml
  • crates/outline/src/default_rules/java.yml
  • crates/outline/src/default_rules/kotlin.yml
  • crates/outline/src/default_rules/python.yml
  • crates/outline/src/default_rules/swift.yml
  • crates/outline/src/default_rules/typescript.yml
  • crates/outline/src/extractor.rs
  • crates/outline/src/lib.rs
  • crates/outline/tests/common/mod.rs
  • crates/outline/tests/jvm_swift_outline_rules.rs
  • crates/outline/tests/python_go_outline_rules.rs
  • crates/outline/tests/typescript_outline_rules.rs

Comment thread crates/cli/src/outline.rs Outdated
Comment thread crates/outline/src/default_rules/typescript.yml Outdated
//!
//! This module only builds those indexes. It does not traverse the AST or
//! perform scoped member extraction.
//! Extraction uses explicit pre-order traversals instead of `find_all`. For each

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.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

gh issue create \
  --repo "ast-grep/ast-grep" \
  --title "TODO: Explore whether level-order (BFS) traversal is faster than pre-order in CombinedExtractors::extract" \
  --body "## Background

In \`crates/outline/src/combined_extractor.rs\`, \`CombinedExtractors::extract\` currently uses an explicit pre-order (DFS) traversal via a stack to match top-level outline items and skip their descendants once matched.

## Task

Explore whether switching to a **level-order (BFS) traversal** would be faster in practice. Potential advantages of BFS:
- Outline items (functions, classes, etc.) tend to cluster near the top levels of the AST, so BFS might find matches earlier and avoid allocating deep stack frames.
- The \"skip descendants once matched\" semantics may integrate naturally with a queue-based approach.

Potential drawbacks:
- BFS requires a queue/deque, which may have higher allocation overhead for deeply nested or wide ASTs.
- Pre-order with early skip may already be near-optimal for typical AST shapes.

## Suggested investigation

- Benchmark both approaches on representative source files (Rust, TypeScript, Go) with the existing outline rules.
- Measure allocation count and throughput.

## References

- PR: https://github.com/ast-grep/ast-grep/pull/2729
- Comment: https://github.com/ast-grep/ast-grep/pull/2729#discussion_r3443167022

Requested by `@HerringtonDarkholme`." \
  --assignee "HerringtonDarkholme"

Length of output: 1554



@HerringtonDarkholme, I've logged the TODO as GitHub issue #2736: Explore whether level-order (BFS) traversal is faster than pre-order in CombinedExtractors::extract, assigned to you. It captures the current DFS stack-based approach, potential BFS trade-offs, and suggested benchmarking directions.


🧠 Learnings used
Learnt from: HerringtonDarkholme
Repo: ast-grep/ast-grep PR: 2484
File: crates/wasm/src/ts_types.rs:33-47
Timestamp: 2026-02-22T15:51:19.118Z
Learning: In Rust WASM targets (single-threaded async environment), thread_local! creates a per-thread singleton with no cross-thread shared mutable state, so data races in Rust terms do not occur. Since await points can interleave tasks, ensure library initialization is idempotent to remain safe across yields. When reviewing code, verify thread_local usage and idempotent initialization where applicable, and avoid relying on mutable global state across await boundaries.


fn match_item<'tree, D: Doc>(
&self,
node: Node<'tree, D>,

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

too much clone, can you use reference here?

Comment thread crates/outline/src/combined_extractor.rs Outdated
Comment thread crates/outline/src/extractor.rs Outdated
Comment thread crates/outline/src/combined_extractor.rs Outdated
@HerringtonDarkholme
HerringtonDarkholme force-pushed the outline-extractor-execution branch from f0a3408 to 3c16ebc Compare June 19, 2026 15:09
}
}

fn push_children<'tree, D: Doc>(stack: &mut Vec<Node<'tree, D>>, node: Node<'tree, D>) {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

this is definitely performance killer lol

Comment thread crates/outline/src/extractor.rs
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