Skip to content
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

Remove ItemCollection from CodeRenderingContext #10764

Merged
merged 24 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
80d1ed3
Merge CodeRenderingContext and DefaultCodeRenderingContext
DustinCampbell Aug 9, 2024
0e1774a
Clean up CodeRenderingContext a bit
DustinCampbell Aug 9, 2024
86e05ee
Pool scope stack in CodeRenderingContext
DustinCampbell Aug 9, 2024
635695f
Pool line pragmas in CodeRenderingContext
DustinCampbell Aug 9, 2024
7ba4179
Pool ancestor stack in CodeRenderingContext
DustinCampbell Aug 9, 2024
25acc07
Merge RazorCSharpDocument and DefaultRazorCSharpDocument
DustinCampbell Aug 9, 2024
d00b1ff
Switch CodeRenderingContext.LinePragmas to an ImmutableArray
DustinCampbell Aug 9, 2024
89204d4
Clean up callers of RazorCSharpDocument.Create(...)
DustinCampbell Aug 9, 2024
c755804
Swap RazorCSharpDocument.Create methods for constructors
DustinCampbell Aug 9, 2024
ff63a4e
Use pooled ImmutableArray builder for CodeRenderingContext diagnostics
DustinCampbell Aug 9, 2024
90f90ef
Switch RazorCSharpDocument.Diagnostics to an ImmutableArray
DustinCampbell Aug 9, 2024
5072db4
Clean up pooled objects in CodeRenderingContext
DustinCampbell Aug 9, 2024
34507da
Avoid extra allocations in IntermediateNodeExtensions.GetAllDiagnostics
DustinCampbell Aug 10, 2024
7ac711b
Remove ItemCollection from CodeRenderingContext
DustinCampbell Aug 12, 2024
03e2d07
Merge RazorCodeGenerationOptionsBuilder and DefaultRazorCodeGeneratio…
DustinCampbell Aug 14, 2024
972691b
Merge RazorCodeGenerationOptions and DefaultRazorCodeGenerationOptions
DustinCampbell Aug 14, 2024
dd11c5e
Clean up RazorCodeGenerationOptions a bit
DustinCampbell Aug 14, 2024
96adc42
Collapse RazorCodeGenerationOptions boolean fields to a flags enum
DustinCampbell Aug 14, 2024
28bfd61
Use SuppressUniqueIds exclusively from RazorCodeGenerationOptions
DustinCampbell Aug 14, 2024
1eb601c
Push NewLine setting into RazorCodeGenerationOptions
DustinCampbell Aug 14, 2024
7a9f32e
Pass RazorSourceDocument into CodeRenderingContext rather than RazorC…
DustinCampbell Aug 14, 2024
6593264
Clean up and enable nullability for CodeRenderingContext and DefaultD…
DustinCampbell Aug 14, 2024
b58f180
Fix goofy whitespace
DustinCampbell Aug 20, 2024
934fea8
Add comments explaining the aggressive inlining behavior of EnumExten…
DustinCampbell Aug 20, 2024
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 @@ -66,7 +66,7 @@ public class MyService<TModel>
AssertSourceMappingsMatchBaseline(compiled.CodeDocument);

// We expect this test to generate a bunch of errors.
Assert.True(compiled.CodeDocument.GetCSharpDocument().Diagnostics.Count > 0);
Assert.NotEmpty(compiled.CodeDocument.GetCSharpDocument().Diagnostics);
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public void Execute_NoOps_IfNamespaceNodeIsMissing()
// Arrange
var irDocument = new DocumentIntermediateNode()
{
Options = RazorCodeGenerationOptions.CreateDefault(),
Options = RazorCodeGenerationOptions.Default,
};

var pass = new AssemblyAttributeInjectionPass
Expand All @@ -40,7 +40,7 @@ public void Execute_NoOps_IfNamespaceNodeHasEmptyContent()
// Arrange
var irDocument = new DocumentIntermediateNode()
{
Options = RazorCodeGenerationOptions.CreateDefault(),
Options = RazorCodeGenerationOptions.Default,
};
var builder = IntermediateNodeBuilder.Create(irDocument);
var @namespace = new NamespaceDeclarationIntermediateNode() { Content = string.Empty };
Expand All @@ -66,7 +66,7 @@ public void Execute_NoOps_IfClassNameNodeIsMissing()
// Arrange
var irDocument = new DocumentIntermediateNode()
{
Options = RazorCodeGenerationOptions.CreateDefault(),
Options = RazorCodeGenerationOptions.Default,
};

