-
Couldn't load subscription status.
- Fork 214
Calculate SuppressAddComponentParameter in tooling #10763
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
Changes from all commits
c92386f
45334b8
7fc2352
6794130
e685ca5
5cca44c
017a513
c77bce3
a3bab60
cc8f604
d3647a9
eca23cb
1f23c67
353e217
dcc4fe8
3d2f246
b108d41
4750b83
66c1790
73cfa13
41f69f9
4cf5339
4347cc3
1e2b4b0
5681389
b28e503
15e1635
72d5e84
2205c2e
4117df5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
|
|
||
| namespace Microsoft.CodeAnalysis.Razor.Compiler.CSharp; | ||
|
|
||
| internal static class CompilationExtensions | ||
| { | ||
| public static bool HasAddComponentParameter(this Compilation compilation) | ||
| { | ||
| return compilation.GetTypesByMetadataName("Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder") | ||
| .Any(static t => | ||
| t.DeclaredAccessibility == Accessibility.Public && | ||
| t.GetMembers("AddComponentParameter") | ||
| .Any(static m => m.DeclaredAccessibility == Accessibility.Public)); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -2,21 +2,24 @@ | |||||||||||||||||||||||||||||||||||||||||
| // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| using System; | ||||||||||||||||||||||||||||||||||||||||||
| using System.Collections.Immutable; | ||||||||||||||||||||||||||||||||||||||||||
| using System.IO; | ||||||||||||||||||||||||||||||||||||||||||
| using System.Linq; | ||||||||||||||||||||||||||||||||||||||||||
| using System.Text; | ||||||||||||||||||||||||||||||||||||||||||
| using System.Threading; | ||||||||||||||||||||||||||||||||||||||||||
| using Microsoft.AspNetCore.Razor.Language; | ||||||||||||||||||||||||||||||||||||||||||
| using Microsoft.CodeAnalysis; | ||||||||||||||||||||||||||||||||||||||||||
| using Microsoft.CodeAnalysis.CSharp; | ||||||||||||||||||||||||||||||||||||||||||
| using Microsoft.CodeAnalysis.Diagnostics; | ||||||||||||||||||||||||||||||||||||||||||
| using Microsoft.CodeAnalysis.Razor.Compiler.CSharp; | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| namespace Microsoft.NET.Sdk.Razor.SourceGenerators | ||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||
| public partial class RazorSourceGenerator | ||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||
| private (RazorSourceGenerationOptions?, Diagnostic?) ComputeRazorSourceGeneratorOptions(((AnalyzerConfigOptionsProvider, ParseOptions), bool) pair, CancellationToken ct) | ||||||||||||||||||||||||||||||||||||||||||
| private (RazorSourceGenerationOptions?, Diagnostic?) ComputeRazorSourceGeneratorOptions((((AnalyzerConfigOptionsProvider, ParseOptions), ImmutableArray<MetadataReference>), bool) pair, CancellationToken ct) | ||||||||||||||||||||||||||||||||||||||||||
ryzngard marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||
| var ((options, parseOptions), isSuppressed) = pair; | ||||||||||||||||||||||||||||||||||||||||||
| var (((options, parseOptions), references), isSuppressed) = pair; | ||||||||||||||||||||||||||||||||||||||||||
| var globalOptions = options.GlobalOptions; | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| if (isSuppressed) | ||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -42,7 +45,15 @@ public partial class RazorSourceGenerator | |||||||||||||||||||||||||||||||||||||||||
| razorLanguageVersion = RazorLanguageVersion.Latest; | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| var razorConfiguration = new RazorConfiguration(razorLanguageVersion, configurationName ?? "default", Extensions: [], UseConsolidatedMvcViews: true); | ||||||||||||||||||||||||||||||||||||||||||
| var minimalReferences = references | ||||||||||||||||||||||||||||||||||||||||||
| .Where(r => r.Display is { } display && display.EndsWith("Microsoft.AspNetCore.Components.dll", StringComparison.Ordinal)) | ||||||||||||||||||||||||||||||||||||||||||
| .ToImmutableArray(); | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| var isComponentParameterSupported = minimalReferences.Length == 0 | ||||||||||||||||||||||||||||||||||||||||||
| ? false | ||||||||||||||||||||||||||||||||||||||||||
| : CSharpCompilation.Create("components", references: minimalReferences).HasAddComponentParameter(); | ||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+48
to
+54
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💭 Since this is the source generator, would it make sense to avoid the extra allocation and array copy caused by
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| var razorConfiguration = new RazorConfiguration(razorLanguageVersion, configurationName ?? "default", Extensions: [], UseConsolidatedMvcViews: true, SuppressAddComponentParameter: !isComponentParameterSupported); | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| var razorSourceGenerationOptions = new RazorSourceGenerationOptions() | ||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.