Skip to content

Commit 1eaf86c

Browse files
authored
Clean up RewrittenSyntaxTree naming and null handling in DefaultTagHelperResolutionPhase (#13003)
* Clean up RewrittenSyntaxTree naming and null handling in resolution phase - Remove syntax tree access from DefaultTagHelperResolutionPhase.ExecuteCore; use codeDocument.ParserOptions directly instead of syntaxTree?.Options - Fix null handling: parserOptions was potentially null when no syntax tree was present; codeDocument.ParserOptions is always non-null - Remove unused ParserOptions field from ResolutionContext struct - Add clarifying comment explaining why options are read from the document * Rename GetPreTagHelperSyntaxTree→GetSyntaxTree and GetSyntaxTree→GetTagHelperRewrittenSyntaxTree - Rename RazorCodeDocument fields and all related methods: - _preTagHelperSyntaxTree → _syntaxTree (canonical, pre-rewrite tree) - _syntaxTree → _tagHelperRewrittenSyntaxTree (rewritten tree) - Update all phase code: - DefaultRazorParsingPhase: WithSyntaxTree → WithTagHelperRewrittenSyntaxTree - DefaultRazorSyntaxTreePhase: same rename - DefaultRazorTagHelperContextDiscoveryPhase: update fallback + early return - DefaultRazorIntermediateNodeLoweringPhase: remove fallback (uses GetSyntaxTree()) - DefaultRazorTagHelperRewritePhase: TryGetSyntaxTree + WithTagHelperRewrittenSyntaxTree - SourceGeneratorProjectEngine: WithSyntaxTree(GetRequiredTagHelperRewrittenSyntaxTree()) - Update all workspaces production code to GetTagHelperRewrittenSyntaxTree - Update all test files to use correct methods * Fix tests to use GetSyntaxTree()/WithSyntaxTree() and eliminate fallback in discovery phase - DefaultRazorParsingPhase: sets _syntaxTree (canonical) directly, not _tagHelperRewrittenSyntaxTree - DefaultRazorSyntaxTreePhase: reads/writes _syntaxTree (canonical) - DefaultRazorTagHelperContextDiscoveryPhase: reads _syntaxTree directly (no fallback needed since parsing always sets it); also removes redundant WithSyntaxTree(syntaxTree) write and simplifies early return - SourceGeneratorProjectEngine: remove redundant WithSyntaxTree() pre-discovery call (parsing now sets it) - NamespaceComputer: TryGetTagHelperRewrittenSyntaxTree → TryGetSyntaxTree - Compiler-layer tests: all non-rewrite tests switch to GetSyntaxTree()/WithSyntaxTree() - Execute_CombinesErrorsOnRewritingErrors: keeps GetTagHelperRewrittenSyntaxTree() (tests rewrite output) - IntegrationTestBase/RazorBaselineIntegrationTestBase: use GetTagHelperRewrittenSyntaxTree() ?? GetRequiredSyntaxTree() fallback for AssertSourceMappingsMatchBaseline/AssertLinePragmas - RazorCodeDocumentExtensionsTest: WithSyntaxTree (matches NamespaceComputer using TryGetSyntaxTree)
1 parent 8dcc052 commit 1eaf86c

36 files changed

Lines changed: 105 additions & 88 deletions

File tree

src/Compiler/Microsoft.AspNetCore.Razor.Language/test/DefaultRazorTagHelperBinderPhaseTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ public void Execute_CombinesErrorsOnRewritingErrors()
489489
codeDocument = projectEngine.ExecutePhase<DefaultRazorTagHelperRewritePhase>(codeDocument);
490490

491491
// Assert
492-
var outputTree = codeDocument.GetSyntaxTree();
492+
var outputTree = codeDocument.GetTagHelperRewrittenSyntaxTree();
493493
Assert.Empty(originalTree.Diagnostics);
494494
Assert.NotSame(erroredOriginalTree, outputTree);
495495
Assert.Equal<RazorDiagnostic>([initialError, expectedRewritingError], outputTree.Diagnostics);

src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/DefaultRazorIntermediateNodeLoweringPhase.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ internal class DefaultRazorIntermediateNodeLoweringPhase : RazorEnginePhaseBase,
3636
{
3737
protected override RazorCodeDocument ExecuteCore(RazorCodeDocument codeDocument, CancellationToken cancellationToken)
3838
{
39-
var syntaxTree = codeDocument.GetPreTagHelperSyntaxTree() ?? codeDocument.GetSyntaxTree();
39+
// The canonical syntax tree is established by DefaultRazorTagHelperContextDiscoveryPhase,
40+
// which always runs before this phase in the pipeline.
41+
var syntaxTree = codeDocument.GetSyntaxTree();
4042
ThrowForMissingDocumentDependency(syntaxTree);
4143

4244
var documentNode = new DocumentIntermediateNode();

src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/DefaultRazorTagHelperContextDiscoveryPhase.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ internal sealed partial class DefaultRazorTagHelperContextDiscoveryPhase : Razor
1818
{
1919
protected override RazorCodeDocument ExecuteCore(RazorCodeDocument codeDocument, CancellationToken cancellationToken)
2020
{
21-
var syntaxTree = codeDocument.GetPreTagHelperSyntaxTree() ?? codeDocument.GetSyntaxTree();
21+
// The canonical syntax tree is established by DefaultRazorParsingPhase (which runs before this phase).
22+
var syntaxTree = codeDocument.GetSyntaxTree();
2223
ThrowForMissingDocumentDependency(syntaxTree);
2324

2425
if (!codeDocument.TryGetTagHelpers(out var tagHelpers))
@@ -56,7 +57,6 @@ protected override RazorCodeDocument ExecuteCore(RazorCodeDocument codeDocument,
5657
var context = TagHelperDocumentContext.GetOrCreate(tagHelperPrefix, visitor.GetResults());
5758
return codeDocument
5859
.WithTagHelperContext(context)
59-
.WithPreTagHelperSyntaxTree(syntaxTree)
6060
.WithDirectiveTagHelperContributions(directiveContributions);
6161
}
6262

src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/DefaultRazorTagHelperRewritePhase.cs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,28 @@ internal sealed class DefaultRazorTagHelperRewritePhase : RazorEnginePhaseBase
1010
{
1111
protected override RazorCodeDocument ExecuteCore(RazorCodeDocument codeDocument, CancellationToken cancellationToken)
1212
{
13-
if (!codeDocument.TryGetPreTagHelperSyntaxTree(out var syntaxTree) ||
14-
!codeDocument.TryGetTagHelperContext(out var context) ||
15-
context.TagHelpers is [])
13+
if (!codeDocument.TryGetSyntaxTree(out var syntaxTree))
1614
{
17-
// No descriptors, so no need to see if any are used. Without setting this though,
18-
// we trigger an Assert in the ProcessRemaining method in the source generator.
1915
return codeDocument.WithReferencedTagHelpers([]);
2016
}
2117

18+
if (!codeDocument.TryGetTagHelperContext(out var context) ||
19+
context.TagHelpers is [])
20+
{
21+
// No tag helpers to rewrite. The rewritten tree is the same as the canonical tree.
22+
// Tooling in the workspaces layer always expects GetRequiredTagHelperRewrittenSyntaxTree()
23+
// to return a non-null value after the full pipeline has run.
24+
return codeDocument
25+
.WithReferencedTagHelpers([])
26+
.WithTagHelperRewrittenSyntaxTree(syntaxTree);
27+
}
28+
2229
var binder = context.GetBinder();
2330
using var usedHelpers = new TagHelperCollection.Builder();
2431
var rewrittenSyntaxTree = TagHelperParseTreeRewriter.Rewrite(syntaxTree, binder, usedHelpers, cancellationToken);
2532

2633
return codeDocument
2734
.WithReferencedTagHelpers(usedHelpers.ToCollection())
28-
.WithSyntaxTree(rewrittenSyntaxTree);
35+
.WithTagHelperRewrittenSyntaxTree(rewrittenSyntaxTree);
2936
}
3037
}

src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/DefaultTagHelperResolutionPhase.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,17 @@ protected override RazorCodeDocument ExecuteCore(RazorCodeDocument codeDocument,
4040
}
4141

4242
var tagHelperContext = codeDocument.GetTagHelperContext();
43-
var syntaxTree = codeDocument.GetPreTagHelperSyntaxTree() ?? codeDocument.GetSyntaxTree();
44-
var parserOptions = syntaxTree?.Options;
43+
44+
// This phase works with IR nodes only -- no syntax tree access needed.
45+
// RazorCodeDocument.ParserOptions is a non-nullable property initialized by Create(),
46+
// so it is always available here.
47+
var parserOptions = codeDocument.ParserOptions;
4548

4649
// Choose resolver based on file kind and language version. Component features
4750
// (MarkupElementIntermediateNode, RZ10012 diagnostics) require Version_3_0+ because
4851
// the ComponentDocumentClassifierPass is only registered at that version.
4952
_resolver = (codeDocument.FileKind.IsComponent() || codeDocument.FileKind.IsComponentImport())
50-
&& parserOptions?.LanguageVersion >= RazorLanguageVersion.Version_3_0
53+
&& parserOptions.LanguageVersion >= RazorLanguageVersion.Version_3_0
5154
? new ComponentTagHelperResolver()
5255
: new LegacyTagHelperResolver();
5356

@@ -65,7 +68,7 @@ protected override RazorCodeDocument ExecuteCore(RazorCodeDocument codeDocument,
6568

6669
using var usedHelpers = new TagHelperCollection.Builder();
6770
var sourceDocument = codeDocument.Source;
68-
var context = new ResolutionContext(sourceDocument, parserOptions, documentNode);
71+
var context = new ResolutionContext(sourceDocument, documentNode);
6972
ResolveElements(documentNode, binder, prefix, usedHelpers, in context);
7073

7174
// Add tag helper descriptor validation diagnostics (e.g. RZ3003).
@@ -90,13 +93,11 @@ protected override RazorCodeDocument ExecuteCore(RazorCodeDocument codeDocument,
9093
private readonly struct ResolutionContext
9194
{
9295
public readonly RazorSourceDocument SourceDocument;
93-
public readonly RazorParserOptions ParserOptions;
9496
public readonly DocumentIntermediateNode DocumentNode;
9597

96-
public ResolutionContext(RazorSourceDocument sourceDocument, RazorParserOptions parserOptions, DocumentIntermediateNode documentNode)
98+
public ResolutionContext(RazorSourceDocument sourceDocument, DocumentIntermediateNode documentNode)
9799
{
98100
SourceDocument = sourceDocument;
99-
ParserOptions = parserOptions;
100101
DocumentNode = documentNode;
101102
}
102103
}

src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/RazorCodeDocument.cs

Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,14 @@ public sealed partial class RazorCodeDocument
2323

2424
private readonly TagHelperCollection? _tagHelpers;
2525
private readonly TagHelperCollection? _referencedTagHelpers;
26-
private readonly RazorSyntaxTree? _preTagHelperSyntaxTree;
26+
// The canonical syntax tree produced by parsing and syntax-tree passes, before tag helper rewriting.
27+
// Established by DefaultRazorTagHelperContextDiscoveryPhase (which reads it from _tagHelperRewrittenSyntaxTree
28+
// on the first run). Once set, this field is stable throughout the rest of the pipeline.
2729
private readonly RazorSyntaxTree? _syntaxTree;
30+
// The working syntax tree: initially set by DefaultRazorParsingPhase (same value as _syntaxTree),
31+
// updated by DefaultRazorSyntaxTreePhase, and finally replaced with the tag-helper-rewritten tree
32+
// by DefaultRazorTagHelperRewritePhase.
33+
private readonly RazorSyntaxTree? _tagHelperRewrittenSyntaxTree;
2834
private readonly ImmutableArray<RazorSyntaxTree> _importSyntaxTrees;
2935
private readonly TagHelperDocumentContext? _tagHelperContext;
3036
private readonly DocumentIntermediateNode? _documentNode;
@@ -38,8 +44,8 @@ private RazorCodeDocument(
3844
RazorCodeGenerationOptions codeGenerationOptions,
3945
TagHelperCollection? tagHelpers,
4046
TagHelperCollection? referencedTagHelpers,
41-
RazorSyntaxTree? preTagHelperSyntaxTree,
4247
RazorSyntaxTree? syntaxTree,
48+
RazorSyntaxTree? tagHelperRewrittenSyntaxTree,
4349
ImmutableArray<RazorSyntaxTree> importSyntaxTrees,
4450
TagHelperDocumentContext? tagHelperContext,
4551
DocumentIntermediateNode? documentNode,
@@ -54,8 +60,8 @@ private RazorCodeDocument(
5460

5561
_tagHelpers = tagHelpers;
5662
_referencedTagHelpers = referencedTagHelpers;
57-
_preTagHelperSyntaxTree = preTagHelperSyntaxTree;
5863
_syntaxTree = syntaxTree;
64+
_tagHelperRewrittenSyntaxTree = tagHelperRewrittenSyntaxTree;
5965
_importSyntaxTrees = importSyntaxTrees;
6066
_tagHelperContext = tagHelperContext;
6167
_documentNode = documentNode;
@@ -84,8 +90,8 @@ public static RazorCodeDocument Create(
8490
codeGenerationOptions ?? RazorCodeGenerationOptions.Default,
8591
tagHelpers: null,
8692
referencedTagHelpers: null,
87-
preTagHelperSyntaxTree: null,
8893
syntaxTree: null,
94+
tagHelperRewrittenSyntaxTree: null,
8995
importSyntaxTrees: default,
9096
tagHelperContext: null,
9197
documentNode: null,
@@ -111,7 +117,7 @@ internal RazorCodeDocument WithTagHelpers(TagHelperCollection? value)
111117
{
112118
return this;
113119
}
114-
return new RazorCodeDocument(Source, Imports, ParserOptions, CodeGenerationOptions, value, _referencedTagHelpers, _preTagHelperSyntaxTree, _syntaxTree, _importSyntaxTrees, _tagHelperContext, _documentNode, _csharpDocument, _directiveTagHelperContributions);
120+
return new RazorCodeDocument(Source, Imports, ParserOptions, CodeGenerationOptions, value, _referencedTagHelpers, _syntaxTree, _tagHelperRewrittenSyntaxTree, _importSyntaxTrees, _tagHelperContext, _documentNode, _csharpDocument, _directiveTagHelperContributions);
115121
}
116122

117123
internal bool TryGetReferencedTagHelpers([NotNullWhen(true)] out TagHelperCollection? result)
@@ -132,50 +138,51 @@ internal RazorCodeDocument WithReferencedTagHelpers(TagHelperCollection value)
132138
{
133139
return this;
134140
}
135-
return new RazorCodeDocument(Source, Imports, ParserOptions, CodeGenerationOptions, _tagHelpers, value, _preTagHelperSyntaxTree, _syntaxTree, _importSyntaxTrees, _tagHelperContext, _documentNode, _csharpDocument, _directiveTagHelperContributions);
141+
return new RazorCodeDocument(Source, Imports, ParserOptions, CodeGenerationOptions, _tagHelpers, value, _syntaxTree, _tagHelperRewrittenSyntaxTree, _importSyntaxTrees, _tagHelperContext, _documentNode, _csharpDocument, _directiveTagHelperContributions);
136142
}
137143

138-
internal bool TryGetPreTagHelperSyntaxTree([NotNullWhen(true)] out RazorSyntaxTree? result)
144+
internal bool TryGetSyntaxTree([NotNullWhen(true)] out RazorSyntaxTree? result)
139145
{
140-
result = _preTagHelperSyntaxTree;
146+
result = _syntaxTree;
141147
return result is not null;
142148
}
143149

144-
internal RazorSyntaxTree? GetPreTagHelperSyntaxTree()
145-
=> _preTagHelperSyntaxTree;
150+
internal RazorSyntaxTree? GetSyntaxTree()
151+
=> _syntaxTree;
146152

147-
internal RazorSyntaxTree GetRequiredPreTagHelperSyntaxTree()
148-
=> _preTagHelperSyntaxTree.AssumeNotNull();
153+
internal RazorSyntaxTree GetRequiredSyntaxTree()
154+
=> _syntaxTree.AssumeNotNull();
149155

150-
internal RazorCodeDocument WithPreTagHelperSyntaxTree(RazorSyntaxTree? value)
156+
internal RazorCodeDocument WithSyntaxTree(RazorSyntaxTree value)
151157
{
152-
if (ReferenceEquals(value, _preTagHelperSyntaxTree))
158+
Debug.Assert(value is not null);
159+
if (ReferenceEquals(value, _syntaxTree))
153160
{
154161
return this;
155162
}
156-
return new RazorCodeDocument(Source, Imports, ParserOptions, CodeGenerationOptions, _tagHelpers, _referencedTagHelpers, value, _syntaxTree, _importSyntaxTrees, _tagHelperContext, _documentNode, _csharpDocument, _directiveTagHelperContributions);
163+
return new RazorCodeDocument(Source, Imports, ParserOptions, CodeGenerationOptions, _tagHelpers, _referencedTagHelpers, value, _tagHelperRewrittenSyntaxTree, _importSyntaxTrees, _tagHelperContext, _documentNode, _csharpDocument, _directiveTagHelperContributions);
157164
}
158165

159-
internal bool TryGetSyntaxTree([NotNullWhen(true)] out RazorSyntaxTree? result)
166+
internal bool TryGetTagHelperRewrittenSyntaxTree([NotNullWhen(true)] out RazorSyntaxTree? result)
160167
{
161-
result = _syntaxTree;
168+
result = _tagHelperRewrittenSyntaxTree;
162169
return result is not null;
163170
}
164171

165-
internal RazorSyntaxTree? GetSyntaxTree()
166-
=> _syntaxTree;
172+
internal RazorSyntaxTree? GetTagHelperRewrittenSyntaxTree()
173+
=> _tagHelperRewrittenSyntaxTree;
167174

168-
internal RazorSyntaxTree GetRequiredSyntaxTree()
169-
=> _syntaxTree.AssumeNotNull();
175+
internal RazorSyntaxTree GetRequiredTagHelperRewrittenSyntaxTree()
176+
=> _tagHelperRewrittenSyntaxTree.AssumeNotNull();
170177

171-
internal RazorCodeDocument WithSyntaxTree(RazorSyntaxTree value)
178+
internal RazorCodeDocument WithTagHelperRewrittenSyntaxTree(RazorSyntaxTree value)
172179
{
173180
Debug.Assert(value is not null);
174-
if (ReferenceEquals(value, _syntaxTree))
181+
if (ReferenceEquals(value, _tagHelperRewrittenSyntaxTree))
175182
{
176183
return this;
177184
}
178-
return new RazorCodeDocument(Source, Imports, ParserOptions, CodeGenerationOptions, _tagHelpers, _referencedTagHelpers, _preTagHelperSyntaxTree, value, _importSyntaxTrees, _tagHelperContext, _documentNode, _csharpDocument, _directiveTagHelperContributions);
185+
return new RazorCodeDocument(Source, Imports, ParserOptions, CodeGenerationOptions, _tagHelpers, _referencedTagHelpers, _syntaxTree, value, _importSyntaxTrees, _tagHelperContext, _documentNode, _csharpDocument, _directiveTagHelperContributions);
179186
}
180187

181188
internal bool TryGetImportSyntaxTrees(out ImmutableArray<RazorSyntaxTree> result)
@@ -202,7 +209,7 @@ internal RazorCodeDocument WithImportSyntaxTrees(ImmutableArray<RazorSyntaxTree>
202209
{
203210
return this;
204211
}
205-
return new RazorCodeDocument(Source, Imports, ParserOptions, CodeGenerationOptions, _tagHelpers, _referencedTagHelpers, _preTagHelperSyntaxTree, _syntaxTree, value, _tagHelperContext, _documentNode, _csharpDocument, _directiveTagHelperContributions);
212+
return new RazorCodeDocument(Source, Imports, ParserOptions, CodeGenerationOptions, _tagHelpers, _referencedTagHelpers, _syntaxTree, _tagHelperRewrittenSyntaxTree, value, _tagHelperContext, _documentNode, _csharpDocument, _directiveTagHelperContributions);
206213
}
207214

208215
internal bool TryGetTagHelperContext([NotNullWhen(true)] out TagHelperDocumentContext? result)
@@ -225,7 +232,7 @@ internal RazorCodeDocument WithTagHelperContext(TagHelperDocumentContext value)
225232
{
226233
return this;
227234
}
228-
return new RazorCodeDocument(Source, Imports, ParserOptions, CodeGenerationOptions, _tagHelpers, _referencedTagHelpers, _preTagHelperSyntaxTree, _syntaxTree, _importSyntaxTrees, value, _documentNode, _csharpDocument, _directiveTagHelperContributions);
235+
return new RazorCodeDocument(Source, Imports, ParserOptions, CodeGenerationOptions, _tagHelpers, _referencedTagHelpers, _syntaxTree, _tagHelperRewrittenSyntaxTree, _importSyntaxTrees, value, _documentNode, _csharpDocument, _directiveTagHelperContributions);
229236
}
230237

231238
internal bool TryGetDocumentNode([NotNullWhen(true)] out DocumentIntermediateNode? result)
@@ -247,7 +254,7 @@ internal RazorCodeDocument WithDocumentNode(DocumentIntermediateNode value)
247254
{
248255
return this;
249256
}
250-
return new RazorCodeDocument(Source, Imports, ParserOptions, CodeGenerationOptions, _tagHelpers, _referencedTagHelpers, _preTagHelperSyntaxTree, _syntaxTree, _importSyntaxTrees, _tagHelperContext, value, _csharpDocument, _directiveTagHelperContributions);
257+
return new RazorCodeDocument(Source, Imports, ParserOptions, CodeGenerationOptions, _tagHelpers, _referencedTagHelpers, _syntaxTree, _tagHelperRewrittenSyntaxTree, _importSyntaxTrees, _tagHelperContext, value, _csharpDocument, _directiveTagHelperContributions);
251258
}
252259

253260
internal bool TryGetCSharpDocument([NotNullWhen(true)] out RazorCSharpDocument? result)
@@ -269,7 +276,7 @@ internal RazorCodeDocument WithCSharpDocument(RazorCSharpDocument value)
269276
{
270277
return this;
271278
}
272-
return new RazorCodeDocument(Source, Imports, ParserOptions, CodeGenerationOptions, _tagHelpers, _referencedTagHelpers, _preTagHelperSyntaxTree, _syntaxTree, _importSyntaxTrees, _tagHelperContext, _documentNode, value, _directiveTagHelperContributions);
279+
return new RazorCodeDocument(Source, Imports, ParserOptions, CodeGenerationOptions, _tagHelpers, _referencedTagHelpers, _syntaxTree, _tagHelperRewrittenSyntaxTree, _importSyntaxTrees, _tagHelperContext, _documentNode, value, _directiveTagHelperContributions);
273280
}
274281

275282
internal ImmutableArray<DirectiveTagHelperContribution> GetDirectiveTagHelperContributions()
@@ -282,7 +289,7 @@ internal RazorCodeDocument WithDirectiveTagHelperContributions(ImmutableArray<Di
282289
return this;
283290
}
284291

285-
return new RazorCodeDocument(Source, Imports, ParserOptions, CodeGenerationOptions, _tagHelpers, _referencedTagHelpers, _preTagHelperSyntaxTree, _syntaxTree, _importSyntaxTrees, _tagHelperContext, _documentNode, _csharpDocument, value);
292+
return new RazorCodeDocument(Source, Imports, ParserOptions, CodeGenerationOptions, _tagHelpers, _referencedTagHelpers, _syntaxTree, _tagHelperRewrittenSyntaxTree, _importSyntaxTrees, _tagHelperContext, _documentNode, _csharpDocument, value);
286293
}
287294

288295
// In general documents will have a relative path (relative to the project root).

src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/RazorHtmlWriter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public static RazorHtmlDocument GetHtmlDocument(RazorCodeDocument codeDocument)
4444
using var codeWriter = new CodeWriter(options);
4545

4646
var htmlWriter = new RazorHtmlWriter(source, codeWriter);
47-
var syntaxTree = codeDocument.GetRequiredSyntaxTree();
47+
var syntaxTree = codeDocument.GetRequiredTagHelperRewrittenSyntaxTree();
4848

4949
htmlWriter.Visit(syntaxTree);
5050

src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/SourceGenerators/SourceGeneratorProjectEngine.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ public SourceGeneratorRazorCodeDocument ProcessInitialParse(RazorProjectItem pro
5858

5959
codeDocument = ExecutePhases(Phases[.._discoveryPhaseIndex], codeDocument, cancellationToken);
6060

61-
// record the syntax tree, before the tag helper re-writing occurs
62-
codeDocument = codeDocument.WithPreTagHelperSyntaxTree(codeDocument.GetSyntaxTree());
61+
// By this point, DefaultRazorParsingPhase has set the canonical syntax tree (_syntaxTree)
62+
// so that discovery and subsequent phases can read it via GetSyntaxTree().
6363
return new SourceGeneratorRazorCodeDocument(codeDocument);
6464
}
6565

@@ -69,7 +69,7 @@ public SourceGeneratorRazorCodeDocument ProcessTagHelpers(
6969
bool checkForIdempotency,
7070
CancellationToken cancellationToken)
7171
{
72-
Debug.Assert(sgDocument.CodeDocument.GetPreTagHelperSyntaxTree() is not null);
72+
Debug.Assert(sgDocument.CodeDocument.GetSyntaxTree() is not null);
7373

7474
int startIndex = _discoveryPhaseIndex;
7575
var codeDocument = sgDocument.CodeDocument;

src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Razor/ExtractToComponentCodeActionProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public Task<ImmutableArray<RazorVSInternalCodeAction>> ProvideAsync(RazorCodeAct
3939
return SpecializedTasks.EmptyImmutableArray<RazorVSInternalCodeAction>();
4040
}
4141

42-
if (!context.CodeDocument.TryGetSyntaxTree(out var syntaxTree))
42+
if (!context.CodeDocument.TryGetTagHelperRewrittenSyntaxTree(out var syntaxTree))
4343
{
4444
return SpecializedTasks.EmptyImmutableArray<RazorVSInternalCodeAction>();
4545
}

src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Razor/ExtractToComponentCodeActionResolver.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ internal class ExtractToComponentCodeActionResolver(
5757
builder.AppendLine();
5858
}
5959

60-
var syntaxTree = componentDocument.GetRequiredSyntaxTree();
60+
var syntaxTree = componentDocument.GetRequiredTagHelperRewrittenSyntaxTree();
6161

6262
// Right now this includes all the usings in the original document.
6363
// https://github.com/dotnet/razor/issues/11025 tracks reducing to only the required set.

0 commit comments

Comments
 (0)