Summary
Rust attributes inside #[cfg_attr(...)] and similar conditional directives that specify derive traits (e.g., #[cfg_attr(test, derive(Debug))]) are not consistently emitted as type references. The current DeriveAttributeRegex and CfgAttrDeriveAttributeRegex extract some cases but fail when the trait list spans multiple lines or when cfg conditions contain complex boolean logic with nested parentheses. This creates gaps in trait reference tracking for test-gated derives.
Where
src/CodeIndex/Indexer/References/Languages/RustReferenceExtractor.cs:10-15 (DeriveAttributeRegex, CfgAttrDeriveAttributeRegex) — single-line only
src/CodeIndex/Indexer/References/Languages/RustReferenceExtractor.cs:79-87 (EmitDeriveTypeList) — no multiline handling
Suggested approach
- Enhance CfgAttrDeriveAttributeRegex to handle nested parens in cfg conditions using balancing groups like C# patterns
- Build a multiline attribute scanner for derive lists spanning multiple physical lines
- Ensure
#[cfg_attr(all(test, feature = "serde"), derive(Debug, Serialize))] and similar nested patterns emit all trait references
- Test with:
#[cfg_attr(\n all(test, not(miri)),\n derive(\n Debug,\n Clone\n )\n)]
Summary
Rust attributes inside
#[cfg_attr(...)]and similar conditional directives that specify derive traits (e.g.,#[cfg_attr(test, derive(Debug))]) are not consistently emitted as type references. The current DeriveAttributeRegex and CfgAttrDeriveAttributeRegex extract some cases but fail when the trait list spans multiple lines or when cfg conditions contain complex boolean logic with nested parentheses. This creates gaps in trait reference tracking for test-gated derives.Where
src/CodeIndex/Indexer/References/Languages/RustReferenceExtractor.cs:10-15(DeriveAttributeRegex, CfgAttrDeriveAttributeRegex) — single-line onlysrc/CodeIndex/Indexer/References/Languages/RustReferenceExtractor.cs:79-87(EmitDeriveTypeList) — no multiline handlingSuggested approach
#[cfg_attr(all(test, feature = "serde"), derive(Debug, Serialize))]and similar nested patterns emit all trait references#[cfg_attr(\n all(test, not(miri)),\n derive(\n Debug,\n Clone\n )\n)]