Skip to content

Conversation

DustinCampbell
Copy link
Member

@DustinCampbell DustinCampbell commented Oct 16, 2025

Tip

I recommend reviewing this PR commit-by-commit. Each commit represents a distinct change.

Syntax annotations were originally added to Roslyn's syntax model to support the IDE. When writing IDE code, it can be very useful to mark a node, perform a tree transformation, and then use the annotation to get back to that node. However, the Razor tooling layer doesn't perform tree transformations in that way. In fact, the only uses of syntax annotations are in the compiler itself where annotations are used to tuck compiler data onto nodes. This results in a lot of overhead for a handful of data properties that can just be part of the syntax model.

This change does exactly that. It takes compiler data stored as annotations -- SpanEditHandler, IsMarkupTransition, DirectiveDescriptor, TagHelperInfo, and TagHelperAttributeInfo -- and moves that data onto the syntax model. With that complete, syntax annotations are pure overhead and can be deleted completely.


CI Build: https://dev.azure.com/dnceng/internal/_build/results?buildId=2818010&view=results
Test Insertion: https://dev.azure.com/devdiv/DevDiv/_git/VS/pullrequest/680258
Toolset Run: https://dev.azure.com/dnceng/internal/_build/results?buildId=2818016&view=results

@DustinCampbell DustinCampbell requested review from a team and chsienki October 16, 2025 22:31
@DustinCampbell DustinCampbell requested a review from a team as a code owner October 16, 2025 22:31
Copy link
Member

@davidwengier davidwengier left a comment

Choose a reason for hiding this comment

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

I am glad these are gone

Make RazorSyntaxGenerator runnable again.
Add an "EditHandler" property to every syntax node node that has a "ChunkGenerator" property.
This change updates the compiler to update and use SpanEditHandlers from the syntax model rather than as annotations.
- Use FrozenSet<SyntaxKind> instead of ImmutableHashSet<SyntaxKind>
- Don't  create sets of one item
In addition to the mechanical work of transitioning from annotations to the syntax model, I added a handful of helpers to RazorDirectiveSyntax and used them throughout tooling layer.
Here's the thing: the Razor compiler doesn't need syntax annotations. Originally, annotations were added to Roslyn to support the IDE when making tree transformations. However, Razor tooling doesn't actually perform any tree transformations. So, tooling doesn't use annotations. The problem is that the compiler *does* use annotations to stuff data onto syntax nodes -- data that should have been part of the syntax model in the first place.

Now that all compiler data has been moved into the syntax model, syntax annotations are pure overhead and can be removed.
@DustinCampbell DustinCampbell changed the base branch from dev/dustinca/improve-greennode-tostring to main October 20, 2025 16:35
@DustinCampbell
Copy link
Member Author

@chsienki: PTAL when you get a chance.

Copy link
Member

@chsienki chsienki left a comment

Choose a reason for hiding this comment

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

❤️

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.

3 participants