-
Notifications
You must be signed in to change notification settings - Fork 214
Remove syntax annotations from the Razor compiler #12345
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
DustinCampbell
wants to merge
8
commits into
dotnet:main
Choose a base branch
from
DustinCampbell:remove-annotations
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,303
−1,779
Conversation
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
davidwengier
approved these changes
Oct 16, 2025
There was a problem hiding this 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.
…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
@chsienki: PTAL when you get a chance. |
chsienki
approved these changes
Oct 20, 2025
There was a problem hiding this 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
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