var builder = IntermediateNodeBuilder.Create(irDocument);
Expand All @@ -93,7 +93,7 @@ public void Execute_NoOps_IfClassNameIsEmpty()
// Arrange
var irDocument = new DocumentIntermediateNode()
{
Options = RazorCodeGenerationOptions.CreateDefault(),
Options = RazorCodeGenerationOptions.Default,
};
var builder = IntermediateNodeBuilder.Create(irDocument);
var @namespace = new NamespaceDeclarationIntermediateNode
Expand Down Expand Up @@ -134,7 +134,7 @@ public void Execute_NoOps_IfDocumentIsNotViewOrPage()
var irDocument = new DocumentIntermediateNode
{
DocumentKind = "Default",
Options = RazorCodeGenerationOptions.CreateDefault(),
Options = RazorCodeGenerationOptions.Default,
};
var builder = IntermediateNodeBuilder.Create(irDocument);
var @namespace = new NamespaceDeclarationIntermediateNode() { Content = "SomeNamespace" };
Expand Down Expand Up @@ -170,7 +170,7 @@ public void Execute_NoOps_ForDesignTime()
var irDocument = new DocumentIntermediateNode
{
DocumentKind = MvcViewDocumentClassifierPass.MvcViewDocumentKind,
Options = RazorCodeGenerationOptions.CreateDesignTimeDefault(),
Options = RazorCodeGenerationOptions.DesignTimeDefault,
};
var builder = IntermediateNodeBuilder.Create(irDocument);
var @namespace = new NamespaceDeclarationIntermediateNode
Expand Down Expand Up @@ -217,7 +217,7 @@ public void Execute_AddsRazorViewAttribute_ToViews()
var irDocument = new DocumentIntermediateNode
{
DocumentKind = MvcViewDocumentClassifierPass.MvcViewDocumentKind,
Options = RazorCodeGenerationOptions.CreateDefault(),
Options = RazorCodeGenerationOptions.Default,
};
var builder = IntermediateNodeBuilder.Create(irDocument);
var @namespace = new NamespaceDeclarationIntermediateNode
Expand Down Expand Up @@ -270,7 +270,7 @@ public void Execute_EscapesViewPathWhenAddingAttributeToViews()
var irDocument = new DocumentIntermediateNode
{
DocumentKind = MvcViewDocumentClassifierPass.MvcViewDocumentKind,
Options = RazorCodeGenerationOptions.CreateDefault(),
Options = RazorCodeGenerationOptions.Default,
};
var builder = IntermediateNodeBuilder.Create(irDocument);
var @namespace = new NamespaceDeclarationIntermediateNode
Expand Down Expand Up @@ -323,7 +323,7 @@ public void Execute_AddsRazorPagettribute_ToPage()
var irDocument = new DocumentIntermediateNode
{
DocumentKind = RazorPageDocumentClassifierPass.RazorPageDocumentKind,
Options = RazorCodeGenerationOptions.CreateDefault(),
Options = RazorCodeGenerationOptions.Default,
};
var builder = IntermediateNodeBuilder.Create(irDocument);
var pageDirective = new DirectiveIntermediateNode
Expand Down Expand Up @@ -383,7 +383,7 @@ public void Execute_EscapesViewPathAndRouteWhenAddingAttributeToPage()
var irDocument = new DocumentIntermediateNode
{
DocumentKind = MvcViewDocumentClassifierPass.MvcViewDocumentKind,
Options = RazorCodeGenerationOptions.CreateDefault(),
Options = RazorCodeGenerationOptions.Default,
};
var builder = IntermediateNodeBuilder.Create(irDocument);
var @namespace = new NamespaceDeclarationIntermediateNode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public void InstrumentationPass_NoOps_ForDesignTime()
// Arrange
var document = new DocumentIntermediateNode()
{
Options = RazorCodeGenerationOptions.CreateDesignTimeDefault(),
Options = RazorCodeGenerationOptions.DesignTimeDefault,
};

var builder = IntermediateNodeBuilder.Create(document);
Expand Down Expand Up @@ -50,7 +50,7 @@ public void InstrumentationPass_InstrumentsHtml()
// Arrange
var document = new DocumentIntermediateNode()
{
Options = RazorCodeGenerationOptions.CreateDefault(),
Options = RazorCodeGenerationOptions.Default,
};

var builder = IntermediateNodeBuilder.Create(document);
Expand Down Expand Up @@ -89,7 +89,7 @@ public void InstrumentationPass_SkipsHtml_WithoutLocation()
// Arrange
var document = new DocumentIntermediateNode()
{
Options = RazorCodeGenerationOptions.CreateDefault(),
Options = RazorCodeGenerationOptions.Default,
};

var builder = IntermediateNodeBuilder.Create(document);
Expand Down Expand Up @@ -121,7 +121,7 @@ public void InstrumentationPass_InstrumentsCSharpExpression()
// Arrange
var document = new DocumentIntermediateNode()
{
Options = RazorCodeGenerationOptions.CreateDefault(),
Options = RazorCodeGenerationOptions.Default,
};

