Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
69011ac
RazorProjectEngine: Use ArgHelper.ThrowIfNull throughout
DustinCampbell Nov 8, 2024
dc2d73a
RazorProjectEngine: Remove two unneeded wrapper methods
DustinCampbell Nov 8, 2024
1c6fb18
RazorProjectEngine: Remove a couple of unneeded ArgHelper.ThrowIfNull
DustinCampbell Nov 8, 2024
5dea634
RazorProjectEngine: Do not allow nullable file kind
DustinCampbell Nov 8, 2024
2f7872d
RazorProjectEngine: Remove ArgumentNullExceptions in ctor
DustinCampbell Nov 8, 2024
141e53b
RazorProjectEngine: Clean up CreateCodeDocumentCore
DustinCampbell Dec 26, 2024
32fd56f
Introduce FeatureCache<T> helper class
DustinCampbell Dec 26, 2024
a600ba0
RazorEngine: Use ArgHelper.ThrowIfNull
DustinCampbell Dec 26, 2024
3e8210c
RazorEngine: Use FeatureCache<T>
DustinCampbell Dec 26, 2024
9bf66aa
Use RazorEngine.GetFeatures<T>() throughout
DustinCampbell Dec 26, 2024
0c482c3
RazorProjectEngine: Use FeatureCache<T>
DustinCampbell Dec 26, 2024
64394f2
Use RazorProjectEngine.GetFeatures<T>() throughout
DustinCampbell Dec 26, 2024
c728852
RazorProjectEngine: Don't expose EngineFeatures
DustinCampbell Dec 26, 2024
3fa7d25
RazorProjectEngine: Rename ProjectFeatures to Features
DustinCampbell Dec 26, 2024
14ed4ac
RazorProjectEngine: Pass PooledArrayBuilder to GetImportSourceDocuments
DustinCampbell Dec 26, 2024
7c76b22
RazorProjectEngine: Extract imports logic to GetImportSources method
DustinCampbell Dec 26, 2024
52b1246
RazorEnginePhaseBase: Use ArgHelper.ThrowIfNull
DustinCampbell Dec 26, 2024
95d5d76
Improvements to Assumed
DustinCampbell Dec 26, 2024
5708be6
Update AssumeNotNull extensions to include optional message
DustinCampbell Dec 26, 2024
1e065d1
RazorEnginePhaseBase: Clean up and add Initialize method
DustinCampbell Dec 26, 2024
e36c4be
RazorEngineFeatureBase: Clean up and add Initialize method
DustinCampbell Dec 26, 2024
f5b2355
RazorProjectEngineFeatureBase: Clean up and add Initialize method
DustinCampbell Dec 26, 2024
9edb972
SourceGeneratorProjectEngine: Don't inherit from RazorProjectEngine
DustinCampbell Dec 26, 2024
cffdcbf
Thread CancellationToken into compile phases and cancel from tooling
DustinCampbell Dec 26, 2024
9d55eb4
Fix telemetry stack walking
DustinCampbell Jan 6, 2025
1956af7
Move ThrowIfCancellationRequested call
DustinCampbell Jan 6, 2025
a86086c
Merge branch 'main' into compiler-cancellation
DustinCampbell Jan 7, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

#nullable disable

using System.Text;
using Microsoft.AspNetCore.Razor.Language;
using Microsoft.AspNetCore.Razor.Language.Intermediate;
using Xunit;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

#nullable disable

using System.Text;
using Microsoft.AspNetCore.Razor.Language;
using Microsoft.AspNetCore.Razor.Language.Extensions;
using Microsoft.AspNetCore.Razor.Language.Intermediate;
Expand Down Expand Up @@ -339,7 +338,7 @@ public override void VisitNamespaceDeclaration(NamespaceDeclarationIntermediateN
}
}

