@@ -30,13 +30,13 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
3030 var attributes = context . CompilationProvider
3131 . Select (
3232 ( 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+ )
4040 ) ;
4141
4242 var createContainersSyntaxProvider = context . SyntaxProvider . CreateSyntaxProvider (
@@ -74,16 +74,22 @@ TypeDeclarationSyntax typeDeclarationSyntax and (ClassDeclarationSyntax or Recor
7474 && typeDeclarationSyntax . Members . OfType < PropertyDeclarationSyntax > ( ) . Any ( z => z . Identifier . Text == "Data" )
7575 && typeDeclarationSyntax . BaseList . Types . Any ( z => z . Type . GetSyntaxName ( ) == "ICanHaveData" ) , ( syntaxContext , _ ) => syntaxContext
7676 ) ;
77-
77+
7878 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 ) ;
8579 context . RegisterSourceOutput ( canBeResolvedSyntaxProvider . Combine ( attributes ) , GenerateCanBeResolvedClass ) ;
8680 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+ // );
8793 }
8894
8995 private void GenerateContainerClass ( SourceProductionContext context , ( GeneratorSyntaxContext syntaxContext , AttributeData attributeData ) valueTuple )
@@ -135,63 +141,6 @@ private void GenerateContainerClass(SourceProductionContext context, (GeneratorS
135141 ) ;
136142 }
137143
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-
195144 private void GenerateCanBeResolvedClass ( SourceProductionContext context , ( GeneratorSyntaxContext syntaxContext , AttributeData attributeData ) valueTuple )
196145 {
197146 var ( syntaxContext , attributeData ) = valueTuple ;
@@ -226,7 +175,7 @@ private static void CreateTypedClass(
226175 INamedTypeSymbol ? generateTypedDataAttributeSymbol ,
227176 INamedTypeSymbol ? generateContainerAttributeSymbol ,
228177 bool includeHandlerIdentity
229- )
178+ )
230179 {
231180 var attribute = typeSymbol ? . GetAttributes ( )
232181 . FirstOrDefault ( z => SymbolEqualityComparer . Default . Equals ( z . AttributeClass , generateTypedDataAttributeSymbol ) ) ;
@@ -295,13 +244,14 @@ bool includeHandlerIdentity
295244 if ( container is { } )
296245 {
297246 var containerName = container is { ConstructorArguments : { Length : > 0 } arguments } ? arguments [ 0 ] . Value as string : null ;
298-
247+
299248 var typedContainer = CreateContainerClass ( typedClass , containerName )
300249 . WithHandlerIdentityConstraint ( includeHandlerIdentity ) ;
301250
302251 var typedArgumentList = TypeArgumentList ( SingletonSeparatedList < TypeSyntax > ( IdentifierName ( "T" ) ) ) ;
303252
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 } ) )
305255 {
306256 typedContainer = typedContainer
307257 . AddMembers (
0 commit comments