@@ -1295,7 +1295,7 @@ public class DocumentationContext: DocumentationContextDataProviderDelegate {
1295
1295
/// A tree of the symbol hierarchy as defined by the combined symbol graph.
1296
1296
var symbolsURLHierarchy = BidirectionalTree < ResolvedTopicReference > ( root: bundle. documentationRootReference)
1297
1297
/// We need only unique relationships so we'll collect them in a set.
1298
- var combinedRelationships = Set < SymbolGraph . Relationship > ( )
1298
+ var combinedRelationships = [ UnifiedSymbolGraph . Selector : Set < SymbolGraph . Relationship > ] ( )
1299
1299
/// Collect symbols from all symbol graphs.
1300
1300
var combinedSymbols = [ String: UnifiedSymbolGraph . Symbol] ( )
1301
1301
@@ -1372,13 +1372,20 @@ public class DocumentationContext: DocumentationContextDataProviderDelegate {
1372
1372
addSymbolsToTopicGraph ( symbolGraph: unifiedSymbolGraph, url: fileURL, symbolReferences: symbolReferences, moduleReference: moduleReference, bundle: bundle)
1373
1373
1374
1374
// For inherited symbols we remove the source docs (if inheriting docs is disabled) before creating their documentation nodes.
1375
- for relationship in unifiedSymbolGraph. relationships {
1376
- // Check for an origin key.
1377
- if relationship. mixins [ SymbolGraph . Relationship. SourceOrigin. mixinKey] != nil
1378
- // Check if it's a memberOf or implementation relationship.
1379
- && ( relationship. kind == . memberOf || relationship. kind == . defaultImplementationOf) {
1380
-
1381
- SymbolGraphRelationshipsBuilder . addInheritedDefaultImplementation ( edge: relationship, context: self , symbolIndex: & symbolIndex, engine: diagnosticEngine)
1375
+ for (_, relationships) in unifiedSymbolGraph. relationshipsByLanguage {
1376
+ for relationship in relationships {
1377
+ // Check for an origin key.
1378
+ if relationship. mixins [ SymbolGraph . Relationship. SourceOrigin. mixinKey] != nil
1379
+ // Check if it's a memberOf or implementation relationship.
1380
+ && ( relationship. kind == . memberOf || relationship. kind == . defaultImplementationOf) {
1381
+
1382
+ SymbolGraphRelationshipsBuilder . addInheritedDefaultImplementation (
1383
+ edge: relationship,
1384
+ context: self ,
1385
+ symbolIndex: & symbolIndex,
1386
+ engine: diagnosticEngine
1387
+ )
1388
+ }
1382
1389
}
1383
1390
}
1384
1391
@@ -1409,33 +1416,45 @@ public class DocumentationContext: DocumentationContextDataProviderDelegate {
1409
1416
1410
1417
// Collect symbols and relationships
1411
1418
combinedSymbols. merge ( unifiedSymbolGraph. symbols, uniquingKeysWith: { $1 } )
1412
- combinedRelationships. formUnion ( unifiedSymbolGraph. relationships)
1419
+
1420
+ for (selector, relationships) in unifiedSymbolGraph. relationshipsByLanguage {
1421
+ combinedRelationships [ selector, default: [ ] ] . formUnion ( relationships)
1422
+ }
1423
+
1424
+ // Keep track of relationships that refer to symbols that are absent from the symbol graph, so that
1425
+ // we can diagnose them.
1426
+ combinedRelationships [
1427
+ . init( interfaceLanguage: " unknown " , platform: nil ) ,
1428
+ default: [ ]
1429
+ ] . formUnion ( unifiedSymbolGraph. orphanRelationships)
1413
1430
}
1414
1431
1415
1432
try shouldContinueRegistration ( )
1416
-
1417
- // Add parent <-> child edges to the URL tree
1418
- try combinedRelationships
1419
- . compactMap ( parentChildRelationship ( from: ) )
1420
- . sorted ( by: Self . sortRelationshipsPreOrder)
1421
- . forEach ( { pair in
1422
- // Add the relationship to the URL hierarchy
1423
- let ( parentRef, childRef) = pair
1424
- // If the unique reference already exists, it's been added by another symbol graph
1425
- // likely built for a different target platform, ignore it as it's the exact same symbol.
1426
- if ( try ? symbolsURLHierarchy. parent ( of: childRef) ) == nil {
1427
- do {
1428
- try symbolsURLHierarchy. add ( childRef, parent: parentRef)
1429
- } catch let error as BidirectionalTree < ResolvedTopicReference > . Error {
1430
- switch error {
1431
- // Some parents might not exist if they are types from other frameworks and
1432
- // those are not pulled into and available in the current symbol graph.
1433
- case . nodeNotFound: break
1434
- default : throw error
1433
+
1434
+ for (_, relationships) in combinedRelationships {
1435
+ // Add parent <-> child edges to the URL tree
1436
+ try relationships
1437
+ . compactMap ( parentChildRelationship ( from: ) )
1438
+ . sorted ( by: Self . sortRelationshipsPreOrder)
1439
+ . forEach ( { pair in
1440
+ // Add the relationship to the URL hierarchy
1441
+ let ( parentRef, childRef) = pair
1442
+ // If the unique reference already exists, it's been added by another symbol graph
1443
+ // likely built for a different target platform, ignore it as it's the exact same symbol.
1444
+ if ( try ? symbolsURLHierarchy. parent ( of: childRef) ) == nil {
1445
+ do {
1446
+ try symbolsURLHierarchy. add ( childRef, parent: parentRef)
1447
+ } catch let error as BidirectionalTree < ResolvedTopicReference > . Error {
1448
+ switch error {
1449
+ // Some parents might not exist if they are types from other frameworks and
1450
+ // those are not pulled into and available in the current symbol graph.
1451
+ case . nodeNotFound: break
1452
+ default : throw error
1453
+ }
1435
1454
}
1436
1455
}
1437
- }
1438
- } )
1456
+ } )
1457
+ }
1439
1458
1440
1459
// Update the children of collision URLs. Walk the tree and update any dependents of updated URLs
1441
1460
for moduleReference in moduleReferences. values {
@@ -1445,7 +1464,14 @@ public class DocumentationContext: DocumentationContextDataProviderDelegate {
1445
1464
}
1446
1465
1447
1466
// Create inherited API collections
1448
- try GeneratedDocumentationTopics . createInheritedSymbolsAPICollections ( relationships: combinedRelationships, symbolsURLHierarchy: & symbolsURLHierarchy, context: self , bundle: bundle)
1467
+ for (_, relationships) in combinedRelationships {
1468
+ try GeneratedDocumentationTopics . createInheritedSymbolsAPICollections (
1469
+ relationships: relationships,
1470
+ symbolsURLHierarchy: & symbolsURLHierarchy,
1471
+ context: self ,
1472
+ bundle: bundle
1473
+ )
1474
+ }
1449
1475
1450
1476
// Parse and prepare the nodes' content concurrently.
1451
1477
let updatedNodes : [ ( node: DocumentationNode , matchedArticleURL: URL ? ) ] = Array ( symbolIndex. values)
@@ -1487,8 +1513,10 @@ public class DocumentationContext: DocumentationContextDataProviderDelegate {
1487
1513
// Look up and add symbols that are _referenced_ in the symbol graph but don't exist in the symbol graph.
1488
1514
try resolveExternalSymbols ( in: combinedSymbols, relationships: combinedRelationships)
1489
1515
1490
- // Build relationships in the completed graph
1491
- buildRelationships ( combinedRelationships, bundle: bundle, engine: diagnosticEngine)
1516
+ for (selector, relationships) in combinedRelationships {
1517
+ // Build relationships in the completed graph
1518
+ buildRelationships ( relationships, selector: selector, bundle: bundle, engine: diagnosticEngine)
1519
+ }
1492
1520
1493
1521
// Index references
1494
1522
referencesIndex. removeAll ( )
@@ -1569,32 +1597,70 @@ public class DocumentationContext: DocumentationContextDataProviderDelegate {
1569
1597
///
1570
1598
/// ## See Also
1571
1599
/// - ``SymbolGraphRelationshipsBuilder``
1572
- func buildRelationships( _ relationships: Set < SymbolGraph . Relationship > , bundle: DocumentationBundle , engine: DiagnosticEngine ) {
1600
+ func buildRelationships(
1601
+ _ relationships: Set < SymbolGraph . Relationship > ,
1602
+ selector: UnifiedSymbolGraph . Selector ,
1603
+ bundle: DocumentationBundle ,
1604
+ engine: DiagnosticEngine
1605
+ ) {
1573
1606
for edge in relationships {
1574
1607
switch edge. kind {
1575
1608
case . conformsTo:
1576
1609
// Build conformant type <-> protocol relationships
1577
- SymbolGraphRelationshipsBuilder . addConformanceRelationship ( edge: edge, in: bundle, symbolIndex: & symbolIndex, engine: diagnosticEngine)
1610
+ SymbolGraphRelationshipsBuilder . addConformanceRelationship (
1611
+ edge: edge,
1612
+ selector: selector,
1613
+ in: bundle,
1614
+ symbolIndex: & symbolIndex,
1615
+ engine: diagnosticEngine
1616
+ )
1578
1617
case . defaultImplementationOf:
1579
1618
// Build implementation <-> protocol requirement relationships.
1580
- SymbolGraphRelationshipsBuilder . addImplementationRelationship ( edge: edge, in: bundle, context: self , symbolIndex: & symbolIndex, engine: diagnosticEngine)
1619
+ SymbolGraphRelationshipsBuilder . addImplementationRelationship (
1620
+ edge: edge,
1621
+ selector: selector,
1622
+ in: bundle,
1623
+ context: self ,
1624
+ symbolIndex: & symbolIndex, engine: diagnosticEngine
1625
+ )
1581
1626
case . inheritsFrom:
1582
1627
// Build ancestor <-> offspring relationships.
1583
- SymbolGraphRelationshipsBuilder . addInheritanceRelationship ( edge: edge, in: bundle, symbolIndex: & symbolIndex, engine: diagnosticEngine)
1628
+ SymbolGraphRelationshipsBuilder . addInheritanceRelationship (
1629
+ edge: edge,
1630
+ selector: selector,
1631
+ in: bundle,
1632
+ symbolIndex: & symbolIndex,
1633
+ engine: diagnosticEngine
1634
+ )
1584
1635
case . requirementOf:
1585
1636
// Build required member -> protocol relationships.
1586
- SymbolGraphRelationshipsBuilder . addRequirementRelationship ( edge: edge, in: bundle, symbolIndex: & symbolIndex, engine: diagnosticEngine)
1637
+ SymbolGraphRelationshipsBuilder . addRequirementRelationship (
1638
+ edge: edge,
1639
+ selector: selector,
1640
+ in: bundle,
1641
+ symbolIndex: & symbolIndex,
1642
+ engine: diagnosticEngine
1643
+ )
1587
1644
case . optionalRequirementOf:
1588
1645
// Build optional required member -> protocol relationships.
1589
- SymbolGraphRelationshipsBuilder . addOptionalRequirementRelationship ( edge: edge, in: bundle, symbolIndex: & symbolIndex, engine: diagnosticEngine)
1646
+ SymbolGraphRelationshipsBuilder . addOptionalRequirementRelationship (
1647
+ edge: edge,
1648
+ selector: selector,
1649
+ in: bundle,
1650
+ symbolIndex: & symbolIndex,
1651
+ engine: diagnosticEngine
1652
+ )
1590
1653
default :
1591
1654
break
1592
1655
}
1593
1656
}
1594
1657
}
1595
1658
1596
1659
/// Look up and add symbols that are _referenced_ in the symbol graph but don't exist in the symbol graph, using an `externalSymbolResolver` (if not `nil`).
1597
- func resolveExternalSymbols( in symbols: [ String : UnifiedSymbolGraph . Symbol ] , relationships: Set < SymbolGraph . Relationship > ) throws {
1660
+ func resolveExternalSymbols(
1661
+ in symbols: [ String : UnifiedSymbolGraph . Symbol ] ,
1662
+ relationships: [ UnifiedSymbolGraph . Selector : Set < SymbolGraph . Relationship > ]
1663
+ ) throws {
1598
1664
guard let symbolResolver = externalSymbolResolver else {
1599
1665
return
1600
1666
}
@@ -1604,8 +1670,10 @@ public class DocumentationContext: DocumentationContextDataProviderDelegate {
1604
1670
1605
1671
// Add all the symbols that are the target of a relationship. These could for example be protocols that are being conformed to,
1606
1672
// classes that are being subclassed, or methods that are being overridden.
1607
- for edge in relationships where symbolIndex [ edge. target] == nil {
1608
- symbolsToResolve. insert ( edge. target)
1673
+ for (_, relationships) in relationships {
1674
+ for edge in relationships where symbolIndex [ edge. target] == nil {
1675
+ symbolsToResolve. insert ( edge. target)
1676
+ }
1609
1677
}
1610
1678
1611
1679
// Add all the types that are referenced in a declaration. These could for example be the type of an argument or return value.
0 commit comments