Skip to content

Commit

Permalink
Features/fuse (#10090)
Browse files Browse the repository at this point in the history
Use runtime code generation for the IDE when under feature flag.
  • Loading branch information
chsienki authored Mar 14, 2024
2 parents d6be87e + 6d81a60 commit f5bc8f5
Show file tree
Hide file tree
Showing 942 changed files with 11,124 additions and 4,118 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,28 +48,44 @@ public void InjectDirectiveTargetExtension_WritesPropertyWithLinePragma_WhenSour
{
TypeName = "PropertyType<ModelType>",
MemberName = "PropertyName",
Source = new SourceSpan(
TypeSource = new SourceSpan(
filePath: "test-path",
absoluteIndex: 0,
absoluteIndex: 7,
lineIndex: 1,
characterIndex: 1,
length: 10)
characterIndex: 7,
length: 23),
MemberSource = new SourceSpan(
filePath: "test-path",
absoluteIndex: 31,
lineIndex: 1,
characterIndex: 31,
length: 12)
};

// Act
target.WriteInjectProperty(context, node);

// Assert
Assert.Equal("""
#nullable restore
#line 2 "test-path"
[global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute]
public PropertyType<ModelType> PropertyName { get; private set; }
public
#nullable restore
#line (2,8)-(2,1) "test-path"
PropertyType<ModelType>
#line default
#line hidden
#nullable disable
#nullable restore
#line (2,32)-(2,1) "test-path"
PropertyName
#line default
#line hidden
#nullable disable
{ get; private set; }
= default!;
""",
context.CodeWriter.GenerateCode());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public CodeGenerationIntegrationTest()

protected override RazorConfiguration Configuration { get; }

protected override CSharpParseOptions CSharpParseOptions => base.CSharpParseOptions.WithLanguageVersion(LanguageVersion.CSharp8);
protected override CSharpParseOptions CSharpParseOptions => base.CSharpParseOptions.WithLanguageVersion(LanguageVersion.CSharp10);

[Fact]
public void InvalidNamespaceAtEOF_DesignTime()
Expand All @@ -41,8 +41,8 @@ public void InvalidNamespaceAtEOF_DesignTime()
AssertCSharpDocumentMatchesBaseline(compiled.CodeDocument.GetCSharpDocument());
AssertSourceMappingsMatchBaseline(compiled.CodeDocument);

var diagnotics = compiled.CodeDocument.GetCSharpDocument().Diagnostics;
Assert.Equal("RZ1007", Assert.Single(diagnotics).Id);
var diagnostics = compiled.CodeDocument.GetCSharpDocument().Diagnostics;
Assert.Equal("RZ1007", Assert.Single(diagnostics).Id);
}

[Fact]
Expand Down Expand Up @@ -309,8 +309,8 @@ public class ThisShouldBeGenerated
AssertCSharpDocumentMatchesBaseline(compiled.CodeDocument.GetCSharpDocument());
AssertSourceMappingsMatchBaseline(compiled.CodeDocument);

var diagnotics = compiled.CodeDocument.GetCSharpDocument().Diagnostics;
Assert.Equal("RZ2001", Assert.Single(diagnotics).Id);
var diagnostics = compiled.CodeDocument.GetCSharpDocument().Diagnostics;
Assert.Equal("RZ2001", Assert.Single(diagnostics).Id);
}

[Fact]
Expand Down Expand Up @@ -367,4 +367,92 @@ public class AllTagHelper : {{typeof(TagHelper).FullName}}
AssertCSharpDocumentMatchesBaseline(compiled.CodeDocument.GetCSharpDocument());
AssertSourceMappingsMatchBaseline(compiled.CodeDocument);
}

