diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/DefaultRazorTagHelperBinderPhaseTest.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/DefaultRazorTagHelperBinderPhaseTest.cs index 47bc89b1b58..966e9a36eeb 100644 --- a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/DefaultRazorTagHelperBinderPhaseTest.cs +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/DefaultRazorTagHelperBinderPhaseTest.cs @@ -489,7 +489,7 @@ public void Execute_CombinesErrorsOnRewritingErrors() codeDocument = projectEngine.ExecutePhase(codeDocument); // Assert - var outputTree = codeDocument.GetSyntaxTree(); + var outputTree = codeDocument.GetTagHelperRewrittenSyntaxTree(); Assert.Empty(originalTree.Diagnostics); Assert.NotSame(erroredOriginalTree, outputTree); Assert.Equal([initialError, expectedRewritingError], outputTree.Diagnostics); diff --git a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/DefaultRazorIntermediateNodeLoweringPhase.cs b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/DefaultRazorIntermediateNodeLoweringPhase.cs index e15d5d7f52d..a809b00f8e9 100644 --- a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/DefaultRazorIntermediateNodeLoweringPhase.cs +++ b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/DefaultRazorIntermediateNodeLoweringPhase.cs @@ -36,7 +36,9 @@ internal class DefaultRazorIntermediateNodeLoweringPhase : RazorEnginePhaseBase, { protected override RazorCodeDocument ExecuteCore(RazorCodeDocument codeDocument, CancellationToken cancellationToken) { - var syntaxTree = codeDocument.GetPreTagHelperSyntaxTree() ?? codeDocument.GetSyntaxTree(); + // The canonical syntax tree is established by DefaultRazorTagHelperContextDiscoveryPhase, + // which always runs before this phase in the pipeline. + var syntaxTree = codeDocument.GetSyntaxTree(); ThrowForMissingDocumentDependency(syntaxTree); var documentNode = new DocumentIntermediateNode(); diff --git a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/DefaultRazorTagHelperContextDiscoveryPhase.cs b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/DefaultRazorTagHelperContextDiscoveryPhase.cs index 5cbb0e65e8b..8f1752cf8e0 100644 --- a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/DefaultRazorTagHelperContextDiscoveryPhase.cs +++ b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/DefaultRazorTagHelperContextDiscoveryPhase.cs @@ -18,7 +18,8 @@ internal sealed partial class DefaultRazorTagHelperContextDiscoveryPhase : Razor { protected override RazorCodeDocument ExecuteCore(RazorCodeDocument codeDocument, CancellationToken cancellationToken) { - var syntaxTree = codeDocument.GetPreTagHelperSyntaxTree() ?? codeDocument.GetSyntaxTree(); + // The canonical syntax tree is established by DefaultRazorParsingPhase (which runs before this phase). + var syntaxTree = codeDocument.GetSyntaxTree(); ThrowForMissingDocumentDependency(syntaxTree); if (!codeDocument.TryGetTagHelpers(out var tagHelpers)) @@ -56,7 +57,6 @@ protected override RazorCodeDocument ExecuteCore(RazorCodeDocument codeDocument, var context = TagHelperDocumentContext.GetOrCreate(tagHelperPrefix, visitor.GetResults()); return codeDocument .WithTagHelperContext(context) - .WithPreTagHelperSyntaxTree(syntaxTree) .WithDirectiveTagHelperContributions(directiveContributions); } diff --git a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/DefaultRazorTagHelperRewritePhase.cs b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/DefaultRazorTagHelperRewritePhase.cs index f4edc5f57c4..ea2859d3ac1 100644 --- a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/DefaultRazorTagHelperRewritePhase.cs +++ b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/DefaultRazorTagHelperRewritePhase.cs @@ -10,21 +10,28 @@ internal sealed class DefaultRazorTagHelperRewritePhase : RazorEnginePhaseBase { protected override RazorCodeDocument ExecuteCore(RazorCodeDocument codeDocument, CancellationToken cancellationToken) { - if (!codeDocument.TryGetPreTagHelperSyntaxTree(out var syntaxTree) || - !codeDocument.TryGetTagHelperContext(out var context) || - context.TagHelpers is []) + if (!codeDocument.TryGetSyntaxTree(out var syntaxTree)) { - // No descriptors, so no need to see if any are used. Without setting this though, - // we trigger an Assert in the ProcessRemaining method in the source generator. return codeDocument.WithReferencedTagHelpers([]); } + if (!codeDocument.TryGetTagHelperContext(out var context) || + context.TagHelpers is []) + { + // No tag helpers to rewrite. The rewritten tree is the same as the canonical tree. + // Tooling in the workspaces layer always expects GetRequiredTagHelperRewrittenSyntaxTree() + // to return a non-null value after the full pipeline has run. + return codeDocument + .WithReferencedTagHelpers([]) + .WithTagHelperRewrittenSyntaxTree(syntaxTree); + } + var binder = context.GetBinder(); using var usedHelpers = new TagHelperCollection.Builder(); var rewrittenSyntaxTree = TagHelperParseTreeRewriter.Rewrite(syntaxTree, binder, usedHelpers, cancellationToken); return codeDocument .WithReferencedTagHelpers(usedHelpers.ToCollection()) - .WithSyntaxTree(rewrittenSyntaxTree); + .WithTagHelperRewrittenSyntaxTree(rewrittenSyntaxTree); } } diff --git a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/DefaultTagHelperResolutionPhase.cs b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/DefaultTagHelperResolutionPhase.cs index 74daa974dad..a71a2b48f43 100644 --- a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/DefaultTagHelperResolutionPhase.cs +++ b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/DefaultTagHelperResolutionPhase.cs @@ -40,14 +40,17 @@ protected override RazorCodeDocument ExecuteCore(RazorCodeDocument codeDocument, } var tagHelperContext = codeDocument.GetTagHelperContext(); - var syntaxTree = codeDocument.GetPreTagHelperSyntaxTree() ?? codeDocument.GetSyntaxTree(); - var parserOptions = syntaxTree?.Options; + + // This phase works with IR nodes only -- no syntax tree access needed. + // RazorCodeDocument.ParserOptions is a non-nullable property initialized by Create(), + // so it is always available here. + var parserOptions = codeDocument.ParserOptions; // Choose resolver based on file kind and language version. Component features // (MarkupElementIntermediateNode, RZ10012 diagnostics) require Version_3_0+ because // the ComponentDocumentClassifierPass is only registered at that version. _resolver = (codeDocument.FileKind.IsComponent() || codeDocument.FileKind.IsComponentImport()) - && parserOptions?.LanguageVersion >= RazorLanguageVersion.Version_3_0 + && parserOptions.LanguageVersion >= RazorLanguageVersion.Version_3_0 ? new ComponentTagHelperResolver() : new LegacyTagHelperResolver(); @@ -65,7 +68,7 @@ protected override RazorCodeDocument ExecuteCore(RazorCodeDocument codeDocument, using var usedHelpers = new TagHelperCollection.Builder(); var sourceDocument = codeDocument.Source; - var context = new ResolutionContext(sourceDocument, parserOptions, documentNode); + var context = new ResolutionContext(sourceDocument, documentNode); ResolveElements(documentNode, binder, prefix, usedHelpers, in context); // Add tag helper descriptor validation diagnostics (e.g. RZ3003). @@ -90,13 +93,11 @@ protected override RazorCodeDocument ExecuteCore(RazorCodeDocument codeDocument, private readonly struct ResolutionContext { public readonly RazorSourceDocument SourceDocument; - public readonly RazorParserOptions ParserOptions; public readonly DocumentIntermediateNode DocumentNode; - public ResolutionContext(RazorSourceDocument sourceDocument, RazorParserOptions parserOptions, DocumentIntermediateNode documentNode) + public ResolutionContext(RazorSourceDocument sourceDocument, DocumentIntermediateNode documentNode) { SourceDocument = sourceDocument; - ParserOptions = parserOptions; DocumentNode = documentNode; } } diff --git a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/RazorCodeDocument.cs b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/RazorCodeDocument.cs index 4ca32d36c1b..ecebff7c9d1 100644 --- a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/RazorCodeDocument.cs +++ b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/RazorCodeDocument.cs @@ -23,8 +23,14 @@ public sealed partial class RazorCodeDocument private readonly TagHelperCollection? _tagHelpers; private readonly TagHelperCollection? _referencedTagHelpers; - private readonly RazorSyntaxTree? _preTagHelperSyntaxTree; + // The canonical syntax tree produced by parsing and syntax-tree passes, before tag helper rewriting. + // Established by DefaultRazorTagHelperContextDiscoveryPhase (which reads it from _tagHelperRewrittenSyntaxTree + // on the first run). Once set, this field is stable throughout the rest of the pipeline. private readonly RazorSyntaxTree? _syntaxTree; + // The working syntax tree: initially set by DefaultRazorParsingPhase (same value as _syntaxTree), + // updated by DefaultRazorSyntaxTreePhase, and finally replaced with the tag-helper-rewritten tree + // by DefaultRazorTagHelperRewritePhase. + private readonly RazorSyntaxTree? _tagHelperRewrittenSyntaxTree; private readonly ImmutableArray _importSyntaxTrees; private readonly TagHelperDocumentContext? _tagHelperContext; private readonly DocumentIntermediateNode? _documentNode; @@ -38,8 +44,8 @@ private RazorCodeDocument( RazorCodeGenerationOptions codeGenerationOptions, TagHelperCollection? tagHelpers, TagHelperCollection? referencedTagHelpers, - RazorSyntaxTree? preTagHelperSyntaxTree, RazorSyntaxTree? syntaxTree, + RazorSyntaxTree? tagHelperRewrittenSyntaxTree, ImmutableArray importSyntaxTrees, TagHelperDocumentContext? tagHelperContext, DocumentIntermediateNode? documentNode, @@ -54,8 +60,8 @@ private RazorCodeDocument( _tagHelpers = tagHelpers; _referencedTagHelpers = referencedTagHelpers; - _preTagHelperSyntaxTree = preTagHelperSyntaxTree; _syntaxTree = syntaxTree; + _tagHelperRewrittenSyntaxTree = tagHelperRewrittenSyntaxTree; _importSyntaxTrees = importSyntaxTrees; _tagHelperContext = tagHelperContext; _documentNode = documentNode; @@ -84,8 +90,8 @@ public static RazorCodeDocument Create( codeGenerationOptions ?? RazorCodeGenerationOptions.Default, tagHelpers: null, referencedTagHelpers: null, - preTagHelperSyntaxTree: null, syntaxTree: null, + tagHelperRewrittenSyntaxTree: null, importSyntaxTrees: default, tagHelperContext: null, documentNode: null, @@ -111,7 +117,7 @@ internal RazorCodeDocument WithTagHelpers(TagHelperCollection? value) { return this; } - return new RazorCodeDocument(Source, Imports, ParserOptions, CodeGenerationOptions, value, _referencedTagHelpers, _preTagHelperSyntaxTree, _syntaxTree, _importSyntaxTrees, _tagHelperContext, _documentNode, _csharpDocument, _directiveTagHelperContributions); + return new RazorCodeDocument(Source, Imports, ParserOptions, CodeGenerationOptions, value, _referencedTagHelpers, _syntaxTree, _tagHelperRewrittenSyntaxTree, _importSyntaxTrees, _tagHelperContext, _documentNode, _csharpDocument, _directiveTagHelperContributions); } internal bool TryGetReferencedTagHelpers([NotNullWhen(true)] out TagHelperCollection? result) @@ -132,50 +138,51 @@ internal RazorCodeDocument WithReferencedTagHelpers(TagHelperCollection value) { return this; } - return new RazorCodeDocument(Source, Imports, ParserOptions, CodeGenerationOptions, _tagHelpers, value, _preTagHelperSyntaxTree, _syntaxTree, _importSyntaxTrees, _tagHelperContext, _documentNode, _csharpDocument, _directiveTagHelperContributions); + return new RazorCodeDocument(Source, Imports, ParserOptions, CodeGenerationOptions, _tagHelpers, value, _syntaxTree, _tagHelperRewrittenSyntaxTree, _importSyntaxTrees, _tagHelperContext, _documentNode, _csharpDocument, _directiveTagHelperContributions); } - internal bool TryGetPreTagHelperSyntaxTree([NotNullWhen(true)] out RazorSyntaxTree? result) + internal bool TryGetSyntaxTree([NotNullWhen(true)] out RazorSyntaxTree? result) { - result = _preTagHelperSyntaxTree; + result = _syntaxTree; return result is not null; } - internal RazorSyntaxTree? GetPreTagHelperSyntaxTree() - => _preTagHelperSyntaxTree; + internal RazorSyntaxTree? GetSyntaxTree() + => _syntaxTree; - internal RazorSyntaxTree GetRequiredPreTagHelperSyntaxTree() - => _preTagHelperSyntaxTree.AssumeNotNull(); + internal RazorSyntaxTree GetRequiredSyntaxTree() + => _syntaxTree.AssumeNotNull(); - internal RazorCodeDocument WithPreTagHelperSyntaxTree(RazorSyntaxTree? value) + internal RazorCodeDocument WithSyntaxTree(RazorSyntaxTree value) { - if (ReferenceEquals(value, _preTagHelperSyntaxTree)) + Debug.Assert(value is not null); + if (ReferenceEquals(value, _syntaxTree)) { return this; } - return new RazorCodeDocument(Source, Imports, ParserOptions, CodeGenerationOptions, _tagHelpers, _referencedTagHelpers, value, _syntaxTree, _importSyntaxTrees, _tagHelperContext, _documentNode, _csharpDocument, _directiveTagHelperContributions); + return new RazorCodeDocument(Source, Imports, ParserOptions, CodeGenerationOptions, _tagHelpers, _referencedTagHelpers, value, _tagHelperRewrittenSyntaxTree, _importSyntaxTrees, _tagHelperContext, _documentNode, _csharpDocument, _directiveTagHelperContributions); } - internal bool TryGetSyntaxTree([NotNullWhen(true)] out RazorSyntaxTree? result) + internal bool TryGetTagHelperRewrittenSyntaxTree([NotNullWhen(true)] out RazorSyntaxTree? result) { - result = _syntaxTree; + result = _tagHelperRewrittenSyntaxTree; return result is not null; } - internal RazorSyntaxTree? GetSyntaxTree() - => _syntaxTree; + internal RazorSyntaxTree? GetTagHelperRewrittenSyntaxTree() + => _tagHelperRewrittenSyntaxTree; - internal RazorSyntaxTree GetRequiredSyntaxTree() - => _syntaxTree.AssumeNotNull(); + internal RazorSyntaxTree GetRequiredTagHelperRewrittenSyntaxTree() + => _tagHelperRewrittenSyntaxTree.AssumeNotNull(); - internal RazorCodeDocument WithSyntaxTree(RazorSyntaxTree value) + internal RazorCodeDocument WithTagHelperRewrittenSyntaxTree(RazorSyntaxTree value) { Debug.Assert(value is not null); - if (ReferenceEquals(value, _syntaxTree)) + if (ReferenceEquals(value, _tagHelperRewrittenSyntaxTree)) { return this; } - return new RazorCodeDocument(Source, Imports, ParserOptions, CodeGenerationOptions, _tagHelpers, _referencedTagHelpers, _preTagHelperSyntaxTree, value, _importSyntaxTrees, _tagHelperContext, _documentNode, _csharpDocument, _directiveTagHelperContributions); + return new RazorCodeDocument(Source, Imports, ParserOptions, CodeGenerationOptions, _tagHelpers, _referencedTagHelpers, _syntaxTree, value, _importSyntaxTrees, _tagHelperContext, _documentNode, _csharpDocument, _directiveTagHelperContributions); } internal bool TryGetImportSyntaxTrees(out ImmutableArray result) @@ -202,7 +209,7 @@ internal RazorCodeDocument WithImportSyntaxTrees(ImmutableArray { return this; } - return new RazorCodeDocument(Source, Imports, ParserOptions, CodeGenerationOptions, _tagHelpers, _referencedTagHelpers, _preTagHelperSyntaxTree, _syntaxTree, value, _tagHelperContext, _documentNode, _csharpDocument, _directiveTagHelperContributions); + return new RazorCodeDocument(Source, Imports, ParserOptions, CodeGenerationOptions, _tagHelpers, _referencedTagHelpers, _syntaxTree, _tagHelperRewrittenSyntaxTree, value, _tagHelperContext, _documentNode, _csharpDocument, _directiveTagHelperContributions); } internal bool TryGetTagHelperContext([NotNullWhen(true)] out TagHelperDocumentContext? result) @@ -225,7 +232,7 @@ internal RazorCodeDocument WithTagHelperContext(TagHelperDocumentContext value) { return this; } - return new RazorCodeDocument(Source, Imports, ParserOptions, CodeGenerationOptions, _tagHelpers, _referencedTagHelpers, _preTagHelperSyntaxTree, _syntaxTree, _importSyntaxTrees, value, _documentNode, _csharpDocument, _directiveTagHelperContributions); + return new RazorCodeDocument(Source, Imports, ParserOptions, CodeGenerationOptions, _tagHelpers, _referencedTagHelpers, _syntaxTree, _tagHelperRewrittenSyntaxTree, _importSyntaxTrees, value, _documentNode, _csharpDocument, _directiveTagHelperContributions); } internal bool TryGetDocumentNode([NotNullWhen(true)] out DocumentIntermediateNode? result) @@ -247,7 +254,7 @@ internal RazorCodeDocument WithDocumentNode(DocumentIntermediateNode value) { return this; } - return new RazorCodeDocument(Source, Imports, ParserOptions, CodeGenerationOptions, _tagHelpers, _referencedTagHelpers, _preTagHelperSyntaxTree, _syntaxTree, _importSyntaxTrees, _tagHelperContext, value, _csharpDocument, _directiveTagHelperContributions); + return new RazorCodeDocument(Source, Imports, ParserOptions, CodeGenerationOptions, _tagHelpers, _referencedTagHelpers, _syntaxTree, _tagHelperRewrittenSyntaxTree, _importSyntaxTrees, _tagHelperContext, value, _csharpDocument, _directiveTagHelperContributions); } internal bool TryGetCSharpDocument([NotNullWhen(true)] out RazorCSharpDocument? result) @@ -269,7 +276,7 @@ internal RazorCodeDocument WithCSharpDocument(RazorCSharpDocument value) { return this; } - return new RazorCodeDocument(Source, Imports, ParserOptions, CodeGenerationOptions, _tagHelpers, _referencedTagHelpers, _preTagHelperSyntaxTree, _syntaxTree, _importSyntaxTrees, _tagHelperContext, _documentNode, value, _directiveTagHelperContributions); + return new RazorCodeDocument(Source, Imports, ParserOptions, CodeGenerationOptions, _tagHelpers, _referencedTagHelpers, _syntaxTree, _tagHelperRewrittenSyntaxTree, _importSyntaxTrees, _tagHelperContext, _documentNode, value, _directiveTagHelperContributions); } internal ImmutableArray GetDirectiveTagHelperContributions() @@ -282,7 +289,7 @@ internal RazorCodeDocument WithDirectiveTagHelperContributions(ImmutableArray> ProvideAsync(RazorCodeAct return SpecializedTasks.EmptyImmutableArray(); } - if (!context.CodeDocument.TryGetSyntaxTree(out var syntaxTree)) + if (!context.CodeDocument.TryGetTagHelperRewrittenSyntaxTree(out var syntaxTree)) { return SpecializedTasks.EmptyImmutableArray(); } diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Razor/ExtractToComponentCodeActionResolver.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Razor/ExtractToComponentCodeActionResolver.cs index 96d82e6882a..92bca08e438 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Razor/ExtractToComponentCodeActionResolver.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Razor/ExtractToComponentCodeActionResolver.cs @@ -57,7 +57,7 @@ internal class ExtractToComponentCodeActionResolver( builder.AppendLine(); } - var syntaxTree = componentDocument.GetRequiredSyntaxTree(); + var syntaxTree = componentDocument.GetRequiredTagHelperRewrittenSyntaxTree(); // Right now this includes all the usings in the original document. // https://github.com/dotnet/razor/issues/11025 tracks reducing to only the required set. diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Razor/RemoveUnnecessaryDirectivesCodeActionProvider.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Razor/RemoveUnnecessaryDirectivesCodeActionProvider.cs index 268e72c0af0..c2cf636b9a9 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Razor/RemoveUnnecessaryDirectivesCodeActionProvider.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Razor/RemoveUnnecessaryDirectivesCodeActionProvider.cs @@ -26,7 +26,7 @@ public Task> ProvideAsync(RazorCodeAct return SpecializedTasks.EmptyImmutableArray(); } - if (!context.CodeDocument.TryGetSyntaxTree(out var tree)) + if (!context.CodeDocument.TryGetTagHelperRewrittenSyntaxTree(out var tree)) { return SpecializedTasks.EmptyImmutableArray(); } diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Razor/SimplifyTagToSelfClosingCodeActionProvider.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Razor/SimplifyTagToSelfClosingCodeActionProvider.cs index 4f7490ce536..ee525ebf1be 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Razor/SimplifyTagToSelfClosingCodeActionProvider.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Razor/SimplifyTagToSelfClosingCodeActionProvider.cs @@ -43,7 +43,7 @@ public Task> ProvideAsync(RazorCodeAct return SpecializedTasks.EmptyImmutableArray(); } - var syntaxTree = context.CodeDocument.GetSyntaxTree(); + var syntaxTree = context.CodeDocument.GetTagHelperRewrittenSyntaxTree(); if (syntaxTree?.Root is null) { return SpecializedTasks.EmptyImmutableArray(); diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Completion/RazorCompletionListProvider.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Completion/RazorCompletionListProvider.cs index cf1e3bf1920..abbe1202e3e 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Completion/RazorCompletionListProvider.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Completion/RazorCompletionListProvider.cs @@ -45,7 +45,7 @@ internal class RazorCompletionListProvider( _ => CompletionReason.Typing, }; - var syntaxTree = codeDocument.GetRequiredSyntaxTree(); + var syntaxTree = codeDocument.GetRequiredTagHelperRewrittenSyntaxTree(); var tagHelperContext = codeDocument.GetRequiredTagHelperContext(); var owner = syntaxTree.Root.FindInnermostNode(absoluteIndex, includeWhitespace: true, walkMarkersBack: true); diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Diagnostics/RazorTranslateDiagnosticsService.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Diagnostics/RazorTranslateDiagnosticsService.cs index f733380b229..839e0be9bdd 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Diagnostics/RazorTranslateDiagnosticsService.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Diagnostics/RazorTranslateDiagnosticsService.cs @@ -80,7 +80,7 @@ private static LspDiagnostic[] FilterHTMLDiagnostics( LspDiagnostic[] unmappedDiagnostics, RazorCodeDocument codeDocument) { - var syntaxTree = codeDocument.GetRequiredSyntaxTree(); + var syntaxTree = codeDocument.GetRequiredTagHelperRewrittenSyntaxTree(); var sourceText = codeDocument.Source.Text; using var _ = DictionaryPool.GetPooledObject(out var processedAttributes); @@ -539,7 +539,7 @@ private bool IsUsingDirectiveUsed(LspDiagnostic diagnostic, RazorCodeDocument co // have to check if the using was actually used by component binding, if so, we need to keep the // diagnostic. Conveniently, this means we don't need to worry about actually reporting our own // unused diagnostics, so it's worth it. - var syntaxTree = codeDocument.GetRequiredSyntaxTree(); + var syntaxTree = codeDocument.GetRequiredTagHelperRewrittenSyntaxTree(); if (TryGetOriginalDiagnosticRange(diagnostic, codeDocument, out var originalRange) && syntaxTree.FindInnermostNode(codeDocument.Source.Text, originalRange.Start) is { Parent.Parent: RazorUsingDirectiveSyntax usingDirectiveSyntax }) { @@ -551,7 +551,7 @@ private bool IsUsingDirectiveUsed(LspDiagnostic diagnostic, RazorCodeDocument co private static bool CheckIfDocumentHasRazorDiagnostic(RazorCodeDocument codeDocument, string razorDiagnosticCode) { - return codeDocument.GetRequiredSyntaxTree().Diagnostics.Any(razorDiagnosticCode, static (d, code) => d.Id == code); + return codeDocument.GetRequiredTagHelperRewrittenSyntaxTree().Diagnostics.Any(razorDiagnosticCode, static (d, code) => d.Id == code); } private bool TryGetOriginalDiagnosticRange(LspDiagnostic diagnostic, RazorCodeDocument codeDocument, [NotNullWhen(true)] out LspRange? originalRange) diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/DocumentMapping/RazorEditService_Methods.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/DocumentMapping/RazorEditService_Methods.cs index f826e0acf66..f918e1b3764 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/DocumentMapping/RazorEditService_Methods.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/DocumentMapping/RazorEditService_Methods.cs @@ -29,7 +29,7 @@ private static void AddMethodChanges(ref PooledArrayBuilder edi return; } - var tree = codeDocument.GetRequiredSyntaxTree(); + var tree = codeDocument.GetRequiredTagHelperRewrittenSyntaxTree(); var firstDirective = tree.EnumerateDirectives(static dir => dir.IsCodeDirective() || dir.IsFunctionsDirective()).FirstOrDefault(); var csharpCodeBlock = firstDirective?.DirectiveBody.CSharpCode; diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Extensions/RazorCodeDocumentExtensions.CachedData.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Extensions/RazorCodeDocumentExtensions.CachedData.cs index e126f446c44..016cd1db967 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Extensions/RazorCodeDocumentExtensions.CachedData.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Extensions/RazorCodeDocumentExtensions.CachedData.cs @@ -35,7 +35,7 @@ public ImmutableArray GetOrComputeClassifiedSpans(CancellationTo using (_stateLock.DisposableWait(cancellationToken)) { - return _classifiedSpans ??= ClassifiedSpanVisitor.VisitRoot(_codeDocument.GetRequiredSyntaxTree()); + return _classifiedSpans ??= ClassifiedSpanVisitor.VisitRoot(_codeDocument.GetRequiredTagHelperRewrittenSyntaxTree()); } } @@ -48,7 +48,7 @@ public ImmutableArray GetOrComputeTagHelperSpans(CancellationToken c using (_stateLock.DisposableWait(cancellationToken)) { - return _tagHelperSpans ??= ComputeTagHelperSpans(_codeDocument.GetRequiredSyntaxTree()); + return _tagHelperSpans ??= ComputeTagHelperSpans(_codeDocument.GetRequiredTagHelperRewrittenSyntaxTree()); } static ImmutableArray ComputeTagHelperSpans(RazorSyntaxTree syntaxTree) diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Extensions/RazorCodeDocumentExtensions.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Extensions/RazorCodeDocumentExtensions.cs index d550f3d531a..177b6325bbd 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Extensions/RazorCodeDocumentExtensions.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Extensions/RazorCodeDocumentExtensions.cs @@ -18,7 +18,7 @@ internal static partial class RazorCodeDocumentExtensions { public static bool TryGetSyntaxRoot(this RazorCodeDocument codeDocument, [NotNullWhen(true)] out Syntax.SyntaxNode? result) { - if (codeDocument.TryGetSyntaxTree(out var syntaxTree)) + if (codeDocument.TryGetTagHelperRewrittenSyntaxTree(out var syntaxTree)) { result = syntaxTree.Root; return true; @@ -29,7 +29,7 @@ public static bool TryGetSyntaxRoot(this RazorCodeDocument codeDocument, [NotNul } public static Syntax.SyntaxNode GetRequiredSyntaxRoot(this RazorCodeDocument codeDocument) - => codeDocument.GetRequiredSyntaxTree().Root; + => codeDocument.GetRequiredTagHelperRewrittenSyntaxTree().Root; public static SourceText GetCSharpSourceText(this RazorCodeDocument document) => document.GetRequiredCSharpDocument().Text; diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/FoldingRanges/AbstractSyntaxNodeFoldingProvider.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/FoldingRanges/AbstractSyntaxNodeFoldingProvider.cs index cb43be48d04..650a4e01a0b 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/FoldingRanges/AbstractSyntaxNodeFoldingProvider.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/FoldingRanges/AbstractSyntaxNodeFoldingProvider.cs @@ -15,7 +15,7 @@ internal abstract class AbstractSyntaxNodeFoldingProvider : IRazorFolding public ImmutableArray GetFoldingRanges(RazorCodeDocument codeDocument) { var sourceText = codeDocument.Source.Text; - var syntaxTree = codeDocument.GetRequiredSyntaxTree(); + var syntaxTree = codeDocument.GetRequiredTagHelperRewrittenSyntaxTree(); var nodes = GetFoldableNodes(syntaxTree); using var builder = new PooledArrayBuilder(nodes.Length); diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/FoldingRanges/UsingsFoldingRangeProvider.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/FoldingRanges/UsingsFoldingRangeProvider.cs index 46f685c4730..921242f3bb3 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/FoldingRanges/UsingsFoldingRangeProvider.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/FoldingRanges/UsingsFoldingRangeProvider.cs @@ -16,7 +16,7 @@ public ImmutableArray GetFoldingRanges(RazorCodeDocument codeDocum using var ranges = new PooledArrayBuilder(); var sourceDocument = codeDocument.Source; - var syntaxTree = codeDocument.GetRequiredSyntaxTree(); + var syntaxTree = codeDocument.GetRequiredTagHelperRewrittenSyntaxTree(); foreach (var directive in syntaxTree.EnumerateUsingDirectives()) { diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Formatting/FormattingContext.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Formatting/FormattingContext.cs index 5de6df77a43..ead39bbbfa7 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Formatting/FormattingContext.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Formatting/FormattingContext.cs @@ -148,7 +148,7 @@ private ImmutableArray GetFormattingSpans() static ImmutableArray ComputeFormattingSpans(RazorCodeDocument codeDocument) { - var syntaxTree = codeDocument.GetRequiredSyntaxTree(); + var syntaxTree = codeDocument.GetRequiredTagHelperRewrittenSyntaxTree(); var inGlobalNamespace = codeDocument.TryGetNamespace(fallbackToRootNamespace: true, out var @namespace) && string.IsNullOrEmpty(@namespace); diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Formatting/Passes/FormattingDiagnosticValidationPass.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Formatting/Passes/FormattingDiagnosticValidationPass.cs index 81f55425eb4..6b17d2425fd 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Formatting/Passes/FormattingDiagnosticValidationPass.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Formatting/Passes/FormattingDiagnosticValidationPass.cs @@ -24,12 +24,12 @@ internal sealed class FormattingDiagnosticValidationPass(ILoggerFactory loggerFa public async Task IsValidAsync(FormattingContext context, ImmutableArray changes, CancellationToken cancellationToken) { - var originalDiagnostics = context.CodeDocument.GetRequiredSyntaxTree().Diagnostics; + var originalDiagnostics = context.CodeDocument.GetRequiredTagHelperRewrittenSyntaxTree().Diagnostics; var text = context.SourceText; var changedText = text.WithChanges(changes); var changedContext = await context.WithTextAsync(changedText, cancellationToken).ConfigureAwait(false); - var changedDiagnostics = changedContext.CodeDocument.GetRequiredSyntaxTree().Diagnostics; + var changedDiagnostics = changedContext.CodeDocument.GetRequiredTagHelperRewrittenSyntaxTree().Diagnostics; // We want to ensure diagnostics didn't change, but since we're formatting things, its expected // that some of them might have moved around. diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Formatting/Passes/RazorFormattingPass.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Formatting/Passes/RazorFormattingPass.cs index 0353c48110e..307efdf1147 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Formatting/Passes/RazorFormattingPass.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Formatting/Passes/RazorFormattingPass.cs @@ -39,7 +39,7 @@ public async Task> ExecuteAsync(FormattingContext con } // Format the razor bits of the file - var syntaxTree = changedContext.CodeDocument.GetRequiredSyntaxTree(); + var syntaxTree = changedContext.CodeDocument.GetRequiredTagHelperRewrittenSyntaxTree(); var razorChanges = FormatRazor(changedContext, syntaxTree); if (razorChanges.Length > 0) diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Formatting/UsingDirectiveHelper.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Formatting/UsingDirectiveHelper.cs index e673f3e397d..48efe276878 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Formatting/UsingDirectiveHelper.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Formatting/UsingDirectiveHelper.cs @@ -215,7 +215,7 @@ private static bool IsNamespaceOrPageDirective(RazorSyntaxNode node) /// public static bool NeedsSortOrConsolidate(RazorCodeDocument codeDocument) { - var syntaxTree = codeDocument.GetRequiredSyntaxTree(); + var syntaxTree = codeDocument.GetRequiredTagHelperRewrittenSyntaxTree(); var usingDirectives = syntaxTree.GetUsingDirectives(); if (usingDirectives.Length <= 1) @@ -267,7 +267,7 @@ public static ImmutableArray GetSortAndConsolidateEdits( RazorCodeDocument codeDocument, ImmutableArray? directivesToKeep = null) { - var syntaxTree = codeDocument.GetRequiredSyntaxTree(); + var syntaxTree = codeDocument.GetRequiredTagHelperRewrittenSyntaxTree(); var usingDirectives = syntaxTree.GetUsingDirectives(); var sourceText = codeDocument.Source.Text; diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/LinkedEditingRange/LinkedEditingRangeHelper.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/LinkedEditingRange/LinkedEditingRangeHelper.cs index 74d344cd27b..d5d5cfe140a 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/LinkedEditingRange/LinkedEditingRangeHelper.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/LinkedEditingRange/LinkedEditingRangeHelper.cs @@ -24,7 +24,7 @@ internal static class LinkedEditingRangeHelper return null; } - var syntaxTree = codeDocument.GetRequiredSyntaxTree(); + var syntaxTree = codeDocument.GetRequiredTagHelperRewrittenSyntaxTree(); // We only care if the user is within a TagHelper or HTML tag with a valid start and end tag. if (TryGetNearestMarkupNameTokens(syntaxTree, validLocation, out var startTagNameToken, out var endTagNameToken) && diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/DocumentContext.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/DocumentContext.cs index 959d51ccded..1b9466fafe1 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/DocumentContext.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/DocumentContext.cs @@ -69,7 +69,7 @@ public ValueTask GetSyntaxTreeAsync(CancellationToken cancellat static RazorSyntaxTree GetSyntaxTreeCore(RazorCodeDocument codeDocument) { - return codeDocument.GetRequiredSyntaxTree(); + return codeDocument.GetRequiredTagHelperRewrittenSyntaxTree(); } async ValueTask GetSyntaxTreeCoreAsync(CancellationToken cancellationToken) diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/DevTools/RemoteDevToolsService.cs b/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/DevTools/RemoteDevToolsService.cs index b1b347ed95a..8fe7206993f 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/DevTools/RemoteDevToolsService.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/DevTools/RemoteDevToolsService.cs @@ -177,7 +177,7 @@ private static async ValueTask GetTagHelpersJsonAsync(RemoteDocumentCont private static async ValueTask GetRazorSyntaxTreeAsync(RemoteDocumentContext documentContext, CancellationToken cancellationToken) { var codeDocument = await documentContext.GetCodeDocumentAsync(cancellationToken).ConfigureAwait(false); - var razorSyntaxTree = codeDocument.GetSyntaxTree(); + var razorSyntaxTree = codeDocument.GetTagHelperRewrittenSyntaxTree(); if (razorSyntaxTree?.Root == null) return null; diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/Diagnostics/RemoteDiagnosticsService.cs b/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/Diagnostics/RemoteDiagnosticsService.cs index c7d79120ad5..508a1f3eb71 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/Diagnostics/RemoteDiagnosticsService.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/Diagnostics/RemoteDiagnosticsService.cs @@ -65,7 +65,7 @@ .. await _translateDiagnosticsService.TranslateAsync(RazorLanguageKind.Html, htm // spans of the unused directives here so we can use that information for code fixes, without having to compute // it on demand every time. var sourceText = codeDocument.Source.Text; - var tree = codeDocument.GetRequiredSyntaxTree(); + var tree = codeDocument.GetRequiredTagHelperRewrittenSyntaxTree(); using var unusedDirectiveSpans = new PooledArrayBuilder(); // In VS, we use Warning so we get an error list entry, and the tags mean we won't get squiggles in the editor. @@ -119,7 +119,7 @@ private static ImmutableArray GetRazorDiagnostics(RemoteDocumentC // them out in the RazorTranslateDiagnosticsService. if (codeDocument.FileKind.IsLegacy() && !codeDocument.IsImportsFile()) { - var syntaxTree = codeDocument.GetRequiredSyntaxTree(); + var syntaxTree = codeDocument.GetRequiredTagHelperRewrittenSyntaxTree(); var sourceText = codeDocument.Source.Text; foreach (var directive in syntaxTree.EnumerateAddTagHelperDirectives()) diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/RemoveAndSortUsings/RemoteRemoveAndSortUsingsService.cs b/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/RemoveAndSortUsings/RemoteRemoveAndSortUsingsService.cs index ab0899f68bf..0d733dafb12 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/RemoveAndSortUsings/RemoteRemoveAndSortUsingsService.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/RemoveAndSortUsings/RemoteRemoveAndSortUsingsService.cs @@ -41,7 +41,7 @@ private static async ValueTask> GetRemoveAndSortUsing { var codeDocument = await context.GetCodeDocumentAsync(cancellationToken).ConfigureAwait(false); var sourceText = codeDocument.Source.Text; - var syntaxTree = codeDocument.GetRequiredSyntaxTree(); + var syntaxTree = codeDocument.GetRequiredTagHelperRewrittenSyntaxTree(); var allUsingDirectives = syntaxTree.GetUsingDirectives(); if (allUsingDirectives.Length == 0) diff --git a/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/Completion/BlazorDataAttributeCompletionItemProviderTest.cs b/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/Completion/BlazorDataAttributeCompletionItemProviderTest.cs index f1f29372174..d99e9c8aa55 100644 --- a/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/Completion/BlazorDataAttributeCompletionItemProviderTest.cs +++ b/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/Completion/BlazorDataAttributeCompletionItemProviderTest.cs @@ -127,7 +127,7 @@ public void GetCompletionItems_OnNonComponentFile_ReturnsEmpty() // Arrange - need to test with non-component file, which requires different setup TestCode testCode = "
"; var codeDocument = GetCodeDocument(testCode.Text, RazorFileKind.Legacy); - var syntaxTree = codeDocument.GetRequiredSyntaxTree(); + var syntaxTree = codeDocument.GetRequiredTagHelperRewrittenSyntaxTree(); var tagHelperContext = codeDocument.GetRequiredTagHelperContext(); var owner = syntaxTree.Root.FindInnermostNode(testCode.Position, includeWhitespace: true, walkMarkersBack: true); owner = AbstractRazorCompletionFactsService.AdjustSyntaxNodeForWordBoundary(owner, testCode.Position); @@ -191,7 +191,7 @@ public void GetCompletionItems_WithSnippetsDisabled_ReturnsPlainText() UseVsCodeCompletionCommitCharacters: false); TestCode testCode = "
"; var codeDocument = GetCodeDocument(testCode.Text); - var syntaxTree = codeDocument.GetRequiredSyntaxTree(); + var syntaxTree = codeDocument.GetRequiredTagHelperRewrittenSyntaxTree(); var tagHelperContext = codeDocument.GetRequiredTagHelperContext(); var owner = syntaxTree.Root.FindInnermostNode(testCode.Position, includeWhitespace: true, walkMarkersBack: true); owner = AbstractRazorCompletionFactsService.AdjustSyntaxNodeForWordBoundary(owner, testCode.Position); @@ -224,7 +224,7 @@ private RazorCodeDocument GetCodeDocument(string content, RazorFileKind? fileKin private RazorCompletionContext CreateRazorCompletionContext(TestCode testCode) { var codeDocument = GetCodeDocument(testCode.Text); - var syntaxTree = codeDocument.GetRequiredSyntaxTree(); + var syntaxTree = codeDocument.GetRequiredTagHelperRewrittenSyntaxTree(); var tagHelperContext = codeDocument.GetRequiredTagHelperContext(); var owner = syntaxTree.Root.FindInnermostNode(testCode.Position, includeWhitespace: true, walkMarkersBack: true); diff --git a/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/Completion/DirectiveAttributeCompletionItemProviderTest.AttributeNames.cs b/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/Completion/DirectiveAttributeCompletionItemProviderTest.AttributeNames.cs index 0c7bd444677..3d22ef952e7 100644 --- a/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/Completion/DirectiveAttributeCompletionItemProviderTest.AttributeNames.cs +++ b/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/Completion/DirectiveAttributeCompletionItemProviderTest.AttributeNames.cs @@ -401,7 +401,7 @@ private static void AssertDoesNotContain(IReadOnlyList comp internal RazorCompletionContext CreateRazorCompletionContext(TestCode testCode) { var codeDocument = GetCodeDocument(testCode.Text); - var syntaxTree = codeDocument.GetRequiredSyntaxTree(); + var syntaxTree = codeDocument.GetRequiredTagHelperRewrittenSyntaxTree(); var tagHelperContext = codeDocument.GetRequiredTagHelperContext(); var owner = syntaxTree.Root.FindInnermostNode(testCode.Position, includeWhitespace: true, walkMarkersBack: true); diff --git a/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/Completion/DirectiveAttributeEventParameterCompletionItemProviderTest.cs b/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/Completion/DirectiveAttributeEventParameterCompletionItemProviderTest.cs index 44ea42e429a..7a6532a0d4b 100644 --- a/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/Completion/DirectiveAttributeEventParameterCompletionItemProviderTest.cs +++ b/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/Completion/DirectiveAttributeEventParameterCompletionItemProviderTest.cs @@ -205,7 +205,7 @@ private static void AssertContains(IReadOnlyList completion private RazorCompletionContext CreateRazorCompletionContext(TestCode documentContent) { var codeDocument = GetCodeDocument(documentContent.Text); - var syntaxTree = codeDocument.GetRequiredSyntaxTree(); + var syntaxTree = codeDocument.GetRequiredTagHelperRewrittenSyntaxTree(); var tagHelperDocumentContext = codeDocument.GetRequiredTagHelperContext(); var absoluteIndex = documentContent.Position; diff --git a/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/Completion/DirectiveAttributeTransitionCompletionItemProviderTest.cs b/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/Completion/DirectiveAttributeTransitionCompletionItemProviderTest.cs index f6b7a85ec2a..aaec60354c0 100644 --- a/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/Completion/DirectiveAttributeTransitionCompletionItemProviderTest.cs +++ b/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/Completion/DirectiveAttributeTransitionCompletionItemProviderTest.cs @@ -345,7 +345,7 @@ private RazorCompletionContext CreateContext(TestCode text, RazorFileKind? fileK { var absoluteIndex = text.Position; var codeDocument = GetCodeDocument(text.Text, fileKind); - var syntaxTree = codeDocument.GetRequiredSyntaxTree(); + var syntaxTree = codeDocument.GetRequiredTagHelperRewrittenSyntaxTree(); var owner = syntaxTree.Root.FindInnermostNode(absoluteIndex, includeWhitespace: true, walkMarkersBack: true); owner = AbstractRazorCompletionFactsService.AdjustSyntaxNodeForWordBoundary(owner, absoluteIndex); diff --git a/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/Completion/RazorCompletionListProviderTest.cs b/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/Completion/RazorCompletionListProviderTest.cs index 876a45e3538..506a9e5041b 100644 --- a/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/Completion/RazorCompletionListProviderTest.cs +++ b/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/Completion/RazorCompletionListProviderTest.cs @@ -537,7 +537,7 @@ private static RazorCodeDocument CreateCodeDocument(string text, string document var codeDocument = TestRazorCodeDocument.CreateEmpty(); var sourceDocument = TestRazorSourceDocument.Create(text, filePath: documentFilePath); var syntaxTree = RazorSyntaxTree.Parse(sourceDocument); - codeDocument = codeDocument.WithSyntaxTree(syntaxTree); + codeDocument = codeDocument.WithTagHelperRewrittenSyntaxTree(syntaxTree); var tagHelperDocumentContext = TagHelperDocumentContext.GetOrCreate(tagHelpers ?? []); codeDocument = codeDocument.WithTagHelperContext(tagHelperDocumentContext); return codeDocument; diff --git a/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/Diagnostics/TaskListDiagnosticProviderTest.cs b/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/Diagnostics/TaskListDiagnosticProviderTest.cs index 6af6ce5a044..abd0c93eb3c 100644 --- a/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/Diagnostics/TaskListDiagnosticProviderTest.cs +++ b/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/Diagnostics/TaskListDiagnosticProviderTest.cs @@ -60,7 +60,7 @@ public void DoesntFit() private static void VerifyTODOComments(TestCode input) { var codeDocument = TestRazorCodeDocument.Create(input.Text); - codeDocument = codeDocument.WithSyntaxTree(RazorSyntaxTree.Parse(codeDocument.Source)); + codeDocument = codeDocument.WithTagHelperRewrittenSyntaxTree(RazorSyntaxTree.Parse(codeDocument.Source)); var inputText = codeDocument.Source.Text; var diagnostics = TaskListDiagnosticProvider.GetTaskListDiagnostics(codeDocument, ["TODO", "ReallyLongPrefix"]); diff --git a/src/Shared/Microsoft.AspNetCore.Razor.Test.Common/Language/IntegrationTests/IntegrationTestBase.cs b/src/Shared/Microsoft.AspNetCore.Razor.Test.Common/Language/IntegrationTests/IntegrationTestBase.cs index ceb0d375125..2d6bc26a7ae 100644 --- a/src/Shared/Microsoft.AspNetCore.Razor.Test.Common/Language/IntegrationTests/IntegrationTestBase.cs +++ b/src/Shared/Microsoft.AspNetCore.Razor.Test.Common/Language/IntegrationTests/IntegrationTestBase.cs @@ -461,7 +461,7 @@ protected void AssertSourceMappingsMatchBaseline(RazorCodeDocument codeDocument, Assert.Equal(baseline, actualBaseline); - var syntaxTree = codeDocument.GetRequiredSyntaxTree(); + var syntaxTree = codeDocument.GetTagHelperRewrittenSyntaxTree() ?? codeDocument.GetRequiredSyntaxTree(); var visitor = new CodeSpanVisitor(); visitor.Visit(syntaxTree.Root); @@ -561,7 +561,7 @@ protected void AssertLinePragmas(RazorCodeDocument codeDocument) Assert.NotNull(csharpDocument); var linePragmas = csharpDocument.LinePragmas; - var syntaxTree = codeDocument.GetRequiredSyntaxTree(); + var syntaxTree = codeDocument.GetTagHelperRewrittenSyntaxTree() ?? codeDocument.GetRequiredSyntaxTree(); var sourceContent = syntaxTree.Source.Text.ToString(); var classifiedSpans = syntaxTree.GetClassifiedSpans(); foreach (var classifiedSpan in classifiedSpans) diff --git a/src/Shared/Microsoft.AspNetCore.Razor.Test.Common/Language/IntegrationTests/RazorBaselineIntegrationTestBase.cs b/src/Shared/Microsoft.AspNetCore.Razor.Test.Common/Language/IntegrationTests/RazorBaselineIntegrationTestBase.cs index 47e68636c3a..ddfae916001 100644 --- a/src/Shared/Microsoft.AspNetCore.Razor.Test.Common/Language/IntegrationTests/RazorBaselineIntegrationTestBase.cs +++ b/src/Shared/Microsoft.AspNetCore.Razor.Test.Common/Language/IntegrationTests/RazorBaselineIntegrationTestBase.cs @@ -182,7 +182,7 @@ protected void AssertLinePragmas(RazorCodeDocument codeDocument) } else { - var syntaxTree = codeDocument.GetRequiredSyntaxTree(); + var syntaxTree = codeDocument.GetTagHelperRewrittenSyntaxTree() ?? codeDocument.GetRequiredSyntaxTree(); var sourceContent = syntaxTree.Source.Text.ToString(); var classifiedSpans = syntaxTree.GetClassifiedSpans(); foreach (var classifiedSpan in classifiedSpans)