Skip to content
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
d649d7e
Consolidate roslyn versions
333fred Jan 10, 2023
5eb2f3d
Filter out compiler-generated types such as RefSafetyRulesAttribute a…
333fred Jan 10, 2023
a0cd9db
Merge branch 'main' into ea-razor-compiler
jjonescz Feb 8, 2023
b9c8df3
Update Roslyn to 4.5.0-2.23107.1
jjonescz Feb 8, 2023
425d1ed
Add reference to `ExternalAccess.RazorCompiler`
jjonescz Feb 8, 2023
918a9eb
Emit design-time outputs from the source generator
jjonescz Feb 8, 2023
5d72464
Emit host outputs from the source generator
jjonescz Feb 8, 2023
f9a8bb7
Test host outputs
jjonescz Feb 8, 2023
200f6db
Generate both design-time and runtime outputs
jjonescz Feb 9, 2023
2593acb
Switch to implementation output
jjonescz Feb 9, 2023
150c1ea
Merge branch 'main' into emit-host-outputs
jjonescz Feb 10, 2023
d7484e6
Remove `general-testing` feed
jjonescz Feb 10, 2023
acc14c4
Update Roslyn to 4.6.0-2.23110.2
jjonescz Feb 10, 2023
b822809
Update Roslyn to 4.6.0-2.23113.3
jjonescz Feb 14, 2023
60f0e5b
Merge branch 'main' into emit-host-outputs
jjonescz Feb 16, 2023
c5b7faa
Merge branch 'main' into emit-host-outputs
jjonescz Mar 23, 2023
0001918
Remove blank line
jjonescz Mar 23, 2023
c53b35d
Merge branch 'main' into emit-host-outputs
jjonescz Mar 29, 2023
df634ab
Re-do changes of this PR onto main
jjonescz Mar 29, 2023
abb981b
Merge branch 'main' into emit-host-outputs
jjonescz Apr 14, 2023
e21f462
Merge branch 'main' into emit-host-outputs
jjonescz Apr 26, 2023
e3bfb62
Update Roslyn to 4.7.0-2.23227.6
jjonescz Apr 28, 2023
2e3673a
Skip host outputs unless opted-in
jjonescz May 3, 2023
b59c580
Merge branch 'main' into emit-host-outputs
jjonescz May 3, 2023
87cab98
Update Roslyn to 4.7.0-2.23253.2
jjonescz May 3, 2023
8363757
Merge branch 'main' into emit-host-outputs
jjonescz Jun 7, 2023
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
3 changes: 0 additions & 3 deletions NuGet.config
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@
-->
<packageSourceMapping>
<clear />
<packageSource key="general-testing">
<package pattern="microsoft.commonlanguageserverProtocol.*" />
</packageSource>
<packageSource key="dotnet-core-internal-tooling">
<package pattern="microsoft.*" />
</packageSource>
Expand Down
3 changes: 2 additions & 1 deletion eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
<Tooling_MicrosoftCodeAnalysisTestingVersion>1.1.2-beta1.22512.1</Tooling_MicrosoftCodeAnalysisTestingVersion>
<MicrosoftVisualStudioShellPackagesVersion>17.5.0-preview-2-33117-317</MicrosoftVisualStudioShellPackagesVersion>
<MicrosoftVisualStudioPackagesVersion>17.5.274-preview</MicrosoftVisualStudioPackagesVersion>
<RoslynPackageVersion>4.6.0-1.23101.17</RoslynPackageVersion>
<RoslynPackageVersion>4.6.0-2.23113.3</RoslynPackageVersion>
<VisualStudioLanguageServerProtocolVersion>17.6.4-preview</VisualStudioLanguageServerProtocolVersion>
<MicrosoftNetCompilersToolsetVersion>4.4.0</MicrosoftNetCompilersToolsetVersion>
<MicrosoftCommonLanguageServerProtocolFrameworkPackageVersion>$(RoslynPackageVersion)</MicrosoftCommonLanguageServerProtocolFrameworkPackageVersion>
Expand Down Expand Up @@ -138,6 +138,7 @@
<Tooling_MicrosoftCodeAnalysisAnalyzersPackageVersion>3.3.4</Tooling_MicrosoftCodeAnalysisAnalyzersPackageVersion>
<Tooling_MicrosoftCodeAnalysisNetAnalyzersPackageVersion>7.0.0-preview1.22116.1</Tooling_MicrosoftCodeAnalysisNetAnalyzersPackageVersion>
<MicrosoftCodeAnalysisExternalAccessRazorPackageVersion>$(RoslynPackageVersion)</MicrosoftCodeAnalysisExternalAccessRazorPackageVersion>
<MicrosoftCodeAnalysisExternalAccessRazorCompilerPackageVersion>$(RoslynPackageVersion)</MicrosoftCodeAnalysisExternalAccessRazorCompilerPackageVersion>
<MicrosoftCodeAnalysisExternalAccessOmniSharpCSharpPackageVersion>$(RoslynPackageVersion)</MicrosoftCodeAnalysisExternalAccessOmniSharpCSharpPackageVersion>
<MicrosoftCodeAnalysisCommonPackageVersion>$(RoslynPackageVersion)</MicrosoftCodeAnalysisCommonPackageVersion>
<MicrosoftCodeAnalysisCSharpPackageVersion>$(RoslynPackageVersion)</MicrosoftCodeAnalysisCSharpPackageVersion>
Expand Down
1 change: 1 addition & 0 deletions src/Compiler/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<PackageVersion Include="Microsoft.CodeAnalysis.Common" Version="$(MicrosoftCodeAnalysisCommonPackageVersion)" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="$(MicrosoftCodeAnalysisCSharpPackageVersion)" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="$(MicrosoftCodeAnalysisCSharpWorkspacesPackageVersion)" />
<PackageVersion Include="Microsoft.CodeAnalysis.ExternalAccess.RazorCompiler" Version="$(MicrosoftCodeAnalysisExternalAccessRazorCompilerPackageVersion)" />
<PackageVersion Include="Microsoft.CodeAnalysis.Workspaces.MSBuild" Version="$(MicrosoftCodeAnalysisWorkspacesMSBuildPackageVersion)" />
<PackageVersion Include="Microsoft.CSharp" Version="$(MicrosoftCSharpVersion)" />
<PackageVersion Include="Microsoft.Css.Parser" Version="$(MicrosoftCssParserVersion)" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" />
<PackageReference Include="Microsoft.CodeAnalysis.ExternalAccess.RazorCompiler" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ internal sealed class RazorSourceGenerationOptions : IEquatable<RazorSourceGener
public LanguageVersion CSharpLanguageVersion { get; set; } = LanguageVersion.CSharp10;