[Fact]
public void Inject_Runtime()
{
// Arrange
AddCSharpSyntaxTree(@"
public class MyApp
{
public string MyProperty { get; set; }
}
");

var projectItem = CreateProjectItemFromFile();

// Act
var compiled = CompileToAssembly(projectItem, designTime: false);

// Assert
AssertDocumentNodeMatchesBaseline(compiled.CodeDocument.GetDocumentIntermediateNode());
AssertCSharpDocumentMatchesBaseline(compiled.CodeDocument.GetCSharpDocument());
AssertLinePragmas(compiled.CodeDocument, designTime: false);
AssertSourceMappingsMatchBaseline(compiled.CodeDocument);
}

[Fact]
public void InjectWithModel_Runtime()
{
// Arrange
AddCSharpSyntaxTree(@"
public class MyModel
{
}
public class MyService<TModel>
{
public string Html { get; set; }
}
public class MyApp
{
public string MyProperty { get; set; }
}");

var projectItem = CreateProjectItemFromFile();

// Act
var compiled = CompileToAssembly(projectItem, designTime: false);

// Assert
AssertDocumentNodeMatchesBaseline(compiled.CodeDocument.GetDocumentIntermediateNode());
AssertCSharpDocumentMatchesBaseline(compiled.CodeDocument.GetCSharpDocument());
AssertLinePragmas(compiled.CodeDocument, designTime: false);
AssertSourceMappingsMatchBaseline(compiled.CodeDocument);
}

[Fact]
public void InjectWithSemicolon_Runtime()
{
// Arrange
AddCSharpSyntaxTree(@"
public class MyModel
{
}
public class MyApp
{
public string MyProperty { get; set; }
}
public class MyService<TModel>
{
public string Html { get; set; }
}
");

var projectItem = CreateProjectItemFromFile();

// Act
var compiled = CompileToAssembly(projectItem, designTime: false);

// Assert
AssertDocumentNodeMatchesBaseline(compiled.CodeDocument.GetDocumentIntermediateNode());
AssertCSharpDocumentMatchesBaseline(compiled.CodeDocument.GetCSharpDocument());
AssertLinePragmas(compiled.CodeDocument, designTime: false);
AssertSourceMappingsMatchBaseline(compiled.CodeDocument);
}
}
Original file line number Diff line number Diff line change
@@ -1,27 +1,55 @@
#pragma checksum "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithModel.cshtml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "a039b7091118c718dc3023b6ac58d9645cb58e59"
#pragma checksum "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithModel.cshtml" "{8829d00f-11b8-4213-878b-770e8597ac16}" "319d5fa6f848e64d19bf7eab2f5e3339cdfc75b02a9bc6f2773eed1a40f5e9d0"
// <auto-generated/>
#pragma warning disable 1591
[assembly: global::Microsoft.AspNetCore.Razor.Hosting.RazorCompiledItemAttribute(typeof(AspNetCore.TestFiles_IntegrationTests_CodeGenerationIntegrationTest_InjectWithModel), @"mvc.1.0.view", @"/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithModel.cshtml")]
namespace AspNetCore
{
#line hidden
#line default
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.AspNetCore.Mvc.ViewFeatures;
public class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_InjectWithModel_cshtml : global::Microsoft.AspNetCore.Mvc.Razor.RazorPage<MyModel>
#line default
#line hidden
[global::Microsoft.AspNetCore.Razor.Hosting.RazorSourceChecksumAttribute(@"Sha256", @"319d5fa6f848e64d19bf7eab2f5e3339cdfc75b02a9bc6f2773eed1a40f5e9d0", @"/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithModel.cshtml")]
public class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_InjectWithModel : global::Microsoft.AspNetCore.Mvc.Razor.RazorPage<MyModel>
{
#pragma warning disable 1998
public async override global::System.Threading.Tasks.Task ExecuteAsync()
{
}
#pragma warning restore 1998
[global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute]
public MyService<MyModel> Html { get; private set; }
public
#line (3,9)-(3,18) "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithModel.cshtml"
MyService<MyModel>

#line default
#line hidden

#line (3,27)-(3,31) "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithModel.cshtml"
Html

#line default
#line hidden
{ get; private set; }
[global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute]
public MyApp MyPropertyName { get; private set; }
public
#line (2,9)-(2,14) "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithModel.cshtml"
MyApp

#line default
#line hidden

#line (2,15)-(2,29) "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithModel.cshtml"
MyPropertyName

#line default
#line hidden
{ get; private set; }
[global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute]
public global::Microsoft.AspNetCore.Mvc.ViewFeatures.IModelExpressionProvider ModelExpressionProvider { get; private set; }
[global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Document -
RazorCompiledItemAttribute -
NamespaceDeclaration - - AspNetCore
UsingDirective - (1:0,1 [14] ) - System
UsingDirective - (16:1,1 [34] ) - System.Collections.Generic
Expand All @@ -7,7 +8,8 @@
UsingDirective - (102:4,1 [32] ) - Microsoft.AspNetCore.Mvc
UsingDirective - (135:5,1 [42] ) - Microsoft.AspNetCore.Mvc.Rendering
UsingDirective - (178:6,1 [45] ) - Microsoft.AspNetCore.Mvc.ViewFeatures
ClassDeclaration - - public - TestFiles_IntegrationTests_CodeGenerationIntegrationTest_InjectWithModel_cshtml - global::Microsoft.AspNetCore.Mvc.Razor.RazorPage<MyModel> -
RazorSourceChecksumAttribute -
ClassDeclaration - - public - TestFiles_IntegrationTests_CodeGenerationIntegrationTest_InjectWithModel - global::Microsoft.AspNetCore.Mvc.Razor.RazorPage<MyModel> -
MethodDeclaration - - public async override - global::System.Threading.Tasks.Task - ExecuteAsync
Inject -
Inject -
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Source Location: (54:2,8 [9] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithModel.cshtml)
|MyService|
Generated Location: (1651:27,0 [9] )
|MyService|

Source Location: (72:2,26 [4] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithModel.cshtml)
|Html|
Generated Location: (1816:33,0 [4] )
|Html|

Source Location: (24:1,8 [5] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithModel.cshtml)
|MyApp|
Generated Location: (2084:41,0 [5] )
|MyApp|

Source Location: (30:1,14 [14] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithModel.cshtml)
|MyPropertyName|
Generated Location: (2236:47,0 [14] )
|MyPropertyName|

Original file line number Diff line number Diff line change
@@ -1,31 +1,83 @@
#pragma checksum "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithSemicolon.cshtml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "5010aab35d235175dab517f8018e41aee9a2ac7f"
#pragma checksum "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithSemicolon.cshtml" "{8829d00f-11b8-4213-878b-770e8597ac16}" "771acb56660727ab6e4ca50e95bde0cf2a72af8de3e9ec1cd4b72969645cb9af"
// <auto-generated/>
#pragma warning disable 1591
[assembly: global::Microsoft.AspNetCore.Razor.Hosting.RazorCompiledItemAttribute(typeof(AspNetCore.TestFiles_IntegrationTests_CodeGenerationIntegrationTest_InjectWithSemicolon), @"mvc.1.0.view", @"/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithSemicolon.cshtml")]
namespace AspNetCore
{
#line hidden
#line default
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.AspNetCore.Mvc.ViewFeatures;
public class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_InjectWithSemicolon_cshtml : global::Microsoft.AspNetCore.Mvc.Razor.RazorPage<MyModel>
#line default
#line hidden
[global::Microsoft.AspNetCore.Razor.Hosting.RazorSourceChecksumAttribute(@"Sha256", @"771acb56660727ab6e4ca50e95bde0cf2a72af8de3e9ec1cd4b72969645cb9af", @"/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithSemicolon.cshtml")]
public class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_InjectWithSemicolon : global::Microsoft.AspNetCore.Mvc.Razor.RazorPage<MyModel>
{
#pragma warning disable 1998
public async override global::System.Threading.Tasks.Task ExecuteAsync()
{
}
#pragma warning restore 1998
[global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute]
public MyService<MyModel> Html2 { get; private set; }
public
#line (5,9)-(5,18) "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithSemicolon.cshtml"
MyService<MyModel>

#line default
#line hidden

#line (5,27)-(5,32) "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithSemicolon.cshtml"
Html2

#line default
#line hidden
{ get; private set; }
[global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute]
public MyApp MyPropertyName2 { get; private set; }
public
#line (4,9)-(4,14) "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithSemicolon.cshtml"
MyApp

#line default
#line hidden

#line (4,15)-(4,30) "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithSemicolon.cshtml"
MyPropertyName2

#line default
#line hidden
{ get; private set; }
[global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute]
public MyService<MyModel> Html { get; private set; }
public
#line (3,9)-(3,18) "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithSemicolon.cshtml"
MyService<MyModel>

#line default
#line hidden

#line (3,27)-(3,31) "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithSemicolon.cshtml"
Html

#line default
#line hidden
{ get; private set; }
[global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute]
public MyApp MyPropertyName { get; private set; }
public
#line (2,9)-(2,14) "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithSemicolon.cshtml"
MyApp

#line default
#line hidden

#line (2,15)-(2,29) "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithSemicolon.cshtml"
MyPropertyName

#line default
#line hidden
{ get; private set; }
[global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute]
public global::Microsoft.AspNetCore.Mvc.ViewFeatures.IModelExpressionProvider ModelExpressionProvider { get; private set; }
[global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Document -
RazorCompiledItemAttribute -
NamespaceDeclaration - - AspNetCore
UsingDirective - (1:0,1 [14] ) - System
UsingDirective - (16:1,1 [34] ) - System.Collections.Generic
Expand All @@ -7,7 +8,8 @@
UsingDirective - (102:4,1 [32] ) - Microsoft.AspNetCore.Mvc
UsingDirective - (135:5,1 [42] ) - Microsoft.AspNetCore.Mvc.Rendering
UsingDirective - (178:6,1 [45] ) - Microsoft.AspNetCore.Mvc.ViewFeatures
ClassDeclaration - - public - TestFiles_IntegrationTests_CodeGenerationIntegrationTest_InjectWithSemicolon_cshtml - global::Microsoft.AspNetCore.Mvc.Razor.RazorPage<MyModel> -
RazorSourceChecksumAttribute -
ClassDeclaration - - public - TestFiles_IntegrationTests_CodeGenerationIntegrationTest_InjectWithSemicolon - global::Microsoft.AspNetCore.Mvc.Razor.RazorPage<MyModel> -
MethodDeclaration - - public async override - global::System.Threading.Tasks.Task - ExecuteAsync
Inject -
Inject -
Expand Down
Loading

0 comments on commit f5bc8f5

Please sign in to comment.