-
Notifications
You must be signed in to change notification settings - Fork 209
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
Merged
ryzngard
merged 30 commits into
dotnet:main
from
ryzngard:SuppressAddComponentParameter
Sep 20, 2024
Merged
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
c92386f
Add boolean
45334b8
Calculate the value and plumb it through
7fc2352
Bump serialization version
6794130
Add missing property write for json
e685ca5
PR feedback
5cca44c
Missed some
017a513
Space and bump json version
c77bce3
Fix test
a3bab60
Fix test data and bug in message pack formatter
cc8f604
No need to update this...
d3647a9
Remove existing configurable code generation option and just use it f…
chsienki eca23cb
Merge branch 'main' into SuppressAddComponentParameter
1f23c67
Remove unused member
353e217
PR feedback
dcc4fe8
Update src/Shared/Microsoft.AspNetCore.Razor.Serialization.Json/Objec…
3d2f246
Undo unrelated changes
b108d41
Fix compilation issue and add debug assert
4750b83
Merge branch 'main' into SuppressAddComponentParameter
66c1790
Update src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Uti…
73cfa13
Update src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/ProjectSyste…
41f69f9
Merge branch 'SuppressAddComponentParameter' of https://github.com/ry…
4cf5339
Merge branch 'main' into SuppressAddComponentParameter
4347cc3
Serialize UseConsolidatedMvcViews
1e2b4b0
Fix compilation. Move server flags to end since they are much more in…
5681389
Update RemoteProjectSnapshot.cs
b28e503
Merge branch 'main' into SuppressAddComponentParameter
15e1635
Set flag based on configuration
72d5e84
Set options builder
2205c2e
PR feedback. Reduce references for compilation
4117df5
Fix tests
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/CSharp/CompilationExtensions.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
....AspNetCore.Razor.Microbenchmarks/Resources/Telerik/Kendo.Mvc.Examples.project.razor.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/Resources/project.razor.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.