Skip to content

Commit

Permalink
Fix/bug with generation (#1340)
Browse files Browse the repository at this point in the history
* maybe test results?!? (#1339)

* Automatically linting code

---------

Co-authored-by: Rocket Understudy <[email protected]>
  • Loading branch information
david-driscoll and rsg-bot authored Nov 27, 2024
1 parent 2a47ed4 commit ee741d4
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 135 deletions.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
namespace Rocket.Surgery.DependencyInjection.Analyzers.AssemblyProviders;
namespace Rocket.Surgery.DependencyInjection.Analyzers.AssemblyProviders;
43 changes: 12 additions & 31 deletions src/DependencyInjection.Analyzers/StatementGeneration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,49 +101,30 @@ string lifetime
)
{
var isServiceTypeAccessible = compilation.IsSymbolAccessibleWithin(serviceType, compilation.Assembly);
var isImplementationTypeAccessible = compilation.IsSymbolAccessibleWithin(implementationType, compilation.Assembly);
return ( isServiceTypeAccessible, serviceTypeExpression, isImplementationTypeAccessible, implementationTypeExpression )
switch
return ( isServiceTypeAccessible, serviceTypeExpression, implementationTypeExpression ) switch
{
(true, TypeOfExpressionSyntax serviceTypeOfExpression, true, TypeOfExpressionSyntax implementationTypeOfExpression)
when serviceType is { IsUnboundGenericType: false } && implementationType is { IsUnboundGenericType: false } => InvocationExpression(
(true, TypeOfExpressionSyntax { Type: { } serviceTypeSyntax }, TypeOfExpressionSyntax { Type: { } implementationTypeSyntax })
when !IsOpenGenericType(serviceType)
&& !IsOpenGenericType(implementationType)
&& compilation.IsSymbolAccessibleWithin(implementationType, compilation.Assembly)
=> InvocationExpression(
MemberAccessExpression(
SyntaxKind.SimpleMemberAccessExpression,
IdentifierName("ServiceDescriptor"),
GenericName(lifetime)
.WithTypeArgumentList(
TypeArgumentList(
SeparatedList(
[
serviceTypeOfExpression.Type,
implementationTypeOfExpression.Type,
]
)
)
)
.WithTypeArgumentList(TypeArgumentList(SeparatedList([serviceTypeSyntax, implementationTypeSyntax])))
)
),
(true, TypeOfExpressionSyntax
{
Type: not GenericNameSyntax { IsUnboundGenericName: true },
} serviceTypeOfExpression, _, not TypeOfExpressionSyntax)
when serviceType is { IsUnboundGenericType: false } => InvocationExpression(
(true, TypeOfExpressionSyntax { Type: { } serviceTypeSyntax }, not TypeOfExpressionSyntax)
when !IsOpenGenericType(serviceType) =>
InvocationExpression(
MemberAccessExpression(
SyntaxKind.SimpleMemberAccessExpression,
IdentifierName("ServiceDescriptor"),
GenericName(lifetime)
.WithTypeArgumentList(TypeArgumentList(SeparatedList([serviceTypeOfExpression.Type])))
GenericName(lifetime).WithTypeArgumentList(TypeArgumentList(SeparatedList([serviceTypeSyntax])))
)
)
.WithArgumentList(
ArgumentList(
SeparatedList(
[
Argument(implementationTypeExpression),
]
)
)
),
.WithArgumentList(ArgumentList(SeparatedList([Argument(implementationTypeExpression)]))),
_ => InvocationExpression(
MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, IdentifierName("ServiceDescriptor"), IdentifierName(lifetime))
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Microsoft.Extensions.DependencyInjection.IServiceCollection ICompiledTypeProvide
// FilePath: Input0.cs Expression: jwpZbvlWPFRLk7VHxDXpyQ==
case 12:
services.Add(ServiceDescriptor.Scoped(RootDependencyProject.GetType("RootDependencyProject.Service`1"), RootDependencyProject.GetType("RootDependencyProject.Service`1")));
services.Add(ServiceDescriptor.Scoped<global::RootDependencyProject.IService<>>(RootDependencyProject.GetType("RootDependencyProject.Service`1")));
services.Add(ServiceDescriptor.Scoped(typeof(global::RootDependencyProject.IService<>), RootDependencyProject.GetType("RootDependencyProject.Service`1")));
break;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,38 +1,5 @@
{
FinalDiagnostics: [
{
Id: CS7003,
Title: ,
Severity: Error,
WarningLevel: 0,
Location: Rocket.Surgery.DependencyInjection.Analyzers/Rocket.Surgery.DependencyInjection.Analyzers.CompiledServiceScanningGenerator/Compiled_AssemblyProvider.g.cs: (32,84)-(32,94),
HelpLink: https://msdn.microsoft.com/query/roslyn.query?appId=roslyn&k=k(CS7003),
MessageFormat: Unexpected use of an unbound generic name,
Message: Unexpected use of an unbound generic name,
Category: Compiler,
CustomTags: [
Compiler,
Telemetry,
NotConfigurable
]
},
{
Id: CS1503,
Title: ,
Severity: Error,
WarningLevel: 0,
Location: Rocket.Surgery.DependencyInjection.Analyzers/Rocket.Surgery.DependencyInjection.Analyzers.CompiledServiceScanningGenerator/Compiled_AssemblyProvider.g.cs: (32,96)-(32,160),
HelpLink: https://msdn.microsoft.com/query/roslyn.query?appId=roslyn&k=k(CS1503),
MessageFormat: Argument {0}: cannot convert from '{1}' to '{2}',
Message: Argument 1: cannot convert from 'System.Type' to 'System.Func<System.IServiceProvider, RootDependencyProject.IService<T>>',
Category: Compiler,
CustomTags: [
Compiler,
Telemetry,
NotConfigurable
]
}
],
FinalDiagnostics: [],
GeneratorDiagnostics: {
Rocket.Surgery.DependencyInjection.Analyzers.CompiledServiceScanningGenerator: []
},
Expand All @@ -47,5 +14,17 @@
System.dll,
System.Private.CoreLib.dll,
System.Runtime.dll
],
Services: [
{
Lifetime: Scoped,
ServiceType: RootDependencyProject.Service`1,
ImplementationType: RootDependencyProject.Service`1
},
{
Lifetime: Scoped,
ServiceType: RootDependencyProject.IService`1,
ImplementationType: RootDependencyProject.Service`1
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ Microsoft.Extensions.DependencyInjection.IServiceCollection ICompiledTypeProvide
{
// FilePath: Input0.cs Expression: moR0aszucgKYmnqmVn/i6g==
case 21:
services.Add(ServiceDescriptor.Scoped<global::Service<>, global::Service<>>());
services.Add(ServiceDescriptor.Scoped<global::IService<>, global::Service<>>());
services.Add(ServiceDescriptor.Scoped(typeof(global::Service<>), typeof(global::Service<>)));
services.Add(ServiceDescriptor.Scoped(typeof(global::IService<>), typeof(global::Service<>)));
break;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,70 +1,5 @@
{
FinalDiagnostics: [
{
Id: CS7003,
Title: ,
Severity: Error,
WarningLevel: 0,
Location: Rocket.Surgery.DependencyInjection.Analyzers/Rocket.Surgery.DependencyInjection.Analyzers.CompiledServiceScanningGenerator/Compiled_AssemblyProvider.g.cs: (30,62)-(30,71),
HelpLink: https://msdn.microsoft.com/query/roslyn.query?appId=roslyn&k=k(CS7003),
MessageFormat: Unexpected use of an unbound generic name,
Message: Unexpected use of an unbound generic name,
Category: Compiler,
CustomTags: [
Compiler,
Telemetry,
NotConfigurable
]
},
{
Id: CS7003,
Title: ,
Severity: Error,
WarningLevel: 0,
Location: Rocket.Surgery.DependencyInjection.Analyzers/Rocket.Surgery.DependencyInjection.Analyzers.CompiledServiceScanningGenerator/Compiled_AssemblyProvider.g.cs: (30,81)-(30,90),
HelpLink: https://msdn.microsoft.com/query/roslyn.query?appId=roslyn&k=k(CS7003),
MessageFormat: Unexpected use of an unbound generic name,
Message: Unexpected use of an unbound generic name,
Category: Compiler,
CustomTags: [
Compiler,
Telemetry,
NotConfigurable
]
},
{
Id: CS7003,
Title: ,
Severity: Error,
WarningLevel: 0,
Location: Rocket.Surgery.DependencyInjection.Analyzers/Rocket.Surgery.DependencyInjection.Analyzers.CompiledServiceScanningGenerator/Compiled_AssemblyProvider.g.cs: (31,62)-(31,72),
HelpLink: https://msdn.microsoft.com/query/roslyn.query?appId=roslyn&k=k(CS7003),
MessageFormat: Unexpected use of an unbound generic name,
Message: Unexpected use of an unbound generic name,
Category: Compiler,
CustomTags: [
Compiler,
Telemetry,
NotConfigurable
]
},
{
Id: CS7003,
Title: ,
Severity: Error,
WarningLevel: 0,
Location: Rocket.Surgery.DependencyInjection.Analyzers/Rocket.Surgery.DependencyInjection.Analyzers.CompiledServiceScanningGenerator/Compiled_AssemblyProvider.g.cs: (31,82)-(31,91),
HelpLink: https://msdn.microsoft.com/query/roslyn.query?appId=roslyn&k=k(CS7003),
MessageFormat: Unexpected use of an unbound generic name,
Message: Unexpected use of an unbound generic name,
Category: Compiler,
CustomTags: [
Compiler,
Telemetry,
NotConfigurable
]
}
],
FinalDiagnostics: [],
GeneratorDiagnostics: {
Rocket.Surgery.DependencyInjection.Analyzers.CompiledServiceScanningGenerator: []
},
Expand All @@ -78,5 +13,17 @@
System.dll,
System.Private.CoreLib.dll,
System.Runtime.dll
],
Services: [
{
Lifetime: Scoped,
ServiceType: Service`1,
ImplementationType: Service`1
},
{
Lifetime: Scoped,
ServiceType: IService`1,
ImplementationType: Service`1
}
]
}

0 comments on commit ee741d4

Please sign in to comment.