private class DesignTimeOptionsFeature : IConfigureRazorParserOptionsFeature, IConfigureRazorCodeGenerationOptionsFeature
private class DesignTimeOptionsFeature : RazorEngineFeatureBase, IConfigureRazorParserOptionsFeature, IConfigureRazorCodeGenerationOptionsFeature
{
private readonly bool _designTime;

Expand All @@ -350,8 +349,6 @@ public DesignTimeOptionsFeature(bool designTime)

public int Order { get; }

public RazorEngine Engine { get; set; }

public void Configure(RazorParserOptionsBuilder options)
{
options.SetDesignTime(_designTime);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#nullable disable

using Microsoft.AspNetCore.Razor.Language;
using Microsoft.AspNetCore.Razor.Language.Extensions;
using Microsoft.AspNetCore.Razor.Language.Intermediate;
using Roslyn.Test.Utilities;
using Xunit;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ private static DocumentIntermediateNode CreateIRDocument(RazorEngine engine, Raz
// We also expect the default tag helper pass to run first.
var documentNode = codeDocument.GetDocumentIntermediateNode();

var defaultTagHelperPass = engine.Features.OfType<DefaultTagHelperOptimizationPass>().Single();
var defaultTagHelperPass = engine.GetFeatures<DefaultTagHelperOptimizationPass>().Single();
defaultTagHelperPass.Execute(codeDocument, documentNode);

return codeDocument.GetDocumentIntermediateNode();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

#nullable disable

using System.Text;
using Microsoft.AspNetCore.Razor.Language;
using Microsoft.AspNetCore.Razor.Language.Extensions;
using Microsoft.AspNetCore.Razor.Language.Intermediate;
Expand Down Expand Up @@ -339,7 +338,7 @@ public override void VisitNamespaceDeclaration(NamespaceDeclarationIntermediateN
}
}

private class DesignTimeOptionsFeature : IConfigureRazorParserOptionsFeature, IConfigureRazorCodeGenerationOptionsFeature
private class DesignTimeOptionsFeature : RazorEngineFeatureBase, IConfigureRazorParserOptionsFeature, IConfigureRazorCodeGenerationOptionsFeature
{
private readonly bool _designTime;

Expand All @@ -350,8 +349,6 @@ public DesignTimeOptionsFeature(bool designTime)

public int Order { get; }

public RazorEngine Engine { get; set; }

public void Configure(RazorParserOptionsBuilder options)
{
options.SetDesignTime(_designTime);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#nullable disable

using Microsoft.AspNetCore.Razor.Language;
using Microsoft.AspNetCore.Razor.Language.Extensions;
using Microsoft.AspNetCore.Razor.Language.Intermediate;
using Roslyn.Test.Utilities;
using Xunit;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@

#nullable disable

using System;
using System.Collections.Immutable;
using Microsoft.AspNetCore.Razor.Language;
using Microsoft.AspNetCore.Razor.Language.Intermediate;
using Moq;
using Xunit;

namespace Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X;
Expand Down Expand Up @@ -136,8 +133,10 @@ public void Pass_SetsNamespace_ComputedFromImports()

var codeDocument = RazorCodeDocument.Create(RazorSourceDocument.Create("ignored", "/Account/Manage/AddUser.cshtml"));

var pass = new NamespaceDirective.Pass();
pass.Engine = new RazorEngine(ImmutableArray<IRazorEngineFeature>.Empty, ImmutableArray<IRazorEnginePhase>.Empty);
var pass = new NamespaceDirective.Pass()
{
Engine = new RazorEngine(features: [], phases: [])
};

// Act
pass.Execute(codeDocument, document);
Expand Down Expand Up @@ -183,8 +182,10 @@ public void Pass_SetsNamespace_ComputedFromSource()

var codeDocument = RazorCodeDocument.Create(RazorSourceDocument.Create("ignored", "/Account/Manage/AddUser.cshtml"));

var pass = new NamespaceDirective.Pass();
pass.Engine = new RazorEngine(ImmutableArray<IRazorEngineFeature>.Empty, ImmutableArray<IRazorEnginePhase>.Empty);
var pass = new NamespaceDirective.Pass()
{
Engine = new RazorEngine(features: [], phases: [])
};

// Act
pass.Execute(codeDocument, document);
Expand Down Expand Up @@ -221,8 +222,10 @@ public void Pass_SetsNamespace_SanitizesClassAndNamespace()

var codeDocument = RazorCodeDocument.Create(RazorSourceDocument.Create("ignored", "/Account/Manage-Info/Add+User.cshtml"));

var pass = new NamespaceDirective.Pass();
pass.Engine = new RazorEngine(ImmutableArray<IRazorEngineFeature>.Empty, ImmutableArray<IRazorEnginePhase>.Empty);
var pass = new NamespaceDirective.Pass()
{
Engine = new RazorEngine(features: [], phases: [])
};

// Act
pass.Execute(codeDocument, document);
Expand Down Expand Up @@ -268,8 +271,10 @@ public void Pass_SetsNamespace_ComputedFromSource_ForView()

var codeDocument = RazorCodeDocument.Create(RazorSourceDocument.Create("ignored", "/Account/Manage/AddUser.cshtml"));

var pass = new NamespaceDirective.Pass();
pass.Engine = new RazorEngine(ImmutableArray<IRazorEngineFeature>.Empty, ImmutableArray<IRazorEnginePhase>.Empty);
var pass = new NamespaceDirective.Pass()
{
Engine = new RazorEngine(features: [], phases: [])
};

// Act
pass.Execute(codeDocument, document);
Expand Down Expand Up @@ -306,8 +311,10 @@ public void Pass_SetsNamespace_VerbatimFromImports()

var codeDocument = RazorCodeDocument.Create(RazorSourceDocument.Create("ignored", "/Account/Manage/AddUser.cshtml"));

var pass = new NamespaceDirective.Pass();
pass.Engine = new RazorEngine(ImmutableArray<IRazorEngineFeature>.Empty, ImmutableArray<IRazorEnginePhase>.Empty);
var pass = new NamespaceDirective.Pass()
{
Engine = new RazorEngine(features: [], phases: [])
};

// Act
pass.Execute(codeDocument, document);
Expand Down Expand Up @@ -342,8 +349,10 @@ public void Pass_DoesNothing_ForUnknownDocumentKind()

var codeDocument = RazorCodeDocument.Create(RazorSourceDocument.Create("ignored", "/Account/Manage/AddUser.cshtml"));

var pass = new NamespaceDirective.Pass();
pass.Engine = new RazorEngine(ImmutableArray<IRazorEngineFeature>.Empty, ImmutableArray<IRazorEnginePhase>.Empty);
var pass = new NamespaceDirective.Pass()
{
Engine = new RazorEngine(features: [], phases: [])
};

// Act
pass.Execute(codeDocument, document);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ private static DocumentIntermediateNode CreateIRDocument(RazorProjectEngine proj
// We also expect the default tag helper pass to run first.
var documentNode = codeDocument.GetDocumentIntermediateNode();

var defaultTagHelperPass = projectEngine.EngineFeatures.OfType<DefaultTagHelperOptimizationPass>().Single();
var defaultTagHelperPass = projectEngine.Engine.GetFeatures<DefaultTagHelperOptimizationPass>().Single();
defaultTagHelperPass.Execute(codeDocument, documentNode);

return codeDocument.GetDocumentIntermediateNode();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#nullable disable

using Microsoft.AspNetCore.Razor.Language;
using Microsoft.AspNetCore.Razor.Language.Extensions;
using Microsoft.AspNetCore.Razor.Language.Intermediate;
using Roslyn.Test.Utilities;
using Xunit;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ public override void VisitNamespaceDeclaration(NamespaceDeclarationIntermediateN
}
}

private class DesignTimeOptionsFeature : IConfigureRazorParserOptionsFeature, IConfigureRazorCodeGenerationOptionsFeature
private class DesignTimeOptionsFeature : RazorEngineFeatureBase, IConfigureRazorParserOptionsFeature, IConfigureRazorCodeGenerationOptionsFeature
{
private readonly bool _designTime;

Expand All @@ -345,8 +345,6 @@ public DesignTimeOptionsFeature(bool designTime)

public int Order { get; }

public RazorEngine Engine { get; set; }

public void Configure(RazorParserOptionsBuilder options)
{
options.SetDesignTime(_designTime);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#nullable disable

using Microsoft.AspNetCore.Razor.Language;
using Microsoft.AspNetCore.Razor.Language.Extensions;
using Microsoft.AspNetCore.Razor.Language.Intermediate;
using Roslyn.Test.Utilities;
using Xunit;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ private DocumentIntermediateNode CreateIRDocument(RazorProjectEngine projectEngi
// We also expect the default tag helper pass to run first.
var documentNode = codeDocument.GetDocumentIntermediateNode();

var defaultTagHelperPass = projectEngine.EngineFeatures.OfType<DefaultTagHelperOptimizationPass>().Single();
var defaultTagHelperPass = projectEngine.Engine.GetFeatures<DefaultTagHelperOptimizationPass>().Single();
defaultTagHelperPass.Execute(codeDocument, documentNode);

return codeDocument.GetDocumentIntermediateNode();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,22 @@ public class ComponentDuplicateAttributeDiagnosticPassTest
{
public ComponentDuplicateAttributeDiagnosticPassTest()
{
Pass = new ComponentMarkupDiagnosticPass();
ProjectEngine = RazorProjectEngine.Create(
RazorConfiguration.Default,
RazorProjectFileSystem.Create(Environment.CurrentDirectory),
b =>
{
// Don't run the markup mutating passes.
b.Features.Remove(b.Features.OfType<ComponentMarkupDiagnosticPass>().Single());
// Don't run the markup mutating passes.
b.Features.Remove(b.Features.OfType<ComponentMarkupDiagnosticPass>().Single());
b.Features.Remove(b.Features.OfType<ComponentMarkupBlockPass>().Single());
b.Features.Remove(b.Features.OfType<ComponentMarkupEncodingPass>().Single());
});
Engine = ProjectEngine.Engine;

Pass.Engine = Engine;
Pass = new ComponentMarkupDiagnosticPass()
{
Engine = Engine
};
}

private RazorProjectEngine ProjectEngine { get; }
Expand Down Expand Up @@ -162,7 +164,7 @@ private RazorCodeDocument CreateDocument(string content)
content = content.Replace("\n", "\r\n");

var source = RazorSourceDocument.Create(content, "test.cshtml");
return ProjectEngine.CreateCodeDocumentCore(source, FileKinds.Component);
return ProjectEngine.CreateCodeDocument(source, FileKinds.Component);
}

private DocumentIntermediateNode Lower(RazorCodeDocument codeDocument)
Expand All @@ -178,19 +180,7 @@ private DocumentIntermediateNode Lower(RazorCodeDocument codeDocument)
}

var document = codeDocument.GetDocumentIntermediateNode();
Engine.Features.OfType<ComponentDocumentClassifierPass>().Single().Execute(codeDocument, document);
Engine.GetFeatures<ComponentDocumentClassifierPass>().Single().Execute(codeDocument, document);
return document;
}

private class StaticTagHelperFeature : ITagHelperFeature
{
public RazorEngine Engine { get; set; }

public List<TagHelperDescriptor> TagHelpers { get; set; }

public IReadOnlyList<TagHelperDescriptor> GetDescriptors()
{
return TagHelpers;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ public class ComponentMarkupBlockPassTest
{
public ComponentMarkupBlockPassTest()
{
Pass = new ComponentMarkupBlockPass(RazorLanguageVersion.Latest);
ProjectEngine = RazorProjectEngine.Create(
RazorConfiguration.Default,
RazorProjectFileSystem.Create(Environment.CurrentDirectory),
Expand All @@ -29,7 +28,10 @@ public ComponentMarkupBlockPassTest()
});
Engine = ProjectEngine.Engine;

Pass.Engine = Engine;
Pass = new ComponentMarkupBlockPass(RazorLanguageVersion.Latest)
{
Engine = Engine
};
}

private RazorProjectEngine ProjectEngine { get; }
Expand Down Expand Up @@ -450,7 +452,7 @@ private RazorCodeDocument CreateDocument(string content)
content = content.Replace("\n", "\r\n");

var source = RazorSourceDocument.Create(content, "test.cshtml");
return ProjectEngine.CreateCodeDocumentCore(source, FileKinds.Component);
return ProjectEngine.CreateCodeDocument(source, FileKinds.Component);
}

private DocumentIntermediateNode Lower(RazorCodeDocument codeDocument)
Expand All @@ -466,20 +468,8 @@ private DocumentIntermediateNode Lower(RazorCodeDocument codeDocument)
}

var document = codeDocument.GetDocumentIntermediateNode();
Engine.Features.OfType<ComponentDocumentClassifierPass>().Single().Execute(codeDocument, document);
Engine.Features.OfType<ComponentMarkupDiagnosticPass>().Single().Execute(codeDocument, document);
Engine.GetFeatures<ComponentDocumentClassifierPass>().Single().Execute(codeDocument, document);
Engine.GetFeatures<ComponentMarkupDiagnosticPass>().Single().Execute(codeDocument, document);
return document;
}

private class StaticTagHelperFeature : ITagHelperFeature
{
public RazorEngine Engine { get; set; }

public List<TagHelperDescriptor> TagHelpers { get; set; }

public IReadOnlyList<TagHelperDescriptor> GetDescriptors()
{
return TagHelpers;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ public ComponentMarkupEncodingPassTest()
});
Engine = ProjectEngine.Engine;

Pass.Engine = Engine;
Pass = new ComponentMarkupEncodingPass(RazorLanguageVersion.Latest)
{
Engine = Engine
};
}

private RazorProjectEngine ProjectEngine { get; }
Expand Down Expand Up @@ -188,7 +191,7 @@ private RazorCodeDocument CreateDocument(string content)
content = content.Replace("\n", "\r\n");

var source = RazorSourceDocument.Create(content, "test.cshtml");
return ProjectEngine.CreateCodeDocumentCore(source, FileKinds.Component);
return ProjectEngine.CreateCodeDocument(source, FileKinds.Component);
}

private DocumentIntermediateNode Lower(RazorCodeDocument codeDocument)
Expand All @@ -204,7 +207,7 @@ private DocumentIntermediateNode Lower(RazorCodeDocument codeDocument)
}

var document = codeDocument.GetDocumentIntermediateNode();
Engine.Features.OfType<ComponentDocumentClassifierPass>().Single().Execute(codeDocument, document);
Engine.GetFeatures<ComponentDocumentClassifierPass>().Single().Execute(codeDocument, document);
return document;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ public class ComponentWhitespacePassTest
{
public ComponentWhitespacePassTest()
{
Pass = new ComponentWhitespacePass();
ProjectEngine = RazorProjectEngine.Create(
RazorConfiguration.Default,
RazorProjectFileSystem.Create(Environment.CurrentDirectory),
Expand All @@ -28,7 +27,10 @@ public ComponentWhitespacePassTest()
});
Engine = ProjectEngine.Engine;

Pass.Engine = Engine;
Pass = new ComponentWhitespacePass()
{
Engine = Engine
};
}

private RazorProjectEngine ProjectEngine { get; }
Expand Down Expand Up @@ -152,7 +154,7 @@ public void Execute_RemovesWhitespacePrecedingAndTrailingCSharpCode()
private RazorCodeDocument CreateDocument(string content)
{
var source = RazorSourceDocument.Create(content, "test.cshtml");
return ProjectEngine.CreateCodeDocumentCore(source, FileKinds.Component);
return ProjectEngine.CreateCodeDocument(source, FileKinds.Component);
}

private DocumentIntermediateNode Lower(RazorCodeDocument codeDocument)
Expand Down
Loading