Remove syntax annotations from the Razor compiler#12345
Merged
DustinCampbell merged 8 commits intodotnet:mainfrom Oct 22, 2025
Merged
Remove syntax annotations from the Razor compiler#12345DustinCampbell merged 8 commits intodotnet:mainfrom
DustinCampbell merged 8 commits intodotnet:mainfrom
Conversation
davidwengier
approved these changes
Oct 16, 2025
Member
davidwengier
left a comment
There was a problem hiding this comment.
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.
…ve from annotations
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.
a2cbaac to
054202c
Compare
Member
Author
|
@chsienki: PTAL when you get a chance. |
This was referenced Oct 22, 2025
This was referenced Oct 24, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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, andTagHelperAttributeInfo-- 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