Skip to content

Commit

Permalink
Update to support CancellationToken
Browse files Browse the repository at this point in the history
  • Loading branch information
NoahSurprenant committed Sep 21, 2024
1 parent f740233 commit 3bc84a9
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,11 @@ private static void AnalyzeReceiverInterface(

foreach (var parameter in method.Parameters)
{
if (SymbolEqualityComparer.Default.Equals(parameter.Type, specialSymbols.CancellationTokenSymbol))
{
continue;
}

ValidateType(context, parameter.Type, parameter.Locations[0], supportTypeSymbols, transpilationSourceAttributeSymbol);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public constructor(
this.Write(" const __");
this.Write(this.ToStringHelper.ToStringWithCulture(method.Name.Format(Options.NamingStyle)));
this.Write(" = ");
this.Write(this.ToStringHelper.ToStringWithCulture(method.WrapLambdaExpressionSyntax(Options)));
this.Write(this.ToStringHelper.ToStringWithCulture(method.WrapLambdaExpressionSyntax(SpecialSymbols, Options)));
this.Write(";\r\n");
}
this.Write("\r\n");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class <#= receiverType.Name #>_Binder implements ReceiverRegister<<#= receiverTy
public readonly register = (connection: HubConnection, receiver: <#= receiverType.Name #>): Disposable => {

<# foreach(var method in receiverType.Methods) { #>
const __<#= method.Name.Format(Options.NamingStyle) #> = <#= method.WrapLambdaExpressionSyntax(Options) #>;
const __<#= method.Name.Format(Options.NamingStyle) #> = <#= method.WrapLambdaExpressionSyntax(SpecialSymbols, Options) #>;
<# } #>

<# foreach(var method in receiverType.Methods) { #>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ namespace TypedSignalR.Client.TypeScript.Templates;

internal static class MethodSymbolExtensions
{
public static string WrapLambdaExpressionSyntax(this IMethodSymbol methodSymbol, ITypedSignalRTranspilationOptions options)
public static string WrapLambdaExpressionSyntax(this IMethodSymbol methodSymbol, SpecialSymbols specialSymbols, ITypedSignalRTranspilationOptions options)
{
if (methodSymbol.Parameters.Length == 0)
{
return $"() => receiver.{methodSymbol.Name.Format(options.MethodStyle)}()";
}

var parameters = ParametersToTypeArray(methodSymbol, options);
var parameters = ParametersToTypeArray(methodSymbol, specialSymbols, options);
return $"(...args: {parameters}) => receiver.{methodSymbol.Name.Format(options.MethodStyle)}(...args)";
}

Expand Down Expand Up @@ -78,9 +78,12 @@ private static string ReturnTypeToTypeScriptString(this IMethodSymbol methodSymb
return TypeMapper.MapTo(methodSymbol.ReturnType, options);
}

private static string ParametersToTypeArray(IMethodSymbol methodSymbol, ITypedSignalRTranspilationOptions options)
private static string ParametersToTypeArray(IMethodSymbol methodSymbol, SpecialSymbols specialSymbols, ITypedSignalRTranspilationOptions options)
{
var parameters = methodSymbol.Parameters.Select(x => TypeMapper.MapTo(x.Type, options));
var parameters = methodSymbol.Parameters
.Where(x => !SymbolEqualityComparer.Default.Equals(x.Type, specialSymbols.CancellationTokenSymbol))
.Select(x => TypeMapper.MapTo(x.Type, options));

return $"[{string.Join(", ", parameters)}]";
}

Expand Down

0 comments on commit 3bc84a9

Please sign in to comment.