Skip to content

feat: Razor-generated code references resolve to .razor/.cshtml source lines - #353

Merged
flupkede merged 1 commit into
developfrom
fix/razor-mapped-linespans
Oct 18, 2026
Merged

flupkede merged 1 commit into
developfrom
fix/razor-mapped-linespans

Conversation

@flupkede

Copy link
Copy Markdown
Owner

The C# helper recorded symbol positions with the raw GetLineSpan(): references inside Razor source-generated trees pointed at generated virtual paths — and since the Razor SDK moved to in-memory Roslyn source generators (no more obj/razor/*.g.cs on disk), those references vanished from rebuilt indexes entirely (find_impact on a ViewModel lost its view-code references; CreateAgencyModel lost its Create.cshtml references).

The helper now uses GetMappedLineSpan() for both the document path and the ranges — the same mechanism VS's ctrl-click uses:

  • #line directives resolve every generated-tree position back to the .razor/.cshtml source file and line.
  • Hidden regions keep the last #line mapping (Roslyn semantics, pinned by test — probed empirically: HasMappedPath=true, path = the last mapped file).
  • Trees with no directives at all map to an empty path and are dropped.
  • Ordinary files: identity mapping, byte-identical behavior.

The SCIP symbol indexes get their own builder stamp (SCIP_INDEX_BUILDER_VERSION = 2026-10.2) so a deployed binary rebuilds them without a text re-embed wave — file_meta keeps comparing the unchanged INDEX_BUILDER_VERSION. Stamp fixtures updated.

Tests: new MappedSpanTests (4 cases: #line resolution, mapped range, hidden-region semantics, ordinary-file identity); helper suite 112/112; Rust fmt/clippy/cargo test --lib --bins + full cargo test --test '*' green. Deploy note: after deploying, the SCIP indexes rebuild automatically on first use (stamp mismatch); the text indexes are untouched.

…e lines

The helper recorded symbol positions with the raw GetLineSpan(): references
inside Razor source-generated trees pointed at generated virtual paths —
and since the Razor SDK moved to in-memory source generators (no more
obj/razor/*.g.cs on disk), those references vanished from rebuilt indexes
entirely (find_impact on a ViewModel lost its view-code references).

The helper now uses GetMappedLineSpan() for both the document path and the
ranges: #line directives resolve every generated-tree position back to the
.razor/.cshtml source file and line — the same mechanism VS's ctrl-click
uses. Hidden regions keep the last #line mapping (Roslyn semantics, pinned
by test); trees with no directives at all map to an empty path and are
dropped. Identity mapping for ordinary files is unchanged.

The SCIP symbol indexes get their own builder stamp
(SCIP_INDEX_BUILDER_VERSION = 2026-10.2) so a deployed binary rebuilds
them without a text re-embed wave: file_meta keeps comparing the
unchanged INDEX_BUILDER_VERSION. Stamp fixtures updated accordingly.

C# test: MappedSpanTests pins the #line resolution, the mapped range, the
hidden-region semantics and the ordinary-file identity mapping.
@flupkede
flupkede merged commit 74d2c58 into develop Oct 18, 2026
6 checks passed
@flupkede
flupkede deleted the fix/razor-mapped-linespans branch October 18, 2026 18:50
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