Skip to content

feat: add outline rule definition#2691

Merged
HerringtonDarkholme merged 1 commit into
mainfrom
outline-rule-definition
Jun 7, 2026
Merged

feat: add outline rule definition#2691
HerringtonDarkholme merged 1 commit into
mainfrom
outline-rule-definition

Conversation

@HerringtonDarkholme

@HerringtonDarkholme HerringtonDarkholme commented Jun 7, 2026

Copy link
Copy Markdown
Member

Summary

  • add the serialized outline extractor contract backed by ast-grep SerializableRuleCore
  • define name sources for matched node text and ast-grep meta-variable captures
  • normalize extractor roles into compact OutlineRoles flags and reject empty role sets

Notes

  • no builtin outline rules are added in this PR
  • no extraction runtime or rendering behavior is added in this PR
  • SymbolType and OutlineRole now derive Deserialize so extractor definitions can use their existing model values

Test

  • cargo test -p ast-grep outline::rule --lib
  • cargo test -p ast-grep outline::model --lib
  • cargo test -p ast-grep test_outline --lib
  • cargo clippy -p ast-grep --lib --tests
  • commit hook: fmt, cargo check, clippy

Summary by CodeRabbit

  • New Features
    • Added an outline rules framework for defining and normalizing extractor rules with role validation.
    • Configuration now accepts camelCase names for symbol types and roles.
  • Bug Fixes
    • Rejects rules with empty role sets to prevent invalid extractor configurations.
  • Tests
    • Added unit tests validating YAML parsing, normalization behavior, and failure on empty roles.

@coderabbitai

coderabbitai Bot commented Jun 7, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: cf604752-2f64-4163-a0aa-c078be2cf154

📥 Commits

Reviewing files that changed from the base of the PR and between 979c7e6 and a48b64b.

📒 Files selected for processing (3)
  • crates/cli/src/outline.rs
  • crates/cli/src/outline/model.rs
  • crates/cli/src/outline/rule.rs

📝 Walkthrough

Walkthrough

Introduces a new rule module and adds serializable outline rule types, deserialization for outline enums, runtime normalization into OutlineRule, validation rejecting empty role sets, and unit tests exercising parsing and errors.

Changes

Outline Rule Configuration and Validation

Layer / File(s) Summary
Deserialization support for outline types
crates/cli/src/outline/model.rs
SymbolType and OutlineRole now derive serde::Deserialize with #[serde(rename_all = "camelCase")] for config parsing.
Rule module declared
crates/cli/src/outline.rs
Adds an internal rule module declaration (dead-code allowed) for outline extractor rule contracts.
Serializable rule contracts
crates/cli/src/outline/rule.rs
Adds SerializableOutlineRule and SerializableOutlineRuleSet that flatten SerializableRuleCore and model id, language, symbol_type, roles, and name from YAML/JSON.
Runtime normalization
crates/cli/src/outline/rule.rs
Adds OutlineRule runtime type containing normalized OutlineRoles, preserved core, id, language, symbol_type, and name.
Validation and conversion
crates/cli/src/outline/rule.rs
Adds OutlineRuleError::EmptyRoles, implements Display/Error, and TryFrom<SerializableOutlineRule> that normalizes roles and errors on empty role sets.
Tests
crates/cli/src/outline/rule.rs
Unit tests for YAML parsing, normalization, name template preservation, and rejection of empty roles.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • ast-grep/ast-grep#2690: Related changes to SymbolType/OutlineRole definitions; this PR extends those with serde deserialization and camelCase mapping for the rule contract.

Poem

🐰 A tiny rule hops into the stack,
YAML whispers roles upon its back,
Normalize each role with care and art,
Empty lists are sent apart,
Tests nod softly — the parsing is smart.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% 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 'feat: add outline rule definition' directly and clearly summarizes the main change: introducing a new outline rule definition module with serializable rule structs and normalization logic.
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-rule-definition

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 7, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.10526% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.50%. Comparing base (7832f0d) to head (a48b64b).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
crates/cli/src/outline/rule.rs 92.10% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2691      +/-   ##
==========================================
+ Coverage   86.47%   86.50%   +0.02%     
==========================================
  Files         118      119       +1     
  Lines       20266    20342      +76     
