Skip to content

refactor: unify range-indexer style across netstandard2.0 surface - #88

Merged
ANcpLua merged 1 commit into
mainfrom
refactor-range-indexer-symmetry
May 4, 2026
Merged

refactor: unify range-indexer style across netstandard2.0 surface#88
ANcpLua merged 1 commit into
mainfrom
refactor-range-indexer-symmetry

Conversation

@ANcpLua

@ANcpLua ANcpLua commented May 4, 2026

Copy link
Copy Markdown
Owner

Summary

  • Link Index.cs / Range.cs polyfills into ANcpLua.Analyzers.AotReflection.csproj, mirroring the existing IsExternalInit.cs link pattern.
  • Convert twelve remaining Substring(start, length) sites to range-indexer syntax (text[..n], text[n..^1], text[start..i], etc.) across StringExtensions, SyntaxExtensions, SemconvVersion, ShortId, BearerHeader, GenerationHelpers, and MarkdownText.

Why

Both netstandard2.0 projects in the repo (ANcpLua.Roslyn.Utilities and ANcpLua.AotReflection) now resolve System.Index / System.Range from the same internal polyfill substrate. ReSharper's "Use range indexer" suggestion now fires uniformly across both projects — the prior asymmetry (MarkdownText modernized, GenerationHelpers not) was caused solely by AotReflection.csproj not linking the IndexRange polyfills, not by any analyzer being disabled. Pattern matches the polyfill-per-project convention used by Microsoft.Bcl.* and PolySharp.

Test plan

  • dotnet build -c Release — 0 warnings, 0 errors
  • CI green on PR

🤖 Generated with Claude Code

Link Index/Range polyfills into AotReflection (mirror IsExternalInit
pattern) and convert all remaining Substring(start, length) call sites
to range-indexer syntax — twelve sites across StringExtensions,
SyntaxExtensions, SemconvVersion, ShortId, BearerHeader,
GenerationHelpers, and MarkdownText.

Both netstandard2.0 projects in the repo now resolve System.Index /
System.Range, so range-indexer is uniformly available and ReSharper
suggests it consistently.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings May 4, 2026 13:24
@coderabbitai

coderabbitai Bot commented May 4, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 2efc37a3-a902-4d5c-b8a7-52f020b98334

📥 Commits

Reviewing files that changed from the base of the PR and between 103ecef and 1463105.

📒 Files selected for processing (8)
  • src/ANcpLua.AotReflection/ANcpLua.Analyzers.AotReflection.csproj
  • src/ANcpLua.AotReflection/Generation/GenerationHelpers.cs
  • src/ANcpLua.Roslyn.Utilities/Http/BearerHeader.cs
  • src/ANcpLua.Roslyn.Utilities/Ids/ShortId.cs
  • src/ANcpLua.Roslyn.Utilities/OTel/SemconvVersion.cs
  • src/ANcpLua.Roslyn.Utilities/StringExtensions.cs
  • src/ANcpLua.Roslyn.Utilities/SyntaxExtensions.cs
  • src/ANcpLua.Roslyn.Utilities/Text/MarkdownText.cs
📜 Recent review details
⏰ Context from checks skipped due to timeout of 120000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: build (windows-latest)
  • GitHub Check: build (ubuntu-latest)
  • GitHub Check: Agent
🧰 Additional context used
📓 Path-based instructions (1)
src/**/*.cs

⚙️ CodeRabbit configuration file

src/**/*.cs: C# 14 / .NET 10 codebase. Review for: idiomatic modern C#, proper async/await (no sync-over-async, no fire-and-forget without justification), correct IDisposable/IAsyncDisposable, null safety (NRTs enabled), and adherence to existing patterns. Flag new public API surface that lacks XML doc comments. Check DI lifetime correctness (scoped vs singleton vs transient).
ARCHITECTURAL INVARIANTS — flag violations as blocking: 1. Every new injectable service must register OpenTelemetry instrumentation
(ActivitySource or Meter).
2. Every new DuckDB write path must handle backpressure (bounded channel or semaphore). 3. No hardcoded connection strings, paths, or magic strings — use IOptions or
IConfiguration.
4. No new dependencies on Sentry-specific types in core/ — Sentry is a comparison
target, not an identity.
5. CancellationToken must be threaded through all async public methods. 6. No sync-over-async (.Result, .GetAwaiter().GetResult()) outside of
well-documented infrastructure code.