var builder = IntermediateNodeBuilder.Create(document);
Expand Down Expand Up @@ -157,7 +157,7 @@ public void InstrumentationPass_SkipsCSharpExpression_WithoutLocation()
// Arrange
var document = new DocumentIntermediateNode()
{
Options = RazorCodeGenerationOptions.CreateDefault(),
Options = RazorCodeGenerationOptions.Default,
};

var builder = IntermediateNodeBuilder.Create(document);
Expand Down Expand Up @@ -188,7 +188,7 @@ public void InstrumentationPass_SkipsCSharpExpression_InsideTagHelperAttribute()
// Arrange
var document = new DocumentIntermediateNode()
{
Options = RazorCodeGenerationOptions.CreateDefault(),
Options = RazorCodeGenerationOptions.Default,
};

var builder = IntermediateNodeBuilder.Create(document);
Expand Down Expand Up @@ -239,7 +239,7 @@ public void InstrumentationPass_SkipsCSharpExpression_InsideTagHelperProperty()
// Arrange
var document = new DocumentIntermediateNode()
{
Options = RazorCodeGenerationOptions.CreateDefault(),
Options = RazorCodeGenerationOptions.Default,
};

var builder = IntermediateNodeBuilder.Create(document);
Expand Down Expand Up @@ -290,7 +290,7 @@ public void InstrumentationPass_InstrumentsTagHelper()
// Arrange
var document = new DocumentIntermediateNode()
{
Options = RazorCodeGenerationOptions.CreateDefault(),
Options = RazorCodeGenerationOptions.Default,
};

var builder = IntermediateNodeBuilder.Create(document);
Expand Down Expand Up @@ -321,7 +321,7 @@ public void InstrumentationPass_SkipsTagHelper_WithoutLocation()
// Arrange
var document = new DocumentIntermediateNode()
{
Options = RazorCodeGenerationOptions.CreateDefault(),
Options = RazorCodeGenerationOptions.Default,
};

var builder = IntermediateNodeBuilder.Create(document);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public class MyService<TModel>
AssertCSharpDocumentMatchesBaseline(compiled.CodeDocument.GetCSharpDocument());

// We expect this test to generate a bunch of errors.
Assert.True(compiled.CodeDocument.GetCSharpDocument().Diagnostics.Count > 0);
Assert.NotEmpty(compiled.CodeDocument.GetCSharpDocument().Diagnostics);
}

[Fact]
Expand Down Expand Up @@ -536,7 +536,7 @@ public class MyService<TModel>
AssertSourceMappingsMatchBaseline(compiled.CodeDocument);

// We expect this test to generate a bunch of errors.
Assert.True(compiled.CodeDocument.GetCSharpDocument().Diagnostics.Count > 0);
Assert.NotEmpty(compiled.CodeDocument.GetCSharpDocument().Diagnostics);
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public class MyService<TModel>
AssertLinePragmas(compiled.CodeDocument, designTime: false);

// We expect this test to generate a bunch of errors.
Assert.True(compiled.CodeDocument.GetCSharpDocument().Diagnostics.Count > 0);
Assert.NotEmpty(compiled.CodeDocument.GetCSharpDocument().Diagnostics);
}

[Fact]
Expand Down Expand Up @@ -949,7 +949,7 @@ public class MyService<TModel>
AssertSourceMappingsMatchBaseline(compiled.CodeDocument);

// We expect this test to generate a bunch of errors.
Assert.True(compiled.CodeDocument.GetCSharpDocument().Diagnostics.Count > 0);
Assert.NotEmpty(compiled.CodeDocument.GetCSharpDocument().Diagnostics);
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ public void CSharpCodeWriter_RespectTabSetting()
o.IndentSize = 4;
});

using var writer = new CodeWriter(Environment.NewLine, options);
using var writer = new CodeWriter(options);

// Act
writer.BuildClassDeclaration(Array.Empty<string>(), "C", "", Array.Empty<string>(), Array.Empty<TypeParameter>(), context: null);
Expand All @@ -428,7 +428,7 @@ public void CSharpCodeWriter_RespectSpaceSetting()
o.IndentSize = 4;
});

using var writer = new CodeWriter(Environment.NewLine, options);
using var writer = new CodeWriter(options);

