@@ -30,13 +30,13 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
30
30
var attributes = context . CompilationProvider
31
31
. Select (
32
32
( compilation , _ ) => new AttributeData (
33
- compilation . GetTypeByMetadataName (
34
- "OmniSharp.Extensions.LanguageServer.Protocol.Generation.GenerateTypedDataAttribute"
35
- ) ! ,
36
- compilation . GetTypeByMetadataName (
37
- "OmniSharp.Extensions.LanguageServer.Protocol.Generation.GenerateContainerAttribute"
38
- ) !
39
- )
33
+ compilation . GetTypeByMetadataName (
34
+ "OmniSharp.Extensions.LanguageServer.Protocol.Generation.GenerateTypedDataAttribute"
35
+ ) ! ,
36
+ compilation . GetTypeByMetadataName (
37
+ "OmniSharp.Extensions.LanguageServer.Protocol.Generation.GenerateContainerAttribute"
38
+ ) !
39
+ )
40
40
) ;
41
41
42
42
var createContainersSyntaxProvider = context . SyntaxProvider . CreateSyntaxProvider (
@@ -74,16 +74,22 @@ TypeDeclarationSyntax typeDeclarationSyntax and (ClassDeclarationSyntax or Recor
74
74
&& typeDeclarationSyntax . Members . OfType < PropertyDeclarationSyntax > ( ) . Any ( z => z . Identifier . Text == "Data" )
75
75
&& typeDeclarationSyntax . BaseList . Types . Any ( z => z . Type . GetSyntaxName ( ) == "ICanHaveData" ) , ( syntaxContext , _ ) => syntaxContext
76
76
) ;
77
-
77
+
78
78
context . RegisterSourceOutput ( createContainersSyntaxProvider . Combine ( attributes ) , GenerateContainerClass ) ;
79
- context . RegisterSourceOutput ( typedParamsCandidatesSyntaxProvider
80
- . Combine ( canBeResolvedSyntaxProvider . Select ( ( z , _ ) => ( TypeDeclarationSyntax ) z . Node ) . Collect ( ) )
81
- . Combine ( canHaveDataSyntaxProvider . Select ( ( z , _ ) => ( TypeDeclarationSyntax ) z . Node ) . Collect ( ) )
82
- . Combine ( createContainersSyntaxProvider . Select ( ( z , _ ) => ( TypeDeclarationSyntax ) z . Node ) . Collect ( ) )
83
- . Select ( ( tuple , token ) => ( candidate : tuple . Left . Left . Left , resolvedItems : tuple . Left . Left . Right . Concat ( tuple . Left . Right ) . Concat ( tuple . Right ) . ToImmutableArray ( ) ) ) ,
84
- GenerateTypedParams ) ;
85
79
context . RegisterSourceOutput ( canBeResolvedSyntaxProvider . Combine ( attributes ) , GenerateCanBeResolvedClass ) ;
86
80
context . RegisterSourceOutput ( canHaveDataSyntaxProvider . Combine ( attributes ) , GenerateCanHaveDataClass ) ;
81
+ // TODO: Add support for generating handler methods and interfaces that take in the strongly typed data.
82
+ // context.RegisterSourceOutput(
83
+ // typedParamsCandidatesSyntaxProvider
84
+ // .Combine(canBeResolvedSyntaxProvider.Select((z, _) => (TypeDeclarationSyntax)z.Node).Collect())
85
+ // .Combine(canHaveDataSyntaxProvider.Select((z, _) => (TypeDeclarationSyntax)z.Node).Collect())
86
+ // .Combine(createContainersSyntaxProvider.Select((z, _) => (TypeDeclarationSyntax)z.Node).Collect())
87
+ // .Select(
88
+ // (tuple, token) => ( candidate: tuple.Left.Left.Left,
89
+ // resolvedItems: tuple.Left.Left.Right.Concat(tuple.Left.Right).Concat(tuple.Right).ToImmutableArray() )
90
+ // ),
91
+ // GenerateTypedParams
92
+ // );
87
93
}
88
94
89
95
private void GenerateContainerClass ( SourceProductionContext context , ( GeneratorSyntaxContext syntaxContext , AttributeData attributeData ) valueTuple )
@@ -135,63 +141,6 @@ private void GenerateContainerClass(SourceProductionContext context, (GeneratorS
135
141
) ;
136
142
}
137
143
138
- private void GenerateTypedParams ( SourceProductionContext context , ( GeneratorSyntaxContext syntaxContext , ImmutableArray < TypeDeclarationSyntax > resolvedItems ) valueTuple )
139
- {
140
- var ( syntaxContext , resolvedItems ) = valueTuple ;
141
- var classToContain = ( TypeDeclarationSyntax ) syntaxContext . Node ;
142
- var typeSymbol = syntaxContext . SemanticModel . GetDeclaredSymbol ( classToContain ) ;
143
-
144
- if ( typeSymbol == null ) return ;
145
- var handlerInterface = typeSymbol . AllInterfaces . FirstOrDefault ( z => z . Name == "IRequest" && z . Arity == 1 ) ;
146
- if ( handlerInterface is null ) return ;
147
- var responseSymbol = handlerInterface ? . TypeArguments [ 0 ] ;
148
-
149
- var isTyped = resolvedItems
150
- . Any (
151
- item =>
152
- {
153
- var symbol = syntaxContext . SemanticModel . GetDeclaredSymbol ( item ) ;
154
- return symbol is not null && SymbolEqualityComparer . Default . Equals ( responseSymbol , symbol ) ;
155
- }
156
- ) ;
157
-
158
- // TODO: Start here to finish creating strongly typed params
159
- var paramsType = CreateContainerClass ( classToContain , containerName )
160
- . AddAttributeLists (
161
- AttributeList (
162
- SeparatedList (
163
- new [ ]
164
- {
165
- Attribute ( ParseName ( "System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute" ) ) ,
166
- Attribute ( ParseName ( "System.Runtime.CompilerServices.CompilerGeneratedAttribute" ) )
167
- }
168
- )
169
- )
170
- ) ;
171
-
172
- var cu = CompilationUnit ( )
173
- . WithUsings ( classToContain . SyntaxTree . GetCompilationUnitRoot ( ) . Usings )
174
- . AddMembers (
175
- NamespaceDeclaration ( ParseName ( typeSymbol . ContainingNamespace . ToDisplayString ( ) ) )
176
- . AddMembers ( container )
177
- . WithLeadingTrivia ( TriviaList ( Trivia ( NullableDirectiveTrivia ( Token ( SyntaxKind . EnableKeyword ) , true ) ) ) )
178
- . WithTrailingTrivia ( TriviaList ( Trivia ( NullableDirectiveTrivia ( Token ( SyntaxKind . RestoreKeyword ) , true ) ) ) )
179
- ) ;
180
-
181
- foreach ( var ns in RequiredUsings )
182
- {
183
- if ( cu . Usings . All ( z => z . Name . ToFullString ( ) != ns ) )
184
- {
185
- cu = cu . AddUsings ( UsingDirective ( ParseName ( ns ) ) ) ;
186
- }
187
- }
188
-
189
- context . AddSource (
190
- $ "{ containerName ?? classToContain . Identifier . Text + "Container" } .cs",
191
- cu . NormalizeWhitespace ( ) . GetText ( Encoding . UTF8 )
192
- ) ;
193
- }
194
-
195
144
private void GenerateCanBeResolvedClass ( SourceProductionContext context , ( GeneratorSyntaxContext syntaxContext , AttributeData attributeData ) valueTuple )
196
145
{
197
146
var ( syntaxContext , attributeData ) = valueTuple ;
@@ -226,7 +175,7 @@ private static void CreateTypedClass(
226
175
INamedTypeSymbol ? generateTypedDataAttributeSymbol ,
227
176
INamedTypeSymbol ? generateContainerAttributeSymbol ,
228
177
bool includeHandlerIdentity
229
- )
178
+ )
230
179
{
231
180
var attribute = typeSymbol ? . GetAttributes ( )
232
181
. FirstOrDefault ( z => SymbolEqualityComparer . Default . Equals ( z . AttributeClass , generateTypedDataAttributeSymbol ) ) ;
@@ -295,13 +244,14 @@ bool includeHandlerIdentity
295
244
if ( container is { } )
296
245
{
297
246
var containerName = container is { ConstructorArguments : { Length : > 0 } arguments } ? arguments [ 0 ] . Value as string : null ;
298
-
247
+
299
248
var typedContainer = CreateContainerClass ( typedClass , containerName )
300
249
. WithHandlerIdentityConstraint ( includeHandlerIdentity ) ;
301
250
302
251
var typedArgumentList = TypeArgumentList ( SingletonSeparatedList < TypeSyntax > ( IdentifierName ( "T" ) ) ) ;
303
252
304
- if ( ! ( container is { NamedArguments : { Length : > 0 } namedArguments } && namedArguments . FirstOrDefault ( z => z . Key == "GenerateImplicitConversion" ) is { Value . Value : false } ) )
253
+ if ( ! ( container is { NamedArguments : { Length : > 0 } namedArguments }
254
+ && namedArguments . FirstOrDefault ( z => z . Key == "GenerateImplicitConversion" ) is { Value . Value : false } ) )
305
255
{
306
256
typedContainer = typedContainer
307
257
. AddMembers (
0 commit comments