==========================================
+ Hits        17525    17596      +71     
- Misses       2741     2746       +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.

🧹 Nitpick comments (1)
crates/cli/src/outline/rule.rs (1)

27-27: ⚡ Quick win

Consider deriving Debug for consistency.

The serializable and runtime rule structs do not derive Debug, while other types in this module (OutlineNameSource, OutlineRoleError) and the model module (SymbolType, OutlineRole, OutlineRoles, OutlineItem) all derive Debug. Adding Debug to SerializableOutlineRule, SerializableOutlineRuleSet, and OutlineRule would improve debugging ergonomics and maintain consistency with the codebase conventions.

Suggested Debug derives
-#[derive(Clone, Deserialize)]
+#[derive(Debug, Clone, Deserialize)]
 #[serde(rename_all = "camelCase")]
 pub struct SerializableOutlineRule {
-#[derive(Clone, Deserialize)]
+#[derive(Debug, Clone, Deserialize)]
 #[serde(rename_all = "camelCase")]
 pub struct SerializableOutlineRuleSet {
-#[derive(Clone)]
+#[derive(Debug, Clone)]
 pub struct OutlineRule {

Also applies to: 46-46, 54-54

🤖 Prompt for 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.

In `@crates/cli/src/outline/rule.rs` at line 27, Add the Debug derive to the three
rule-related types to match other types and improve debugging: update the derive
attributes for SerializableOutlineRule (currently #[derive(Clone, Deserialize)])
to #[derive(Clone, Deserialize, Debug)], for SerializableOutlineRuleSet to
include Debug, and for OutlineRule to include Debug as well; ensure the Debug
derive is added alongside the existing derives for each struct
(SerializableOutlineRule, SerializableOutlineRuleSet, OutlineRule).
🤖 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.

Nitpick comments:
In `@crates/cli/src/outline/rule.rs`:
- Line 27: Add the Debug derive to the three rule-related types to match other
types and improve debugging: update the derive attributes for
SerializableOutlineRule (currently #[derive(Clone, Deserialize)]) to
#[derive(Clone, Deserialize, Debug)], for SerializableOutlineRuleSet to include
Debug, and for OutlineRule to include Debug as well; ensure the Debug derive is
added alongside the existing derives for each struct (SerializableOutlineRule,
SerializableOutlineRuleSet, OutlineRule).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 7054430c-b294-4d89-9165-21e693b78eac

📥 Commits

Reviewing files that changed from the base of the PR and between 7832f0d and 1398a02.

📒 Files selected for processing (3)
  • crates/cli/src/outline.rs
  • crates/cli/src/outline/model.rs
  • crates/cli/src/outline/rule.rs

Comment thread crates/cli/src/outline/rule.rs Outdated
Comment thread crates/cli/src/outline/rule.rs Outdated
@HerringtonDarkholme
HerringtonDarkholme force-pushed the outline-rule-definition branch 2 times, most recently from 979c7e6 to 99cc41e Compare June 7, 2026 20:10
@HerringtonDarkholme
HerringtonDarkholme force-pushed the outline-rule-definition branch from 99cc41e to a48b64b Compare June 7, 2026 20:12

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

🧹 Nitpick comments (3)
crates/cli/src/outline/rule.rs (3)

19-35: ⚡ Quick win

Consider adding Debug derive for easier debugging.

The struct lacks a Debug derive, which would be helpful during development and troubleshooting. Since all field types already implement Debug (String, SgLang, SymbolType, Vec, SerializableRuleCore), adding it is straightforward.

🔍 Proposed enhancement
-#[derive(Clone, Deserialize)]
+#[derive(Clone, Debug, Deserialize)]
 #[serde(rename_all = "camelCase")]
 pub struct SerializableOutlineRule {
🤖 Prompt for 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.

In `@crates/cli/src/outline/rule.rs` around lines 19 - 35, The
SerializableOutlineRule struct is missing a Debug derive which makes printing
and debugging instances harder; add Debug to the derive list on the
SerializableOutlineRule struct (alongside Clone and Deserialize) so the type
implements std::fmt::Debug—update the attribute to #[derive(Clone, Deserialize,
Debug)] for SerializableOutlineRule.

46-60: ⚡ Quick win

Consider adding Debug derive for easier debugging.

The runtime struct lacks a Debug derive. Adding it would improve debuggability during development and when troubleshooting rule normalization issues.

🔍 Proposed enhancement
-#[derive(Clone)]
+#[derive(Clone, Debug)]
 pub struct OutlineRule {
🤖 Prompt for 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.

In `@crates/cli/src/outline/rule.rs` around lines 46 - 60, The OutlineRule struct
is missing a Debug derive which makes debugging harder; update the struct
definition for OutlineRule to add #[derive(Clone, Debug)] (or include Debug
alongside existing derives) so instances can be formatted for logs and
debugging, ensuring the derive applies to the struct that contains fields id,
language (SgLang), symbol_type (SymbolType), roles (OutlineRoles), name, and
core (SerializableRuleCore).

38-43: ⚡ Quick win

Consider adding Debug derive for easier debugging.

Similar to SerializableOutlineRule, this struct would benefit from a Debug derive for development and troubleshooting.

🔍 Proposed enhancement
-#[derive(Clone, Deserialize)]
+#[derive(Clone, Debug, Deserialize)]
 #[serde(rename_all = "camelCase")]
 pub struct SerializableOutlineRuleSet {
🤖 Prompt for 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.

In `@crates/cli/src/outline/rule.rs` around lines 38 - 43, The struct
SerializableOutlineRuleSet is missing a Debug derive which makes debugging
harder; add Debug to its derive list (i.e., change #[derive(Clone, Deserialize)]
to #[derive(Clone, Debug, Deserialize)]) so SerializableOutlineRuleSet instances
can be formatted in logs and debuggers, mirroring the existing
SerializableOutlineRule derive usage.
🤖 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.

Nitpick comments:
In `@crates/cli/src/outline/rule.rs`:
- Around line 19-35: The SerializableOutlineRule struct is missing a Debug
derive which makes printing and debugging instances harder; add Debug to the
derive list on the SerializableOutlineRule struct (alongside Clone and
Deserialize) so the type implements std::fmt::Debug—update the attribute to
#[derive(Clone, Deserialize, Debug)] for SerializableOutlineRule.
- Around line 46-60: The OutlineRule struct is missing a Debug derive which
makes debugging harder; update the struct definition for OutlineRule to add
#[derive(Clone, Debug)] (or include Debug alongside existing derives) so
instances can be formatted for logs and debugging, ensuring the derive applies
to the struct that contains fields id, language (SgLang), symbol_type
(SymbolType), roles (OutlineRoles), name, and core (SerializableRuleCore).
- Around line 38-43: The struct SerializableOutlineRuleSet is missing a Debug
derive which makes debugging harder; add Debug to its derive list (i.e., change
#[derive(Clone, Deserialize)] to #[derive(Clone, Debug, Deserialize)]) so
SerializableOutlineRuleSet instances can be formatted in logs and debuggers,
mirroring the existing SerializableOutlineRule derive usage.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 61416709-cbdd-4e31-af19-aaffd707f3b7

📥 Commits

Reviewing files that changed from the base of the PR and between 1398a02 and 979c7e6.

📒 Files selected for processing (3)
  • crates/cli/src/outline.rs
  • crates/cli/src/outline/model.rs
  • crates/cli/src/outline/rule.rs
✅ Files skipped from review due to trivial changes (1)
  • crates/cli/src/outline.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • crates/cli/src/outline/model.rs

@HerringtonDarkholme
HerringtonDarkholme added this pull request to the merge queue Jun 7, 2026
Merged via the queue into main with commit a09d1f0 Jun 7, 2026
6 checks passed
@HerringtonDarkholme
HerringtonDarkholme deleted the outline-rule-definition branch June 7, 2026 20:14
@aeroxy

aeroxy commented Jun 8, 2026

Copy link
Copy Markdown

Great, I'll reuse some of these features downstream! <3

One less moving part to maintain.

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