// Act
writer.BuildClassDeclaration(Array.Empty<string>(), "C", "", Array.Empty<string>(), Array.Empty<TypeParameter>(), context: null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public void CreateDefault_CreatesDefaultCodeTarget()
{
// Arrange
var codeDocument = TestRazorCodeDocument.CreateEmpty();
var options = RazorCodeGenerationOptions.CreateDefault();
var options = RazorCodeGenerationOptions.Default;

// Act
var target = CodeTarget.CreateDefault(codeDocument, options);
Expand All @@ -32,7 +32,7 @@ public void CreateDefault_CallsDelegate()
Action<CodeTargetBuilder> @delegate = (b) => { wasCalled = true; };

var codeDocument = TestRazorCodeDocument.CreateEmpty();
var options = RazorCodeGenerationOptions.CreateDefault();
var options = RazorCodeGenerationOptions.Default;

// Act
CodeTarget.CreateDefault(codeDocument, options, @delegate);
Expand All @@ -46,7 +46,7 @@ public void CreateDefault_AllowsNullDelegate()
{
// Arrange
var codeDocument = TestRazorCodeDocument.CreateEmpty();
var options = RazorCodeGenerationOptions.CreateDefault();
var options = RazorCodeGenerationOptions.Default;

// Act
CodeTarget.CreateDefault(codeDocument, options, configure: null);
Expand All @@ -59,7 +59,7 @@ public void CreateEmpty_AllowsNullDelegate()
{
// Arrange
var codeDocument = TestRazorCodeDocument.CreateEmpty();
var options = RazorCodeGenerationOptions.CreateDefault();
var options = RazorCodeGenerationOptions.Default;

// Act
CodeTarget.CreateDefault(codeDocument, options, configure: null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public void Build_CreatesDefaultCodeTarget()
{
// Arrange
var codeDocument = TestRazorCodeDocument.CreateEmpty();
var options = RazorCodeGenerationOptions.CreateDefault();
var options = RazorCodeGenerationOptions.Default;

var builder = new DefaultCodeTargetBuilder(codeDocument, options);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class DefaultCodeTargetTest
public void Constructor_CreatesDefensiveCopy()
{
// Arrange
var options = RazorCodeGenerationOptions.CreateDefault();
var options = RazorCodeGenerationOptions.Default;

var extensions = new ICodeTargetExtension[]
{
Expand All @@ -33,7 +33,7 @@ public void Constructor_CreatesDefensiveCopy()
public void CreateWriter_DesignTime_CreatesDesignTimeNodeWriter()
{
// Arrange
var options = RazorCodeGenerationOptions.CreateDesignTimeDefault();
var options = RazorCodeGenerationOptions.DesignTimeDefault;
var target = new DefaultCodeTarget(options, Enumerable.Empty<ICodeTargetExtension>());

// Act
Expand All @@ -47,7 +47,7 @@ public void CreateWriter_DesignTime_CreatesDesignTimeNodeWriter()
public void CreateWriter_Runtime_CreatesRuntimeNodeWriter()
{
// Arrange
var options = RazorCodeGenerationOptions.CreateDefault();
var options = RazorCodeGenerationOptions.Default;
var target = new DefaultCodeTarget(options, Enumerable.Empty<ICodeTargetExtension>());

// Act
Expand All @@ -61,7 +61,7 @@ public void CreateWriter_Runtime_CreatesRuntimeNodeWriter()
public void HasExtension_ReturnsTrue_WhenExtensionFound()
{
// Arrange
var options = RazorCodeGenerationOptions.CreateDefault();
var options = RazorCodeGenerationOptions.Default;

var extensions = new ICodeTargetExtension[]
{
Expand All @@ -82,7 +82,7 @@ public void HasExtension_ReturnsTrue_WhenExtensionFound()
public void HasExtension_ReturnsFalse_WhenExtensionNotFound()
{
// Arrange
var options = RazorCodeGenerationOptions.CreateDefault();
var options = RazorCodeGenerationOptions.Default;

var extensions = new ICodeTargetExtension[]
{
Expand All @@ -103,7 +103,7 @@ public void HasExtension_ReturnsFalse_WhenExtensionNotFound()
public void GetExtension_ReturnsExtension_WhenExtensionFound()
{
// Arrange
var options = RazorCodeGenerationOptions.CreateDefault();
var options = RazorCodeGenerationOptions.Default;

var extensions = new ICodeTargetExtension[]
{
Expand All @@ -124,7 +124,7 @@ public void GetExtension_ReturnsExtension_WhenExtensionFound()
public void GetExtension_ReturnsFirstMatch_WhenExtensionFound()
{
// Arrange
var options = RazorCodeGenerationOptions.CreateDefault();
var options = RazorCodeGenerationOptions.Default;

var extensions = new ICodeTargetExtension[]
{
Expand All @@ -148,7 +148,7 @@ public void GetExtension_ReturnsFirstMatch_WhenExtensionFound()
public void GetExtension_ReturnsNull_WhenExtensionNotFound()
{
// Arrange
var options = RazorCodeGenerationOptions.CreateDefault();
var options = RazorCodeGenerationOptions.Default;

var extensions = new ICodeTargetExtension[]
{
Expand Down
Loading
Loading