Skip to content

Conversation

@davidwengier
Copy link
Member

Fixes #12421

Fall out from mapping component tags

@davidwengier davidwengier requested a review from a team as a code owner October 31, 2025 06:16
while (sourceText.GetLinePosition(hostDocumentIndex).Line == hostDocumentPosition.Line)
{
return false;
if (_documentMappingService.TryMapToCSharpPositionOrNext(csharpDocument, hostDocumentIndex, out _, out projectedIndex))
Copy link
Contributor

Choose a reason for hiding this comment

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

TryMapToCSharpPositionOrNext

not related to this PR:

Hadn't seen this method before so I took a peek, and I'm curious whether TryMapToCSharpDocumentPositionInternal is missing a break statement when

originalAbsoluteIndex > razorIndex && !nextCSharpPositionOnFailure

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll take a look

Copy link
Member Author

Choose a reason for hiding this comment

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

Ahh, turns out we've discussed this before: #9291

TL;DR, source mappings are ordered by the GeneratedSpan (as the compiler adds source mappings as it writes the generated file, not necessarily as it reads the Razor file) so an early exit there would potentially miss something.

Copy link
Contributor

Choose a reason for hiding this comment

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

OK, that makes sense. But now I'm confused how that code knows it's the "next" one if there are multiple C# ranges on the same line? The "next" code short circuits based on a mapping being on the line, not that it is the first one on that line after the span.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I suspect it doesn't, and is entirely possible to break. I would guess in "normal" Razor code the code-gen is generally in order of the original span, an it's only certain constructs that break it, so maybe we've just been lucky and nobody has hit it.

Having said that, I did get one test failure when I added to early break, I just didn't dig in. It was a document highlight test though, which is somewhat intriguing.

Copy link
Contributor

@ToddGrun ToddGrun left a comment

Choose a reason for hiding this comment

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

:shipit:

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.

Breakpoints can be set on component start tags

2 participants