Files:

  • src/ANcpLua.Roslyn.Utilities/OTel/SemconvVersion.cs
  • src/ANcpLua.AotReflection/Generation/GenerationHelpers.cs
  • src/ANcpLua.Roslyn.Utilities/Ids/ShortId.cs
  • src/ANcpLua.Roslyn.Utilities/Text/MarkdownText.cs
  • src/ANcpLua.Roslyn.Utilities/SyntaxExtensions.cs
  • src/ANcpLua.Roslyn.Utilities/Http/BearerHeader.cs
  • src/ANcpLua.Roslyn.Utilities/StringExtensions.cs
🔇 Additional comments (8)
src/ANcpLua.AotReflection/ANcpLua.Analyzers.AotReflection.csproj (1)

46-47: Polyfill links are correctly integrated.

The added Index.cs and Range.cs links match the existing polyfill-link pattern and correctly address netstandard2.0 range/index availability.

src/ANcpLua.Roslyn.Utilities/Http/BearerHeader.cs (1)

31-31: Range extraction keeps semantics intact.

The slice-based token extraction is safe under the existing guards and preserves prior behavior.

src/ANcpLua.Roslyn.Utilities/OTel/SemconvVersion.cs (1)

28-28: Slice conversion is correct and bounded.

The new range slice is equivalent to the old substring path and remains guarded by the prefix check.

src/ANcpLua.AotReflection/Generation/GenerationHelpers.cs (1)

30-30: Namespace/name and prefix slicing remain correct.

Both range-based replacements preserve prior boundary behavior and output shapes.

Also applies to: 41-41

src/ANcpLua.Roslyn.Utilities/Text/MarkdownText.cs (1)

20-20: Truncation refactor is behaviorally equivalent.

The range slice keeps the same truncation and ellipsis contract under existing guards.

src/ANcpLua.Roslyn.Utilities/SyntaxExtensions.cs (1)

546-546: Generic argument slicing/parsing remains consistent.

The range-based extraction and segment slicing preserve current parser logic and bounds safety.

Also applies to: 624-624

src/ANcpLua.Roslyn.Utilities/StringExtensions.cs (1)

621-621: Range-based truncation/unwrap updates are safe.

The updated slices are fully constrained by existing guards and fixed-length hash outputs, preserving behavior.

Also applies to: 788-788, 826-826, 833-833

src/ANcpLua.Roslyn.Utilities/Ids/ShortId.cs (1)

47-47: Hex truncation refactor is correct.

Both range slices are protected by existing length validation and keep the same ID-shape contract.

Also applies to: 104-104


Summary by CodeRabbit

Release Notes

  • Refactor
    • Modernized string manipulation across the codebase to use contemporary C# range and index syntax ([..], [start..end]) instead of legacy Substring() calls, improving code clarity and consistency while preserving all existing behavior.
    • Updated project configuration to include additional compile-time polyfill sources.

Walkthrough

The PR systematically replaces Substring() calls with C# range/index syntax ([..], [start..], [..end]) across eight files. Additionally, polyfill sources for Index.cs and Range.cs are linked into the AotReflection project file to enable the range syntax. No functional behavior changes.

Changes

String Slicing Modernization

