-
Notifications
You must be signed in to change notification settings - Fork 79
Add support for modern .NET to AppServices library #576
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
Arlodotexe
merged 2 commits into
uwp-net8-windows
from
user/sergiopedri/uwp-net9-appservices
Oct 14, 2024
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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
34 changes: 34 additions & 0 deletions
34
...kit.AppServices.SourceGenerators/Extensions/GeneratorAttributeSyntaxContextWithOptions.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,34 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| // See the LICENSE file in the project root for more information. | ||
|
|
||
| using System.Collections.Immutable; | ||
| using Microsoft.CodeAnalysis; | ||
| using Microsoft.CodeAnalysis.Diagnostics; | ||
|
|
||
| namespace CommunityToolkit.AppServices.SourceGenerators.Extensions; | ||
|
|
||
| /// <summary> | ||
| /// <inheritdoc cref="GeneratorAttributeSyntaxContext" path="/summary/node()"/> | ||
| /// </summary> | ||
| /// <param name="syntaxContext">The original <see cref="GeneratorAttributeSyntaxContext"/> value.</param> | ||
| /// <param name="globalOptions">The original <see cref="AnalyzerConfigOptions"/> value.</param> | ||
| internal readonly struct GeneratorAttributeSyntaxContextWithOptions( | ||
| GeneratorAttributeSyntaxContext syntaxContext, | ||
| AnalyzerConfigOptions globalOptions) | ||
| { | ||
| /// <inheritdoc cref="GeneratorAttributeSyntaxContext.TargetNode"/> | ||
| public SyntaxNode TargetNode { get; } = syntaxContext.TargetNode; | ||
|
|
||
| /// <inheritdoc cref="GeneratorAttributeSyntaxContext.TargetSymbol"/> | ||
| public ISymbol TargetSymbol { get; } = syntaxContext.TargetSymbol; | ||
|
|
||
| /// <inheritdoc cref="GeneratorAttributeSyntaxContext.SemanticModel"/> | ||
| public SemanticModel SemanticModel { get; } = syntaxContext.SemanticModel; | ||
|
|
||
| /// <inheritdoc cref="GeneratorAttributeSyntaxContext.Attributes"/> | ||
| public ImmutableArray<AttributeData> Attributes { get; } = syntaxContext.Attributes; | ||
|
|
||
| /// <inheritdoc cref="AnalyzerConfigOptionsProvider.GlobalOptions"/> | ||
| public AnalyzerConfigOptions GlobalOptions { get; } = globalOptions; | ||
| } |
27 changes: 27 additions & 0 deletions
27
...unityToolkit.AppServices.SourceGenerators/Extensions/GeneratorSyntaxContextWithOptions.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,27 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| // See the LICENSE file in the project root for more information. | ||
|
|
||
| using Microsoft.CodeAnalysis; | ||
| using Microsoft.CodeAnalysis.Diagnostics; | ||
|
|
||
| namespace CommunityToolkit.AppServices.SourceGenerators.Extensions; | ||
|
|
||
| /// <summary> | ||
| /// <inheritdoc cref="GeneratorSyntaxContext" path="/summary/node()"/> | ||
| /// </summary> | ||
| /// <param name="syntaxContext">The original <see cref="GeneratorSyntaxContext"/> value.</param> | ||
| /// <param name="globalOptions">The original <see cref="AnalyzerConfigOptions"/> value.</param> | ||
| internal readonly struct GeneratorSyntaxContextWithOptions( | ||
| GeneratorSyntaxContext syntaxContext, | ||
| AnalyzerConfigOptions globalOptions) | ||
| { | ||
| /// <inheritdoc cref="GeneratorSyntaxContext.Node"/> | ||
| public SyntaxNode Node { get; } = syntaxContext.Node; | ||
|
|
||
| /// <inheritdoc cref="GeneratorSyntaxContext.SemanticModel"/> | ||
| public SemanticModel SemanticModel { get; } = syntaxContext.SemanticModel; | ||
|
|
||
| /// <inheritdoc cref="AnalyzerConfigOptionsProvider.GlobalOptions"/> | ||
| public AnalyzerConfigOptions GlobalOptions { get; } = globalOptions; | ||
| } |
59 changes: 59 additions & 0 deletions
59
...rvices.SourceGenerators/Extensions/IncrementalGeneratorInitializationContextExtensions.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,59 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| // See the LICENSE file in the project root for more information. | ||
|
|
||
| using System; | ||
| using System.Threading; | ||
| using Microsoft.CodeAnalysis; | ||
| using Microsoft.CodeAnalysis.Diagnostics; | ||
|
|
||
| namespace CommunityToolkit.AppServices.SourceGenerators.Extensions; | ||
|
|
||
| /// <summary> | ||
| /// Extension methods for <see cref="IncrementalGeneratorInitializationContext"/>. | ||
| /// </summary> | ||
| internal static class IncrementalGeneratorInitializationContextExtensions | ||
| { | ||
| /// <inheritdoc cref="SyntaxValueProvider.ForAttributeWithMetadataName"/> | ||
| public static IncrementalValuesProvider<T> ForAttributeWithMetadataNameAndOptions<T>( | ||
| this IncrementalGeneratorInitializationContext context, | ||
| string fullyQualifiedMetadataName, | ||
| Func<SyntaxNode, CancellationToken, bool> predicate, | ||
| Func<GeneratorAttributeSyntaxContextWithOptions, CancellationToken, T> transform) | ||
| { | ||
| // Invoke 'ForAttributeWithMetadataName' normally, but just return the context directly | ||
| IncrementalValuesProvider<GeneratorAttributeSyntaxContext> syntaxContext = context.SyntaxProvider.ForAttributeWithMetadataName( | ||
| fullyQualifiedMetadataName, | ||
| predicate, | ||
| static (context, token) => context); | ||
|
|
||
| // Do the same for the analyzer config options | ||
| IncrementalValueProvider<AnalyzerConfigOptions> configOptions = context.AnalyzerConfigOptionsProvider.Select(static (provider, token) => provider.GlobalOptions); | ||
|
|
||
| // Merge the two and invoke the provided transform on these two values. Neither value | ||
| // is equatable, meaning the pipeline will always re-run until this point. This is | ||
| // intentional: we don't want any symbols or other expensive objects to be kept alive | ||
| // across incremental steps, especially if they could cause entire compilations to be | ||
| // rooted, which would significantly increase memory use and introduce more GC pauses. | ||
| // In this specific case, flowing non equatable values in a pipeline is therefore fine. | ||
| return syntaxContext.Combine(configOptions).Select((input, token) => transform(new GeneratorAttributeSyntaxContextWithOptions(input.Left, input.Right), token)); | ||
| } | ||
|
|
||
| /// <inheritdoc cref="SyntaxValueProvider.CreateSyntaxProvider"/> | ||
| public static IncrementalValuesProvider<T> CreateSyntaxProviderWithOptions<T>( | ||
| this IncrementalGeneratorInitializationContext context, | ||
| Func<SyntaxNode, CancellationToken, bool> predicate, | ||
| Func<GeneratorSyntaxContextWithOptions, CancellationToken, T> transform) | ||
| { | ||
| // Invoke 'ForAttributeWithMetadataName' normally, but just return the context directly | ||
| IncrementalValuesProvider<GeneratorSyntaxContext> syntaxContext = context.SyntaxProvider.CreateSyntaxProvider( | ||
| predicate, | ||
| static (context, token) => context); | ||
|
|
||
| // Do the same for the analyzer config options | ||
| IncrementalValueProvider<AnalyzerConfigOptions> configOptions = context.AnalyzerConfigOptionsProvider.Select(static (provider, token) => provider.GlobalOptions); | ||
|
|
||
| // Merge the two and invoke the provided transform, like the extension above | ||
| return syntaxContext.Combine(configOptions).Select((input, token) => transform(new GeneratorSyntaxContextWithOptions(input.Left, input.Right), token)); | ||
| } | ||
| } |
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
5 changes: 5 additions & 0 deletions
5
components/AppServices/src/CommunityToolkit.AppServices.targets
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
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.