/// <summary>
/// Gets a flag that determines if localized component names should be supported.</c>.
/// Gets a flag that determines if localized component names should be supported.
/// </summary>
public bool SupportLocalizedComponentNames { get; set; } = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Microsoft.AspNetCore.Razor.Language;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.ExternalAccess.RazorCompiler;

namespace Microsoft.NET.Sdk.Razor.SourceGenerators
{
Expand All @@ -24,11 +25,11 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
var compilation = context.CompilationProvider;

// determine if we should suppress this run and filter out all the additional files if so
var isGeneratorSuppressed = context.AnalyzerConfigOptionsProvider.Select(GetSuppressionStatus);
var isGeneratorSuppressed = analyzerConfigOptions.Select(GetSuppressionStatus);
var additionalTexts = context.AdditionalTextsProvider
.Combine(isGeneratorSuppressed)
.Where(pair => !pair.Right)
.Select((pair, _) => pair.Left);
.Combine(isGeneratorSuppressed)
.Where(pair => !pair.Right)
.Select((pair, _) => pair.Left);

var razorSourceGeneratorOptions = analyzerConfigOptions
.Combine(parseOptions)
Expand Down Expand Up @@ -68,7 +69,6 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
.Combine(razorSourceGeneratorOptions)
.Select(static (pair, _) =>
{

var ((sourceItem, importFiles), razorSourceGeneratorOptions) = pair;
RazorSourceGeneratorEventSource.Log.GenerateDeclarationCodeStart(sourceItem.FilePath);

Expand Down Expand Up @@ -204,25 +204,38 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
return allTagHelpers;
});

var generatedOutput = sourceItems

IncrementalValuesProvider<(string hintName, RazorCodeDocument codeDocument)> codeDocuments(bool designTime) => sourceItems
.Combine(importFiles.Collect())
.Combine(allTagHelpers)
.Combine(razorSourceGeneratorOptions)
.Select(static (pair, _) =>
.Select((pair, _) =>
{
var (((sourceItem, imports), allTagHelpers), razorSourceGeneratorOptions) = pair;

RazorSourceGeneratorEventSource.Log.RazorCodeGenerateStart(sourceItem.FilePath);
var kind = designTime ? "DesignTime" : "Runtime";
RazorSourceGeneratorEventSource.Log.RazorCodeGenerateStart(sourceItem.FilePath, kind);

// Add a generated suffix so tools, such as coverlet, consider the file to be generated
var hintName = GetIdentifierFromPath(sourceItem.RelativePhysicalPath) + ".g.cs";

var projectEngine = GetGenerationProjectEngine(allTagHelpers, sourceItem, imports, razorSourceGeneratorOptions);

var codeDocument = projectEngine.Process(sourceItem);
var codeDocument = designTime
? projectEngine.ProcessDesignTime(sourceItem)
: projectEngine.Process(sourceItem);

RazorSourceGeneratorEventSource.Log.RazorCodeGenerateStop(sourceItem.FilePath, kind);
return (hintName, codeDocument);
});

var csharpDocuments = codeDocuments(designTime: false)
.Select(static (tuple, _) =>
{
var (hintName, codeDocument) = tuple;

var csharpDocument = codeDocument.GetCSharpDocument();

RazorSourceGeneratorEventSource.Log.RazorCodeGenerateStop(sourceItem.FilePath);
return (hintName, csharpDocument);
})
.WithLambdaComparer(static (a, b) =>
Expand All @@ -236,7 +249,7 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
return string.Equals(a.csharpDocument.GeneratedCode, b.csharpDocument.GeneratedCode, StringComparison.Ordinal);
}, static a => StringComparer.Ordinal.GetHashCode(a.csharpDocument));

context.RegisterSourceOutput(generatedOutput, static (context, pair) =>
context.RegisterImplementationSourceOutput(csharpDocuments, static (context, pair) =>
{
var (hintName, csharpDocument) = pair;
RazorSourceGeneratorEventSource.Log.AddSyntaxTrees(hintName);
Expand All @@ -249,6 +262,14 @@ public void Initialize(IncrementalGeneratorInitializationContext context)

context.AddSource(hintName, csharpDocument.GeneratedCode);
});

var hostOutput = codeDocuments(designTime: true);
context.RegisterHostOutput(hostOutput, static (context, tuple, _) =>
{
var (hintName, codeDocument) = tuple;
context.AddOutput(hintName + ".rsg-cs", codeDocument.GetCSharpDocument().GeneratedCode);
context.AddOutput(hintName + ".rsg-html", codeDocument.GetHtmlDocument().GeneratedCode);
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ private RazorSourceGeneratorEventSource() { }

private const int RazorCodeGenerateStartId = 10;
[Event(RazorCodeGenerateStartId, Level = EventLevel.Informational)]
public void RazorCodeGenerateStart(string file) => WriteEvent(RazorCodeGenerateStartId, file);
public void RazorCodeGenerateStart(string file, string kind) => WriteEvent(RazorCodeGenerateStartId, file, kind);

private const int RazorCodeGenerateStopId = 11;
[Event(RazorCodeGenerateStopId, Level = EventLevel.Informational)]
public void RazorCodeGenerateStop(string file) => WriteEvent(RazorCodeGenerateStopId, file);
public void RazorCodeGenerateStop(string file, string kind) => WriteEvent(RazorCodeGenerateStopId, file, kind);

private const int AddSyntaxTreesId = 12;
[Event(AddSyntaxTreesId, Level = EventLevel.Informational)]
Expand Down
Loading