feat(TextSegment): add WriteTo appendLine override, inline storage, and Count#267
feat(TextSegment): add WriteTo appendLine override, inline storage, and Count#267
Conversation
Add WriteTo(SourceTextWriter, bool) overload that lets callers suppress or force a line terminator regardless of the segment's stored AppendLine flag, with XML doc comment and theory tests covering all four override combinations. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…o-alloc fast path Replaces single-array storage with 8 inline string fields (_part0–_part7) plus an overflow _additionalParts array, eliminating heap allocation for segments with ≤ 8 parts (the common case in source generators). Adds indexer and enumerator to support collection access, with tests covering inline/overflow boundary, null values, out-of-range guards, and Grow behaviour. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
📝 WalkthroughWalkthroughThis pull request refactors Changes
Estimated code review effort🎯 4 (Complex) | ⏱️ ~50 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 1 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #267 +/- ##
==========================================
+ Coverage 88.88% 89.29% +0.40%
==========================================
Files 19 20 +1
Lines 1332 1401 +69
Branches 101 109 +8
==========================================
+ Hits 1184 1251 +67
- Misses 104 107 +3
+ Partials 44 43 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
🧹 Nitpick comments (2)
src/InterpolationCodeWriter/TextSegment.Interpolation.cs (1)
519-528: Consider usingHasValuefor nullable struct check.For nullable value types, using
!value.HasValueis more idiomatic thanvalue is null. The pattern matching approach works but involves unnecessary boxing.♻️ Suggested change
public void AppendFormatted(in TextSegment? value) { - if (value is null) + if (!value.HasValue) { return; } var underlyingValue = value.Value; AppendFormatted(in underlyingValue); }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/InterpolationCodeWriter/TextSegment.Interpolation.cs` around lines 519 - 528, Replace the null-pattern check with the nullable struct HasValue check in AppendFormatted to avoid boxing: in the AppendFormatted(in TextSegment? value) method use if (!value.HasValue) return; then get var underlyingValue = value.Value and call AppendFormatted(in underlyingValue); this updates the nullability check for the nullable TextSegment to the idiomatic HasValue usage.src/InterpolationCodeWriter/Internals/Throws.cs (1)
42-50: XML documentation references wrong exception type.The
<exception>tag at lines 48-50 statesArgumentOutOfRangeExceptionis thrown, which is correct. However, the method nameIndexOutOfRangeIfInvalidand the summary imply it throwsIndexOutOfRangeException. The actual implementation throwsArgumentOutOfRangeException, which is the correct choice for parameter validation. Consider renaming the method toOutOfRangeIfInvalidIndexfor consistency with other helpers in this class (e.g.,OutOfRangeIfNegative,OutOfRangeIfGreaterThan).🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/InterpolationCodeWriter/Internals/Throws.cs` around lines 42 - 50, The XML docs and method name are inconsistent with the exception thrown: the method IndexOutOfRangeIfInvalid actually throws ArgumentOutOfRangeException; rename the method to OutOfRangeIfInvalidIndex (to match existing helpers like OutOfRangeIfNegative and OutOfRangeIfGreaterThan), and update its XML <summary> and any references to use the new name while keeping the <exception> tag as ArgumentOutOfRangeException so the docs reflect the actual behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@src/InterpolationCodeWriter/Internals/Throws.cs`:
- Around line 42-50: The XML docs and method name are inconsistent with the
exception thrown: the method IndexOutOfRangeIfInvalid actually throws
ArgumentOutOfRangeException; rename the method to OutOfRangeIfInvalidIndex (to
match existing helpers like OutOfRangeIfNegative and OutOfRangeIfGreaterThan),
and update its XML <summary> and any references to use the new name while
keeping the <exception> tag as ArgumentOutOfRangeException so the docs reflect
the actual behavior.
In `@src/InterpolationCodeWriter/TextSegment.Interpolation.cs`:
- Around line 519-528: Replace the null-pattern check with the nullable struct
HasValue check in AppendFormatted to avoid boxing: in the AppendFormatted(in
TextSegment? value) method use if (!value.HasValue) return; then get var
underlyingValue = value.Value and call AppendFormatted(in underlyingValue); this
updates the nullability check for the nullable TextSegment to the idiomatic
HasValue usage.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 84d51e17-9367-45e6-904c-ccc95998ec60
📒 Files selected for processing (7)
src/InterpolationCodeWriter/Internals/Throws.cssrc/InterpolationCodeWriter/TextSegment.Collection.cssrc/InterpolationCodeWriter/TextSegment.Interpolation.cssrc/InterpolationCodeWriter/TextSegment.cstests/InterpolationCodeWriter.Tests/TextSegmentTest.Collection.cstests/InterpolationCodeWriter.Tests/TextSegmentTest.csversion.json
Summary
WriteTo(SourceTextWriter, bool appendLine)overload to override the segment's storedAppendLineflag at write timestring?fields (_part0–_part7) plus an overflow array, eliminating heap allocation for segments with ≤ 8 partsTextSegment.Collectionpartial exposingCount, a public indexer, andGetEnumeratorover the inline storageThrows.IndexOutOfRangeIfInvalidhelper for bounds checking in the new indexerTextSegmentTest.Collectiontests coveringCount, the indexer, and enumeration behaviorsTest plan
dotnet test— all existing and new tests pass_additionalPartsallocation🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Chores