diff options
author | Brennan <brecon@microsoft.com> | 2021-11-11 22:21:26 +0300 |
---|---|---|
committer | Brennan <brecon@microsoft.com> | 2021-11-11 22:53:06 +0300 |
commit | db89aab3216683416f0a094095fa960c6b4dfc0e (patch) | |
tree | 3bdecfad92b6a2027f840e9c0e631410792cec79 | |
parent | 124229cf813e01a15ef0911706c54ccb6ad05d73 (diff) |
17 files changed, 140 insertions, 154 deletions
diff --git a/src/SignalR/clients/csharp/Client.SourceGenerator/src/HubProxyAttributes/ClientHubAttribute.cs b/src/SignalR/clients/csharp/Client.SourceGenerator/src/HubProxyAttributes/ClientHubAttribute.cs new file mode 100644 index 0000000000..e84a878f45 --- /dev/null +++ b/src/SignalR/clients/csharp/Client.SourceGenerator/src/HubProxyAttributes/ClientHubAttribute.cs @@ -0,0 +1,18 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System; + +namespace Microsoft.AspNetCore.SignalR.Client; + +/// <summary> +/// Provides information for generating strongly typed SignalR client callbacks. +/// Place this attribute on a method with the following syntax: +/// <code> +/// public static partial IDisposable RegisterCallbacks<T>(this HubConnection connection, T proxy); +/// </code> +/// </summary> +[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] +public sealed class ClientHubAttribute : Attribute +{ +} diff --git a/src/SignalR/clients/csharp/Client.SourceGenerator/src/HubProxyAttributes/HubClientProxyAttribute.cs b/src/SignalR/clients/csharp/Client.SourceGenerator/src/HubProxyAttributes/HubClientProxyAttribute.cs deleted file mode 100644 index edc8266045..0000000000 --- a/src/SignalR/clients/csharp/Client.SourceGenerator/src/HubProxyAttributes/HubClientProxyAttribute.cs +++ /dev/null @@ -1,19 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System; - -namespace Microsoft.AspNetCore.SignalR.Client -{ - /// <summary> - /// Provides information for generating strongly typed SignalR client callbacks. - /// Place this attribute on a method with the following syntax: - /// <code> - /// public static partial IDisposable RegisterCallbacks<T>(this HubConnection connection, T proxy); - /// </code> - /// </summary> - [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] - public sealed class HubClientProxyAttribute : Attribute - { - } -} diff --git a/src/SignalR/clients/csharp/Client.SourceGenerator/src/HubProxyAttributes/HubServerProxyAttribute.cs b/src/SignalR/clients/csharp/Client.SourceGenerator/src/HubProxyAttributes/HubServerProxyAttribute.cs deleted file mode 100644 index bce170a316..0000000000 --- a/src/SignalR/clients/csharp/Client.SourceGenerator/src/HubProxyAttributes/HubServerProxyAttribute.cs +++ /dev/null @@ -1,19 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System; - -namespace Microsoft.AspNetCore.SignalR.Client -{ - /// <summary> - /// Provides information for generating strongly typed SignalR server invocations from the client. - /// Place this attribute on a method with the following syntax: - /// <code> - /// public static partial T GetProxy<T>(this HubConnection connection); - /// </code> - /// </summary> - [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] - public sealed class HubServerProxyAttribute : Attribute - { - } -} diff --git a/src/SignalR/clients/csharp/Client.SourceGenerator/src/HubProxyAttributes/PublicAPI.Unshipped.txt b/src/SignalR/clients/csharp/Client.SourceGenerator/src/HubProxyAttributes/PublicAPI.Unshipped.txt index 5520999c80..0e0f0e5d86 100644 --- a/src/SignalR/clients/csharp/Client.SourceGenerator/src/HubProxyAttributes/PublicAPI.Unshipped.txt +++ b/src/SignalR/clients/csharp/Client.SourceGenerator/src/HubProxyAttributes/PublicAPI.Unshipped.txt @@ -1,4 +1,4 @@ -Microsoft.AspNetCore.SignalR.Client.HubClientProxyAttribute -Microsoft.AspNetCore.SignalR.Client.HubClientProxyAttribute.HubClientProxyAttribute() -> void -Microsoft.AspNetCore.SignalR.Client.HubServerProxyAttribute -Microsoft.AspNetCore.SignalR.Client.HubServerProxyAttribute.HubServerProxyAttribute() -> void +Microsoft.AspNetCore.SignalR.Client.ClientHubAttribute +Microsoft.AspNetCore.SignalR.Client.ClientHubAttribute.ClientHubAttribute() -> void +Microsoft.AspNetCore.SignalR.Client.ServerHubProxyAttribute +Microsoft.AspNetCore.SignalR.Client.ServerHubProxyAttribute.ServerHubProxyAttribute() -> void diff --git a/src/SignalR/clients/csharp/Client.SourceGenerator/src/HubProxyAttributes/ServerHubProxyAttribute.cs b/src/SignalR/clients/csharp/Client.SourceGenerator/src/HubProxyAttributes/ServerHubProxyAttribute.cs new file mode 100644 index 0000000000..d1813d0a52 --- /dev/null +++ b/src/SignalR/clients/csharp/Client.SourceGenerator/src/HubProxyAttributes/ServerHubProxyAttribute.cs @@ -0,0 +1,18 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System; + +namespace Microsoft.AspNetCore.SignalR.Client; + +/// <summary> +/// Provides information for generating strongly typed SignalR server invocations from the client. +/// Place this attribute on a method with the following syntax: +/// <code> +/// public static partial T GetProxy<T>(this HubConnection connection); +/// </code> +/// </summary> +[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] +public sealed class ServerHubProxyAttribute : Attribute +{ +} diff --git a/src/SignalR/clients/csharp/Client.SourceGenerator/src/gen/HubClientProxyGenerator.Emitter.cs b/src/SignalR/clients/csharp/Client.SourceGenerator/src/gen/ClientHubGenerator.Emitter.cs index 144e92523c..a6e83f736e 100644 --- a/src/SignalR/clients/csharp/Client.SourceGenerator/src/gen/HubClientProxyGenerator.Emitter.cs +++ b/src/SignalR/clients/csharp/Client.SourceGenerator/src/gen/ClientHubGenerator.Emitter.cs @@ -7,7 +7,7 @@ using Microsoft.CodeAnalysis.Text; namespace Microsoft.AspNetCore.SignalR.Client.SourceGenerator; -internal partial class HubClientProxyGenerator +internal partial class ClientHubGenerator { public class Emitter { diff --git a/src/SignalR/clients/csharp/Client.SourceGenerator/src/gen/HubClientProxyGenerator.Parser.cs b/src/SignalR/clients/csharp/Client.SourceGenerator/src/gen/ClientHubGenerator.Parser.cs index 346c82026c..ceeb32302e 100644 --- a/src/SignalR/clients/csharp/Client.SourceGenerator/src/gen/HubClientProxyGenerator.Parser.cs +++ b/src/SignalR/clients/csharp/Client.SourceGenerator/src/gen/ClientHubGenerator.Parser.cs @@ -11,7 +11,7 @@ using Microsoft.CodeAnalysis.CSharp.Syntax; namespace Microsoft.AspNetCore.SignalR.Client.SourceGenerator; -internal partial class HubClientProxyGenerator +internal partial class ClientHubGenerator { public class Parser { @@ -21,7 +21,7 @@ internal partial class HubClientProxyGenerator { Identifier: { - Text: "HubClientProxy" + Text: "ClientHub" } }, Parent: @@ -39,7 +39,7 @@ internal partial class HubClientProxyGenerator var attributeSymbol = ModelExtensions.GetSymbolInfo(context.SemanticModel, attributeSyntax).Symbol; if (attributeSymbol is null || - !attributeSymbol.ToString().EndsWith("HubClientProxyAttribute()", StringComparison.Ordinal)) + !attributeSymbol.ToString().EndsWith("ClientHubAttribute()", StringComparison.Ordinal)) { return null; } @@ -53,7 +53,7 @@ internal partial class HubClientProxyGenerator if (!symbol.IsPartialDefinition) { context.ReportDiagnostic(Diagnostic.Create( - DiagnosticDescriptors.HubClientProxyAttributedMethodIsNotPartial, + DiagnosticDescriptors.ClientHubAttributedMethodIsNotPartial, symbol.Locations[0])); return false; } @@ -62,7 +62,7 @@ internal partial class HubClientProxyGenerator if (!symbol.IsExtensionMethod) { context.ReportDiagnostic(Diagnostic.Create( - DiagnosticDescriptors.HubClientProxyAttributedMethodIsNotExtension, + DiagnosticDescriptors.ClientHubAttributedMethodIsNotExtension, symbol.Locations[0])); return false; } @@ -71,7 +71,7 @@ internal partial class HubClientProxyGenerator if (symbol.Arity != 1) { context.ReportDiagnostic(Diagnostic.Create( - DiagnosticDescriptors.HubClientProxyAttributedMethodTypeArgCountIsBad, + DiagnosticDescriptors.ClientHubAttributedMethodTypeArgCountIsBad, symbol.Locations[0])); return false; } @@ -80,7 +80,7 @@ internal partial class HubClientProxyGenerator if (symbol.Parameters.Length != 2) { context.ReportDiagnostic(Diagnostic.Create( - DiagnosticDescriptors.HubClientProxyAttributedMethodArgCountIsBad, + DiagnosticDescriptors.ClientHubAttributedMethodArgCountIsBad, symbol.Locations[0])); return false; } @@ -89,7 +89,7 @@ internal partial class HubClientProxyGenerator if (!SymbolEqualityComparer.Default.Equals(symbol.TypeArguments[0], symbol.Parameters[1].Type)) { context.ReportDiagnostic(Diagnostic.Create( - DiagnosticDescriptors.HubClientProxyAttributedMethodTypeArgAndProviderTypeDoesNotMatch, + DiagnosticDescriptors.ClientHubAttributedMethodTypeArgAndProviderTypeDoesNotMatch, symbol.Locations[0])); return false; } @@ -98,7 +98,7 @@ internal partial class HubClientProxyGenerator if (symbol.ReturnType.ToString() != "System.IDisposable") { context.ReportDiagnostic(Diagnostic.Create( - DiagnosticDescriptors.HubClientProxyAttributedMethodHasBadReturnType, + DiagnosticDescriptors.ClientHubAttributedMethodHasBadReturnType, symbol.Locations[0])); return false; } @@ -107,7 +107,7 @@ internal partial class HubClientProxyGenerator if (hubConnectionSymbol.ToString() != "Microsoft.AspNetCore.SignalR.Client.HubConnection") { context.ReportDiagnostic(Diagnostic.Create( - DiagnosticDescriptors.HubClientProxyAttributedMethodArgIsNotHubConnection, + DiagnosticDescriptors.ClientHubAttributedMethodArgIsNotHubConnection, symbol.Locations[0])); return false; } @@ -160,7 +160,7 @@ internal partial class HubClientProxyGenerator foreach (var attributeData in methodSymbol.GetAttributes()) { if (!attributeData.AttributeClass.ToString() - .EndsWith("HubClientProxyAttribute", StringComparison.Ordinal)) + .EndsWith("ClientHubAttribute", StringComparison.Ordinal)) { continue; } @@ -195,7 +195,7 @@ internal partial class HubClientProxyGenerator { _context.ReportDiagnostic( Diagnostic.Create( - DiagnosticDescriptors.TooManyHubClientProxyAttributedMethods, + DiagnosticDescriptors.TooManyClientHubAttributedMethods, extraneous.GetLocation())); } @@ -226,7 +226,7 @@ internal partial class HubClientProxyGenerator if (sourceGenerationSpec.SetterMethodAccessibility is null) { _context.ReportDiagnostic(Diagnostic.Create( - DiagnosticDescriptors.HubClientProxyAttributedMethodBadAccessibility, + DiagnosticDescriptors.ClientHubAttributedMethodBadAccessibility, methodDeclarationSyntax.GetLocation())); return sourceGenerationSpec; } @@ -301,7 +301,7 @@ internal partial class HubClientProxyGenerator if (!(member.ReturnsVoid || member.ReturnType is INamedTypeSymbol { Arity: 0, Name: "Task" })) { _context.ReportDiagnostic(Diagnostic.Create( - DiagnosticDescriptors.HubClientProxyUnsupportedReturnType, + DiagnosticDescriptors.ClientHubUnsupportedReturnType, typeSpec.CallSite, methodSpec.Name, member.ReturnType.Name)); methodSpec.Support = SupportClassification.UnsupportedReturnType; diff --git a/src/SignalR/clients/csharp/Client.SourceGenerator/src/gen/HubClientProxyGenerator.SourceGenerationSpec.cs b/src/SignalR/clients/csharp/Client.SourceGenerator/src/gen/ClientHubGenerator.SourceGenerationSpec.cs index e9640fe586..aae0cf8a55 100644 --- a/src/SignalR/clients/csharp/Client.SourceGenerator/src/gen/HubClientProxyGenerator.SourceGenerationSpec.cs +++ b/src/SignalR/clients/csharp/Client.SourceGenerator/src/gen/ClientHubGenerator.SourceGenerationSpec.cs @@ -6,7 +6,7 @@ using Microsoft.CodeAnalysis; namespace Microsoft.AspNetCore.SignalR.Client.SourceGenerator; -internal partial class HubClientProxyGenerator +internal partial class ClientHubGenerator { public class SourceGenerationSpec { diff --git a/src/SignalR/clients/csharp/Client.SourceGenerator/src/gen/HubServerProxyGenerator.cs b/src/SignalR/clients/csharp/Client.SourceGenerator/src/gen/ClientHubGenerator.cs index 16672acfe1..df40ef5275 100644 --- a/src/SignalR/clients/csharp/Client.SourceGenerator/src/gen/HubServerProxyGenerator.cs +++ b/src/SignalR/clients/csharp/Client.SourceGenerator/src/gen/ClientHubGenerator.cs @@ -8,7 +8,7 @@ using Microsoft.CodeAnalysis.CSharp.Syntax; namespace Microsoft.AspNetCore.SignalR.Client.SourceGenerator; [Generator] -internal partial class HubServerProxyGenerator : IIncrementalGenerator +internal partial class ClientHubGenerator : IIncrementalGenerator { public void Initialize(IncrementalGeneratorInitializationContext context) { diff --git a/src/SignalR/clients/csharp/Client.SourceGenerator/src/gen/DiagnosticDescriptors.cs b/src/SignalR/clients/csharp/Client.SourceGenerator/src/gen/DiagnosticDescriptors.cs index 296207920d..cdb9b407c2 100644 --- a/src/SignalR/clients/csharp/Client.SourceGenerator/src/gen/DiagnosticDescriptors.cs +++ b/src/SignalR/clients/csharp/Client.SourceGenerator/src/gen/DiagnosticDescriptors.cs @@ -8,10 +8,10 @@ namespace Microsoft.AspNetCore.SignalR.Client.SourceGenerator; internal static class DiagnosticDescriptors { // Ranges - // SSG0000-0099: HubServerProxyGenerator - // SSG0100-0199: HubClientProxyGenerator + // SSG0000-0099: ServerHubProxyGenerator + // SSG0100-0199: ClientHubGenerator - public static DiagnosticDescriptor HubServerProxyNonInterfaceGenericTypeArgument { get; } = new DiagnosticDescriptor( + public static DiagnosticDescriptor ServerHubProxyNonInterfaceGenericTypeArgument { get; } = new DiagnosticDescriptor( id: "SSG0000", title: "Non-interface generic type argument", messageFormat: "Only interfaces are accepted. '{0}' is not an interface.", @@ -19,7 +19,7 @@ internal static class DiagnosticDescriptors defaultSeverity: DiagnosticSeverity.Error, isEnabledByDefault: true); - public static DiagnosticDescriptor HubServerProxyUnsupportedReturnType { get; } = new DiagnosticDescriptor( + public static DiagnosticDescriptor ServerHubProxyUnsupportedReturnType { get; } = new DiagnosticDescriptor( id: "SSG0001", title: "Unsupported return type", messageFormat: "'{0}' has a return type of '{1}' but only Task, ValueTask, Task<T> and ValueTask<T> are supported for source generation.", @@ -27,73 +27,73 @@ internal static class DiagnosticDescriptors defaultSeverity: DiagnosticSeverity.Warning, isEnabledByDefault: true); - public static DiagnosticDescriptor TooManyHubServerProxyAttributedMethods { get; } = new DiagnosticDescriptor( + public static DiagnosticDescriptor TooManyServerHubProxyAttributedMethods { get; } = new DiagnosticDescriptor( id: "SSG0002", - title: "Too many HubServerProxy attributed methods", - messageFormat: "There can only be one HubServerProxy attributed method.", + title: "Too many ServerHubProxy attributed methods", + messageFormat: "There can only be one ServerHubProxy attributed method.", category: "SignalR.Client.SourceGenerator", defaultSeverity: DiagnosticSeverity.Error, isEnabledByDefault: true); - public static DiagnosticDescriptor HubServerProxyAttributedMethodBadAccessibility { get; } = new DiagnosticDescriptor( + public static DiagnosticDescriptor ServerHubProxyAttributedMethodBadAccessibility { get; } = new DiagnosticDescriptor( id: "SSG0003", - title: "HubServerProxy attributed method has bad accessibility", - messageFormat: "HubServerProxy attributed method may only have an accessibility of public, internal, protected, protected internal or private.", + title: "ServerHubProxy attributed method has bad accessibility", + messageFormat: "ServerHubProxy attributed method may only have an accessibility of public, internal, protected, protected internal or private.", category: "SignalR.Client.SourceGenerator", defaultSeverity: DiagnosticSeverity.Error, isEnabledByDefault: true); - public static DiagnosticDescriptor HubServerProxyAttributedMethodIsNotPartial { get; } = new DiagnosticDescriptor( + public static DiagnosticDescriptor ServerHubProxyAttributedMethodIsNotPartial { get; } = new DiagnosticDescriptor( id: "SSG0004", - title: "HubServerProxy attributed method is not partial", - messageFormat: "HubServerProxy attributed method must be partial.", + title: "ServerHubProxy attributed method is not partial", + messageFormat: "ServerHubProxy attributed method must be partial.", category: "SignalR.Client.SourceGenerator", defaultSeverity: DiagnosticSeverity.Error, isEnabledByDefault: true); - public static DiagnosticDescriptor HubServerProxyAttributedMethodIsNotExtension { get; } = new DiagnosticDescriptor( + public static DiagnosticDescriptor ServerHubProxyAttributedMethodIsNotExtension { get; } = new DiagnosticDescriptor( id: "SSG0005", - title: "HubServerProxy attributed method is not an extension method", - messageFormat: "HubServerProxy attributed method must be an extension method for HubConnection.", + title: "ServerHubProxy attributed method is not an extension method", + messageFormat: "ServerHubProxy attributed method must be an extension method for HubConnection.", category: "SignalR.Client.SourceGenerator", defaultSeverity: DiagnosticSeverity.Error, isEnabledByDefault: true); - public static DiagnosticDescriptor HubServerProxyAttributedMethodTypeArgCountIsBad { get; } = new DiagnosticDescriptor( + public static DiagnosticDescriptor ServerHubProxyAttributedMethodTypeArgCountIsBad { get; } = new DiagnosticDescriptor( id: "SSG0006", - title: "HubServerProxy attributed method has bad number of type arguments", - messageFormat: "HubServerProxy attributed method must have exactly one type argument.", + title: "ServerHubProxy attributed method has bad number of type arguments", + messageFormat: "ServerHubProxy attributed method must have exactly one type argument.", category: "SignalR.Client.SourceGenerator", defaultSeverity: DiagnosticSeverity.Error, isEnabledByDefault: true); - public static DiagnosticDescriptor HubServerProxyAttributedMethodTypeArgAndReturnTypeDoesNotMatch { get; } = new DiagnosticDescriptor( + public static DiagnosticDescriptor ServerHubProxyAttributedMethodTypeArgAndReturnTypeDoesNotMatch { get; } = new DiagnosticDescriptor( id: "SSG0007", - title: "HubServerProxy attributed method type argument and return type does not match", - messageFormat: "HubServerProxy attributed method must have the same type argument and return type.", + title: "ServerHubProxy attributed method type argument and return type does not match", + messageFormat: "ServerHubProxy attributed method must have the same type argument and return type.", category: "SignalR.Client.SourceGenerator", defaultSeverity: DiagnosticSeverity.Error, isEnabledByDefault: true); - public static DiagnosticDescriptor HubServerProxyAttributedMethodArgCountIsBad { get; } = new DiagnosticDescriptor( + public static DiagnosticDescriptor ServerHubProxyAttributedMethodArgCountIsBad { get; } = new DiagnosticDescriptor( id: "SSG0008", - title: "HubServerProxy attributed method has bad number of arguments", - messageFormat: "HubServerProxy attributed method must have exactly one argument which must be of type HubConnection.", + title: "ServerHubProxy attributed method has bad number of arguments", + messageFormat: "ServerHubProxy attributed method must have exactly one argument which must be of type HubConnection.", category: "SignalR.Client.SourceGenerator", defaultSeverity: DiagnosticSeverity.Error, isEnabledByDefault: true); - public static DiagnosticDescriptor HubServerProxyAttributedMethodArgIsNotHubConnection { get; } = new DiagnosticDescriptor( + public static DiagnosticDescriptor ServerHubProxyAttributedMethodArgIsNotHubConnection { get; } = new DiagnosticDescriptor( id: "SSG0009", - title: "HubServerProxy attributed method has argument of wrong type", - messageFormat: "HubServerProxy attributed method must have exactly one argument which must be of type HubConnection.", + title: "ServerHubProxy attributed method has argument of wrong type", + messageFormat: "ServerHubProxy attributed method must have exactly one argument which must be of type HubConnection.", category: "SignalR.Client.SourceGenerator", defaultSeverity: DiagnosticSeverity.Error, isEnabledByDefault: true); - // HubClientProxy section + // ClientHub section - public static DiagnosticDescriptor HubClientProxyUnsupportedReturnType { get; } = new DiagnosticDescriptor( + public static DiagnosticDescriptor ClientHubUnsupportedReturnType { get; } = new DiagnosticDescriptor( id: "SSG0100", title: "Unsupported return type", messageFormat: "'{0}' has a return type of '{1}' but only void and Task are supported for callback methods.", @@ -101,74 +101,74 @@ internal static class DiagnosticDescriptors defaultSeverity: DiagnosticSeverity.Warning, isEnabledByDefault: true); - public static DiagnosticDescriptor TooManyHubClientProxyAttributedMethods { get; } = new DiagnosticDescriptor( + public static DiagnosticDescriptor TooManyClientHubAttributedMethods { get; } = new DiagnosticDescriptor( id: "SSG0102", - title: "Too many HubClientProxy attributed methods", - messageFormat: "There can only be one HubClientProxy attributed method.", + title: "Too many ClientHub attributed methods", + messageFormat: "There can only be one ClientHub attributed method.", category: "SignalR.Client.SourceGenerator", defaultSeverity: DiagnosticSeverity.Error, isEnabledByDefault: true); - public static DiagnosticDescriptor HubClientProxyAttributedMethodBadAccessibility { get; } = new DiagnosticDescriptor( + public static DiagnosticDescriptor ClientHubAttributedMethodBadAccessibility { get; } = new DiagnosticDescriptor( id: "SSG0103", - title: "HubClientProxy attributed method has bad accessibility", - messageFormat: "HubClientProxy attributed method may only have an accessibility of public, internal, protected, protected internal or private.", + title: "ClientHub attributed method has bad accessibility", + messageFormat: "ClientHub attributed method may only have an accessibility of public, internal, protected, protected internal or private.", category: "SignalR.Client.SourceGenerator", defaultSeverity: DiagnosticSeverity.Error, isEnabledByDefault: true); - public static DiagnosticDescriptor HubClientProxyAttributedMethodIsNotPartial { get; } = new DiagnosticDescriptor( + public static DiagnosticDescriptor ClientHubAttributedMethodIsNotPartial { get; } = new DiagnosticDescriptor( id: "SSG0104", - title: "HubClientProxy attributed method is not partial", - messageFormat: "HubClientProxy attributed method must be partial.", + title: "ClientHub attributed method is not partial", + messageFormat: "ClientHub attributed method must be partial.", category: "SignalR.Client.SourceGenerator", defaultSeverity: DiagnosticSeverity.Error, isEnabledByDefault: true); - public static DiagnosticDescriptor HubClientProxyAttributedMethodIsNotExtension { get; } = new DiagnosticDescriptor( + public static DiagnosticDescriptor ClientHubAttributedMethodIsNotExtension { get; } = new DiagnosticDescriptor( id: "SSG0105", - title: "HubClientProxy attributed method is not an extension method", - messageFormat: "HubClientProxy attributed method must be an extension method for HubConnection.", + title: "ClientHub attributed method is not an extension method", + messageFormat: "ClientHub attributed method must be an extension method for HubConnection.", category: "SignalR.Client.SourceGenerator", defaultSeverity: DiagnosticSeverity.Error, isEnabledByDefault: true); - public static DiagnosticDescriptor HubClientProxyAttributedMethodTypeArgCountIsBad { get; } = new DiagnosticDescriptor( + public static DiagnosticDescriptor ClientHubAttributedMethodTypeArgCountIsBad { get; } = new DiagnosticDescriptor( id: "SSG0106", - title: "HubClientProxy attributed method has bad number of type arguments", - messageFormat: "HubClientProxy attributed method must have exactly one type argument.", + title: "ClientHub attributed method has bad number of type arguments", + messageFormat: "ClientHub attributed method must have exactly one type argument.", category: "SignalR.Client.SourceGenerator", defaultSeverity: DiagnosticSeverity.Error, isEnabledByDefault: true); - public static DiagnosticDescriptor HubClientProxyAttributedMethodTypeArgAndProviderTypeDoesNotMatch { get; } = new DiagnosticDescriptor( + public static DiagnosticDescriptor ClientHubAttributedMethodTypeArgAndProviderTypeDoesNotMatch { get; } = new DiagnosticDescriptor( id: "SSG0107", - title: "HubClientProxy attributed method type argument and return type does not match", - messageFormat: "HubClientProxy attributed method must have the same type argument and return type.", + title: "ClientHub attributed method type argument and return type does not match", + messageFormat: "ClientHub attributed method must have the same type argument and return type.", category: "SignalR.Client.SourceGenerator", defaultSeverity: DiagnosticSeverity.Error, isEnabledByDefault: true); - public static DiagnosticDescriptor HubClientProxyAttributedMethodArgCountIsBad { get; } = new DiagnosticDescriptor( + public static DiagnosticDescriptor ClientHubAttributedMethodArgCountIsBad { get; } = new DiagnosticDescriptor( id: "SSG0108", - title: "HubClientProxy attributed method has bad number of arguments", - messageFormat: "HubClientProxy attributed method must have exactly two arguments.", + title: "ClientHub attributed method has bad number of arguments", + messageFormat: "ClientHub attributed method must have exactly two arguments.", category: "SignalR.Client.SourceGenerator", defaultSeverity: DiagnosticSeverity.Error, isEnabledByDefault: true); - public static DiagnosticDescriptor HubClientProxyAttributedMethodArgIsNotHubConnection { get; } = new DiagnosticDescriptor( + public static DiagnosticDescriptor ClientHubAttributedMethodArgIsNotHubConnection { get; } = new DiagnosticDescriptor( id: "SSG0109", - title: "HubClientProxy attributed method has first argument of wrong type", - messageFormat: "HubClientProxy attributed method must have its first argument type be HubConnection.", + title: "ClientHub attributed method has first argument of wrong type", + messageFormat: "ClientHub attributed method must have its first argument type be HubConnection.", category: "SignalR.Client.SourceGenerator", defaultSeverity: DiagnosticSeverity.Error, isEnabledByDefault: true); - public static DiagnosticDescriptor HubClientProxyAttributedMethodHasBadReturnType { get; } = new DiagnosticDescriptor( + public static DiagnosticDescriptor ClientHubAttributedMethodHasBadReturnType { get; } = new DiagnosticDescriptor( id: "SSG0110", - title: "HubClientProxy attributed method has wrong return type", - messageFormat: "HubClientProxy attributed method must have a return type of IDisposable.", + title: "ClientHub attributed method has wrong return type", + messageFormat: "ClientHub attributed method must have a return type of IDisposable.", category: "SignalR.Client.SourceGenerator", defaultSeverity: DiagnosticSeverity.Error, isEnabledByDefault: true); diff --git a/src/SignalR/clients/csharp/Client.SourceGenerator/src/gen/GeneratorHelpers.cs b/src/SignalR/clients/csharp/Client.SourceGenerator/src/gen/GeneratorHelpers.cs index 6cbee2b12c..fefa06ace8 100644 --- a/src/SignalR/clients/csharp/Client.SourceGenerator/src/gen/GeneratorHelpers.cs +++ b/src/SignalR/clients/csharp/Client.SourceGenerator/src/gen/GeneratorHelpers.cs @@ -24,15 +24,15 @@ internal static class GeneratorHelpers default: return null; } + } - public static string SourceFilePrefix() - { - return @"// <auto-generated> + public static string SourceFilePrefix() + { + return @"// <auto-generated> // Generated by Microsoft.AspNetCore.Client.SourceGenerator // </auto-generated> #nullable enable "; - } } } diff --git a/src/SignalR/clients/csharp/Client.SourceGenerator/src/gen/HubServerProxyGenerator.Emitter.cs b/src/SignalR/clients/csharp/Client.SourceGenerator/src/gen/ServerHubProxyGenerator.Emitter.cs index 839bd75b30..35262882e0 100644 --- a/src/SignalR/clients/csharp/Client.SourceGenerator/src/gen/HubServerProxyGenerator.Emitter.cs +++ b/src/SignalR/clients/csharp/Client.SourceGenerator/src/gen/ServerHubProxyGenerator.Emitter.cs @@ -7,7 +7,7 @@ using Microsoft.CodeAnalysis.Text; namespace Microsoft.AspNetCore.SignalR.Client.SourceGenerator; -internal partial class HubServerProxyGenerator +internal partial class ServerHubProxyGenerator { public class Emitter { diff --git a/src/SignalR/clients/csharp/Client.SourceGenerator/src/gen/HubServerProxyGenerator.Parser.cs b/src/SignalR/clients/csharp/Client.SourceGenerator/src/gen/ServerHubProxyGenerator.Parser.cs index 72d2bc7f37..b6d63ba1c4 100644 --- a/src/SignalR/clients/csharp/Client.SourceGenerator/src/gen/HubServerProxyGenerator.Parser.cs +++ b/src/SignalR/clients/csharp/Client.SourceGenerator/src/gen/ServerHubProxyGenerator.Parser.cs @@ -12,7 +12,7 @@ using Microsoft.CodeAnalysis.CSharp.Syntax; namespace Microsoft.AspNetCore.SignalR.Client.SourceGenerator; -internal partial class HubServerProxyGenerator +internal partial class ServerHubProxyGenerator { internal class Parser { @@ -22,7 +22,7 @@ internal partial class HubServerProxyGenerator { Identifier: { - Text: "HubServerProxy" + Text: "ServerHubProxy" } }, Parent: @@ -40,7 +40,7 @@ internal partial class HubServerProxyGenerator var attributeSymbol = context.SemanticModel.GetSymbolInfo(attributeSyntax).Symbol; if (attributeSymbol is null || - !attributeSymbol.ToString().EndsWith("HubServerProxyAttribute()", StringComparison.Ordinal)) + !attributeSymbol.ToString().EndsWith("ServerHubProxyAttribute()", StringComparison.Ordinal)) { return null; } @@ -54,7 +54,7 @@ internal partial class HubServerProxyGenerator if (!symbol.IsPartialDefinition) { context.ReportDiagnostic(Diagnostic.Create( - DiagnosticDescriptors.HubServerProxyAttributedMethodIsNotPartial, + DiagnosticDescriptors.ServerHubProxyAttributedMethodIsNotPartial, symbol.Locations[0])); return false; } @@ -63,7 +63,7 @@ internal partial class HubServerProxyGenerator if (!symbol.IsExtensionMethod) { context.ReportDiagnostic(Diagnostic.Create( - DiagnosticDescriptors.HubServerProxyAttributedMethodIsNotExtension, + DiagnosticDescriptors.ServerHubProxyAttributedMethodIsNotExtension, symbol.Locations[0])); return false; } @@ -72,7 +72,7 @@ internal partial class HubServerProxyGenerator if (symbol.Arity != 1) { context.ReportDiagnostic(Diagnostic.Create( - DiagnosticDescriptors.HubServerProxyAttributedMethodTypeArgCountIsBad, + DiagnosticDescriptors.ServerHubProxyAttributedMethodTypeArgCountIsBad, symbol.Locations[0])); return false; } @@ -81,7 +81,7 @@ internal partial class HubServerProxyGenerator if (!SymbolEqualityComparer.Default.Equals(symbol.TypeArguments[0], symbol.ReturnType)) { context.ReportDiagnostic(Diagnostic.Create( - DiagnosticDescriptors.HubServerProxyAttributedMethodTypeArgAndReturnTypeDoesNotMatch, + DiagnosticDescriptors.ServerHubProxyAttributedMethodTypeArgAndReturnTypeDoesNotMatch, symbol.Locations[0])); return false; } @@ -90,7 +90,7 @@ internal partial class HubServerProxyGenerator if (symbol.Parameters.Length != 1) { context.ReportDiagnostic(Diagnostic.Create( - DiagnosticDescriptors.HubServerProxyAttributedMethodArgCountIsBad, + DiagnosticDescriptors.ServerHubProxyAttributedMethodArgCountIsBad, symbol.Locations[0])); return false; } @@ -98,7 +98,7 @@ internal partial class HubServerProxyGenerator if (hubConnectionSymbol.ToString() != "Microsoft.AspNetCore.SignalR.Client.HubConnection") { context.ReportDiagnostic(Diagnostic.Create( - DiagnosticDescriptors.HubServerProxyAttributedMethodArgIsNotHubConnection, + DiagnosticDescriptors.ServerHubProxyAttributedMethodArgIsNotHubConnection, symbol.Locations[0])); return false; } @@ -151,7 +151,7 @@ internal partial class HubServerProxyGenerator foreach (var attributeData in methodSymbol.GetAttributes()) { if (!attributeData.AttributeClass.ToString() - .EndsWith("HubServerProxyAttribute", StringComparison.Ordinal)) + .EndsWith("ServerHubProxyAttribute", StringComparison.Ordinal)) { continue; } @@ -185,7 +185,7 @@ internal partial class HubServerProxyGenerator foreach (var extraneous in methodDeclarationSyntaxes) { _context.ReportDiagnostic( - Diagnostic.Create(DiagnosticDescriptors.TooManyHubServerProxyAttributedMethods, + Diagnostic.Create(DiagnosticDescriptors.TooManyServerHubProxyAttributedMethods, extraneous.GetLocation())); } @@ -216,7 +216,7 @@ internal partial class HubServerProxyGenerator if (sourceGenerationSpec.GetterMethodAccessibility is null) { _context.ReportDiagnostic(Diagnostic.Create( - DiagnosticDescriptors.HubServerProxyAttributedMethodBadAccessibility, + DiagnosticDescriptors.ServerHubProxyAttributedMethodBadAccessibility, methodDeclarationSyntax.GetLocation())); return sourceGenerationSpec; } @@ -239,7 +239,7 @@ internal partial class HubServerProxyGenerator { // T in GetProxy<T> must be an interface _context.ReportDiagnostic(Diagnostic.Create( - DiagnosticDescriptors.HubServerProxyNonInterfaceGenericTypeArgument, + DiagnosticDescriptors.ServerHubProxyNonInterfaceGenericTypeArgument, memberAccess.GetLocation(), proxyType.ToString())); continue; @@ -324,7 +324,7 @@ internal partial class HubServerProxyGenerator member.ReturnType is not INamedTypeSymbol { Name: "Task" or "ValueTask" }) { _context.ReportDiagnostic(Diagnostic.Create( - DiagnosticDescriptors.HubServerProxyUnsupportedReturnType, + DiagnosticDescriptors.ServerHubProxyUnsupportedReturnType, classSpec.CallSite, methodSpec.Name, member.ReturnType.Name)); methodSpec.Support = SupportClassification.UnsupportedReturnType; diff --git a/src/SignalR/clients/csharp/Client.SourceGenerator/src/gen/HubServerProxyGenerator.SourceGenerationSpec.cs b/src/SignalR/clients/csharp/Client.SourceGenerator/src/gen/ServerHubProxyGenerator.SourceGenerationSpec.cs index cc65423621..37d9b3ff11 100644 --- a/src/SignalR/clients/csharp/Client.SourceGenerator/src/gen/HubServerProxyGenerator.SourceGenerationSpec.cs +++ b/src/SignalR/clients/csharp/Client.SourceGenerator/src/gen/ServerHubProxyGenerator.SourceGenerationSpec.cs @@ -7,7 +7,7 @@ using Microsoft.CodeAnalysis; namespace Microsoft.AspNetCore.SignalR.Client.SourceGenerator; -internal partial class HubServerProxyGenerator +internal partial class ServerHubProxyGenerator { public class SourceGenerationSpec { diff --git a/src/SignalR/clients/csharp/Client.SourceGenerator/src/gen/HubClientProxyGenerator.cs b/src/SignalR/clients/csharp/Client.SourceGenerator/src/gen/ServerHubProxyGenerator.cs index 49797243d0..314b54d5c7 100644 --- a/src/SignalR/clients/csharp/Client.SourceGenerator/src/gen/HubClientProxyGenerator.cs +++ b/src/SignalR/clients/csharp/Client.SourceGenerator/src/gen/ServerHubProxyGenerator.cs @@ -8,7 +8,7 @@ using Microsoft.CodeAnalysis.CSharp.Syntax; namespace Microsoft.AspNetCore.SignalR.Client.SourceGenerator; [Generator] -internal partial class HubClientProxyGenerator : IIncrementalGenerator +internal partial class ServerHubProxyGenerator : IIncrementalGenerator { public void Initialize(IncrementalGeneratorInitializationContext context) { diff --git a/src/SignalR/clients/csharp/Client/test/UnitTests/HubClientProxyGeneratorTests.cs b/src/SignalR/clients/csharp/Client/test/UnitTests/ClientHubGeneratorTests.cs index d656b00c1d..5de049b0ae 100644 --- a/src/SignalR/clients/csharp/Client/test/UnitTests/HubClientProxyGeneratorTests.cs +++ b/src/SignalR/clients/csharp/Client/test/UnitTests/ClientHubGeneratorTests.cs @@ -5,19 +5,13 @@ using Moq; namespace Microsoft.AspNetCore.SignalR.Client.Tests; -[AttributeUsage(AttributeTargets.Method)] -internal class HubClientProxyAttribute : Attribute -{ - -} - internal static partial class RegisterCallbackProviderExtensions { - [HubClientProxy] - public static partial IDisposable SetHubClient<T>(this HubConnection conn, T provider); + [ClientHub] + public static partial IDisposable SetHubClient<T>(this HubConnection conn, T p); } -public class HubClientProxyGeneratorTests +public class ClientHubGeneratorTests { public interface IMyClient { diff --git a/src/SignalR/clients/csharp/Client/test/UnitTests/HubServerProxyGeneratorTests.cs b/src/SignalR/clients/csharp/Client/test/UnitTests/ServerHubProxyGeneratorTests.cs index 4658db2014..c7b51709eb 100644 --- a/src/SignalR/clients/csharp/Client/test/UnitTests/HubServerProxyGeneratorTests.cs +++ b/src/SignalR/clients/csharp/Client/test/UnitTests/ServerHubProxyGeneratorTests.cs @@ -6,19 +6,13 @@ using Moq; namespace Microsoft.AspNetCore.SignalR.Client.Tests; -[AttributeUsage(AttributeTargets.Method)] -internal class HubServerProxyAttribute : Attribute -{ - -} - internal static partial class HubServerProxyExtensions { - [HubServerProxy] + [ServerHubProxy] public static partial T GetHubServer<T>(this HubConnection conn); } -public class HubServerProxyGeneratorTests +public class ServerHubProxyGeneratorTests { public interface IMyHub { |