Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/IceRpc.ServiceGenerator/Internal/Parser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ internal IReadOnlyList<ServiceClass> GetServiceDefinitions(IEnumerable<ClassDecl
}

var serviceDefinitions = new List<ServiceClass>();
// Multiple partial declarations of the same class with [Service] applied to more than one part each yield
// their own ClassDeclarationSyntax from ForAttributeWithMetadataName. Process each class symbol once so we
// don't AddSource the same hint name twice.
var seenClassSymbols = new HashSet<INamedTypeSymbol>(SymbolEqualityComparer.Default);
// we enumerate by syntax tree, to minimize the need to instantiate semantic models (since they're expensive)
foreach (IGrouping<SyntaxTree, ClassDeclarationSyntax> group in classes.GroupBy(x => x.SyntaxTree))
{
Expand All @@ -53,7 +57,7 @@ internal IReadOnlyList<ServiceClass> GetServiceDefinitions(IEnumerable<ClassDecl

SemanticModel semanticModel = _compilation.GetSemanticModel(classDeclaration.SyntaxTree);
INamedTypeSymbol? classSymbol = semanticModel.GetDeclaredSymbol(classDeclaration, _cancellationToken);
if (classSymbol is null)
if (classSymbol is null || !seenClassSymbols.Add(classSymbol))
Comment on lines 49 to +60
{
continue;
}
Expand Down
Loading