Skip to content
This repository has been archived by the owner on Jun 1, 2023. It is now read-only.

Commit

Permalink
Add resolution for nested types through typealiases
Browse files Browse the repository at this point in the history
  • Loading branch information
mattt committed Apr 23, 2021
1 parent 099ac58 commit bac46a1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
13 changes: 11 additions & 2 deletions Sources/SwiftDoc/Interface.swift
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,19 @@ public final class Interface {
let `typealias` = symbol.api as? Typealias,
let initializedType = `typealias`.initializedType
{
pathComponents = (symbol.context.compactMap { ($0 as? Symbol)?.name ?? ($0 as? Extension)?.extendedType }) + [initializedType]
let initializedTypePathComponents = initializedType.split(separator: ".")
let candidates = symbolsGroupedByIdentifier.keys
.filter { $0.name == initializedType }
.filter { $0.pathComponents.count <= initializedTypePathComponents.count }
if let id = candidates.max(by: { $0.pathComponents.count > $1.pathComponents.count }) {
pathComponents = id.pathComponents + CollectionOfOne(id.name)
} else {
return []
}
}
}

return symbolsGroupedByQualifiedName[pathComponents.joined(separator: ".")] ?? []
let path = pathComponents.joined(separator: ".")
return symbolsGroupedByQualifiedName[path] ?? []
}
}
10 changes: 10 additions & 0 deletions Tests/SwiftDocTests/InterfaceTypeTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,10 @@ final class InterfaceTypeTests: XCTestCase {
}
public typealias MyClass = SomeClass
public class AnotherClass {
typealias PublicClass = SomeClass
}
public typealias ExternalClass = UIGestureRecognizer
"""#
Expand All @@ -306,6 +310,12 @@ final class InterfaceTypeTests: XCTestCase {
XCTAssertEqual(module.interface.symbols(named: "MyClass.InnerObject", resolvingTypealiases: true).first?.name, "InnerObject")
XCTAssertNil(module.interface.symbols(named: "MyClass.InnerObject", resolvingTypealiases: false).first)

XCTAssertEqual(module.interface.symbols(named: "AnotherClass.PublicClass", resolvingTypealiases: true).first?.name, "SomeClass")
XCTAssertTrue(module.interface.symbols(named: "AnotherClass.PublicClass", resolvingTypealiases: false).first?.api is Typealias)

XCTAssertEqual(module.interface.symbols(named: "AnotherClass.PublicClass.ActuallyInternal", resolvingTypealiases: true).first?.name, "InnerStruct")
XCTAssertNil(module.interface.symbols(named: "AnotherClass.PublicClass.ActuallyInternal", resolvingTypealiases: false).first)

XCTAssertNil(module.interface.symbols(named: "ExternalClass", resolvingTypealiases: true).first)
XCTAssertTrue(module.interface.symbols(named: "ExternalClass", resolvingTypealiases: false).first?.api is Typealias)

Expand Down

0 comments on commit bac46a1

Please sign in to comment.