Layer / File(s) Summary
Polyfill Linkage
src/ANcpLua.AotReflection/ANcpLua.Analyzers.AotReflection.csproj
Linked Index.cs and Range.cs polyfills from Roslyn utilities into the Polyfills folder to enable range/index syntax support.
String Slicing Refactor
src/ANcpLua.AotReflection/Generation/GenerationHelpers.cs, src/ANcpLua.Roslyn.Utilities/Http/BearerHeader.cs, src/ANcpLua.Roslyn.Utilities/Ids/ShortId.cs, src/ANcpLua.Roslyn.Utilities/OTel/SemconvVersion.cs, src/ANcpLua.Roslyn.Utilities/StringExtensions.cs, src/ANcpLua.Roslyn.Utilities/SyntaxExtensions.cs, src/ANcpLua.Roslyn.Utilities/Text/MarkdownText.cs
All Substring(...) calls replaced with C# range syntax ([start..end], [..end], [start..], [..^1]), preserving identical behavior across namespace/name extraction, bearer token parsing, hex truncation, version parsing, hash generation, generic argument extraction, and text truncation.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~5 minutes

🚥 Pre-merge checks | ✅ 8
✅ Passed checks (8 passed)
Check name Status Explanation
Title check ✅ Passed Title follows conventional commits format with 'refactor' prefix, includes scope context, and is 65 characters—under the 72-character limit.
Description check ✅ Passed Description clearly outlines the polyfill linking and systematic Substring-to-range-indexer conversions across seven files, directly matching the changeset.
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.
Otel Instrumentation Required ✅ Passed PR modifies only static utility classes and extension methods with zero DI registrations; internal implementation refactoring from Substring() to range indexing poses no architectural concerns.
No Unbounded Mcp Responses ✅ Passed PR modifies zero files under src/qyl.mcp/; all eight changes are internal utility refactorings in ANcpLua.Roslyn.Utilities and ANcpLua.AotReflection converting Substring calls to range-indexer syntax.
Duckdb Backpressure On Write Paths ✅ Passed PR contains zero DuckDB references and introduces no new database write operations; changes limited to string handling refactoring and project file updates.
Cancellationtoken Threading ✅ Passed PR refactors string slicing from Substring() to C# range-indexer syntax with no new async methods added.

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


Review rate limit: 4/5 reviews remaining, refill in 12 minutes.

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

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Refactors string-slicing code to consistently use C# range/index syntax across the netstandard2.0-targeting surfaces, and ensures the AOT reflection analyzer project has the same Index/Range polyfill substrate to keep analyzer/style behavior consistent across projects.

Changes:

  • Link System.Index / System.Range polyfill sources into ANcpLua.Analyzers.AotReflection.csproj (matching the existing linked-polyfill pattern).
  • Replace remaining Substring(start, length) usages with range slicing ([..], [..^1], [start..i], etc.) across utilities and AOT reflection generation helpers.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/ANcpLua.Roslyn.Utilities/Text/MarkdownText.cs Uses range slicing for markdown cell truncation instead of Substring.
src/ANcpLua.Roslyn.Utilities/SyntaxExtensions.cs Uses range slicing for generic-argument parsing and extraction.
src/ANcpLua.Roslyn.Utilities/StringExtensions.cs Uses range slicing for nullable unwrap and hash truncation paths.
src/ANcpLua.Roslyn.Utilities/OTel/SemconvVersion.cs Uses range slicing when stripping the semconv- prefix prior to splitting.
src/ANcpLua.Roslyn.Utilities/Ids/ShortId.cs Uses range slicing when truncating generated hex strings.
src/ANcpLua.Roslyn.Utilities/Http/BearerHeader.cs Uses range slicing when stripping the Bearer scheme prefix.
src/ANcpLua.AotReflection/Generation/GenerationHelpers.cs Uses range slicing to split namespace/type name and strip global::.
src/ANcpLua.AotReflection/ANcpLua.Analyzers.AotReflection.csproj Links Index/Range polyfill sources so range/index syntax is uniformly supported in this netstandard2.0 project.

@ANcpLua
ANcpLua merged commit 182f448 into main May 4, 2026
14 checks passed
@ANcpLua
ANcpLua deleted the refactor-range-indexer-symmetry branch May 4, 2026 14:48
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