Skip to content

Commit

Permalink
chore: add upstream changes and use cancellationToken
Browse files Browse the repository at this point in the history
  • Loading branch information
TimothyMakkison committed Oct 7, 2024
1 parent edfb950 commit a56e5d3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
4 changes: 2 additions & 2 deletions InterfaceStubGenerator.Shared/InterfaceStubGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,9 @@ public void Initialize(GeneratorInitializationContext context)

class SyntaxReceiver : ISyntaxReceiver
{
public List<MethodDeclarationSyntax> CandidateMethods { get; } = new();
public List<MethodDeclarationSyntax> CandidateMethods { get; } = [];

public List<InterfaceDeclarationSyntax> CandidateInterfaces { get; } = new();
public List<InterfaceDeclarationSyntax> CandidateInterfaces { get; } = [];

public void OnVisitSyntaxNode(SyntaxNode syntaxNode)
{
Expand Down
16 changes: 12 additions & 4 deletions InterfaceStubGenerator.Shared/Parser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ internal static class Parser
/// <param name="refitInternalNamespace">The refit internal namespace.</param>
/// <param name="candidateMethods">The candidate methods.</param>
/// <param name="candidateInterfaces">The candidate interfaces.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns></returns>
public static (
List<Diagnostic> diagnostics,
Expand All @@ -28,6 +29,9 @@ ContextGenerationModel contextGenerationSpec
CancellationToken cancellationToken
)
{
if (compilation == null)
throw new ArgumentNullException(nameof(compilation));

refitInternalNamespace = $"{refitInternalNamespace ?? string.Empty}RefitInternalGenerated";

// we're going to create a new compilation that contains the attribute.
Expand Down Expand Up @@ -67,7 +71,7 @@ CancellationToken cancellationToken
foreach (var method in group)
{
// Get the symbol being declared by the method
var methodSymbol = model.GetDeclaredSymbol(method);
var methodSymbol = model.GetDeclaredSymbol(method, cancellationToken: cancellationToken);
if (!IsRefitMethod(methodSymbol, httpMethodBaseAttributeSymbol))
continue;

Expand All @@ -85,7 +89,11 @@ CancellationToken cancellationToken
m => m.ContainingType,
SymbolEqualityComparer.Default
)
.ToDictionary(g => g.Key, v => v.ToList());
.ToDictionary<IGrouping<INamedTypeSymbol, IMethodSymbol>, INamedTypeSymbol, List<IMethodSymbol>>(
g => g.Key,
v => [.. v],
SymbolEqualityComparer.Default
);

// Look through the candidate interfaces
var interfaceSymbols = new List<INamedTypeSymbol>();
Expand All @@ -95,7 +103,7 @@ CancellationToken cancellationToken
foreach (var iface in group)
{
// get the symbol belonging to the interface
var ifaceSymbol = model.GetDeclaredSymbol(iface);
var ifaceSymbol = model.GetDeclaredSymbol(iface, cancellationToken: cancellationToken);

// See if we already know about it, might be a dup
if (ifaceSymbol is null || interfaces.ContainsKey(ifaceSymbol))
Expand Down Expand Up @@ -162,7 +170,7 @@ sealed class PreserveAttribute : global::System.Attribute
// Is it needed in order to get the preserve attribute display name.
// Will the compilation ever change this.
compilation = compilation.AddSyntaxTrees(
CSharpSyntaxTree.ParseText(SourceText.From(attributeText, Encoding.UTF8), options)
CSharpSyntaxTree.ParseText(SourceText.From(attributeText, Encoding.UTF8), options, cancellationToken: cancellationToken)
);

// get the newly bound attribute
Expand Down

0 comments on commit a56e5d3

Please sign in to comment.