You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Diagnose duplicate representations of @AlternateRepresentation
If an `@AlternateRepresentation` clashes with already available source languages, this will now be reported as diagnostics.
These diagnostics are performed in the final stage of registering a bundle, during the global analysis of the topic graph, where all nodes are available and all links will have been resolved. This is so that we have all the information we need for detecting duplicates.
The following cases are detected:
- if the symbol the alternate representation is being defined for (the "original" symbol) was already available in one of the languages the counterpart symbol is available in
- if the alternate representations have duplicate source languages in common, i.e. if counterpart1 is available in Objective-C and counterpart2 is **also** available in Objective-C.
Suggestions will be provided depending on context:
- which languages are duplicate
- all the languages the symbol is already available in will be available as part of the diagnostic explanation
- if the `@AlternateRepresentation` directive is a duplicate, a suggestion will be made to remove it, with a suitable replacement
- if the `@AlternateRepresentation` directive is a duplicate, a note pointing to the original directive will be added
Example diagnostics:
```
warning: An alternate representation for Swift already exists
This node is already available in Swift and Objective-C.
SynonymSample.docc/SymbolExtension2.md:4:5: An alternate representation for Swift has already been defined by an @AlternateRepresentation directive.
--> SynonymSample.docc/SymbolExtension2.md:5:5-5:57
3 | @metadata {
4 | @AlternateRepresentation(``Synonyms/Synonym-5zxmc``)
5 + @AlternateRepresentation(``Synonyms/Synonym-5zxmc``)
| ╰─suggestion: Remove this alternate representation
6 | }
7 |
```
```
warning: This node already has a representation in Swift
This node is already available in Swift.
--> SynonymSample.docc/SynonymExtension.md:5:5-5:56
3 | @metadata {
4 | @AlternateRepresentation(``Synonyms/Synonym-1wqxt``)
5 + @AlternateRepresentation(``Synonyms/OtherSynonym``)
| ╰─suggestion: Replace the counterpart link with a node which isn't available in Swift
6 | }
7 |
```
summary:"\(entity.name.plainText.singleQuoted) already has a representation in \(listSourceLanguages(duplicateSourceLanguages))",
3245
+
explanation:"Symbols can only specify custom alternate language representations for languages that the documented symbol doesn't already have a representation for."
3246
+
),
3247
+
possibleSolutions:[Solution(summary:"Replace this alternate language representation with a symbol which isn't available in \(listSourceLanguages(entity.availableSourceLanguages))", replacements:[])]
XCTAssertEqual(problem.diagnostic.summary,"'SwiftSymbol' already has a representation in Swift")
5487
+
XCTAssertEqual(problem.diagnostic.explanation,"Symbols can only specify custom alternate language representations for languages that the documented symbol doesn't already have a representation for.")
5488
+
XCTAssertEqual(problem.possibleSolutions.count,1)
5489
+
5490
+
// Verify solutions provide context, but no replacements
0 commit comments