From 4982b02d40b6fbe5483a03171648201b5bfa524b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20St=C3=BChrk?= Date: Thu, 18 Mar 2021 20:15:07 +0100 Subject: [PATCH 1/4] Don't link to not included symbols in the Relationships section. --- Sources/swift-doc/Extensions/SwiftDoc+Extensions.swift | 6 +++--- .../Supporting Types/Components/Relationships.swift | 6 ++++-- Sources/swift-doc/Supporting Types/Pages/TypePage.swift | 4 ++-- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/Sources/swift-doc/Extensions/SwiftDoc+Extensions.swift b/Sources/swift-doc/Extensions/SwiftDoc+Extensions.swift index fac1bcd4..f7bd046a 100644 --- a/Sources/swift-doc/Extensions/SwiftDoc+Extensions.swift +++ b/Sources/swift-doc/Extensions/SwiftDoc+Extensions.swift @@ -36,13 +36,13 @@ extension Symbol { return node } - func graph(in module: Module, baseURL: String) -> Graph { + func graph(in module: Module, baseURL: String, symbolFilter: (Symbol) -> Bool) -> Graph { var graph = Graph(directed: true) do { var node = self.node - if !(api is Unknown) { + if !(api is Unknown) && symbolFilter(self) { node.href = path(for: self, with: baseURL) } @@ -61,7 +61,7 @@ extension Symbol { guard self != symbol else { continue } var node = symbol.node - if !(symbol.api is Unknown) { + if !(symbol.api is Unknown) && symbolFilter(symbol) { node.href = path(for: symbol, with: baseURL) } graph.append(node) diff --git a/Sources/swift-doc/Supporting Types/Components/Relationships.swift b/Sources/swift-doc/Supporting Types/Components/Relationships.swift index 8febf849..a68f0113 100644 --- a/Sources/swift-doc/Supporting Types/Components/Relationships.swift +++ b/Sources/swift-doc/Supporting Types/Components/Relationships.swift @@ -30,16 +30,18 @@ struct Relationships: Component { var symbol: Symbol let baseURL: String var inheritedTypes: [Symbol] + let symbolFilter: (Symbol) -> Bool - init(of symbol: Symbol, in module: Module, baseURL: String) { + init(of symbol: Symbol, in module: Module, baseURL: String, symbolFilter: @escaping (Symbol) -> Bool) { self.module = module self.symbol = symbol self.inheritedTypes = module.interface.typesInherited(by: symbol) + module.interface.typesConformed(by: symbol) self.baseURL = baseURL + self.symbolFilter = symbolFilter } var graphHTML: HypertextLiteral.HTML? { - var graph = symbol.graph(in: module, baseURL: baseURL) + var graph = symbol.graph(in: module, baseURL: baseURL, symbolFilter: symbolFilter) guard !graph.edges.isEmpty else { return nil } graph.aspectRatio = 0.125 diff --git a/Sources/swift-doc/Supporting Types/Pages/TypePage.swift b/Sources/swift-doc/Supporting Types/Pages/TypePage.swift index b3bee3f7..700c1dc4 100644 --- a/Sources/swift-doc/Supporting Types/Pages/TypePage.swift +++ b/Sources/swift-doc/Supporting Types/Pages/TypePage.swift @@ -28,7 +28,7 @@ struct TypePage: Page { Heading { symbol.id.description } Documentation(for: symbol, in: module, baseURL: baseURL) - Relationships(of: symbol, in: module, baseURL: baseURL) + Relationships(of: symbol, in: module, baseURL: baseURL, symbolFilter: symbolFilter) Members(of: symbol, in: module, baseURL: baseURL, symbolFilter: symbolFilter) Requirements(of: symbol, in: module, baseURL: baseURL) } @@ -42,7 +42,7 @@ struct TypePage: Page { \#(Documentation(for: symbol, in: module, baseURL: baseURL).html) - \#(Relationships(of: symbol, in: module, baseURL: baseURL).html) + \#(Relationships(of: symbol, in: module, baseURL: baseURL, symbolFilter: symbolFilter).html) \#(Members(of: symbol, in: module, baseURL: baseURL, symbolFilter: symbolFilter).html) \#(Requirements(of: symbol, in: module, baseURL: baseURL).html) """# From 8f1965ea1a912d028ce0437c7d19c9e94d6c405e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20St=C3=BChrk?= Date: Thu, 25 Mar 2021 21:44:09 +0100 Subject: [PATCH 2/4] Add changelog entry for #226 --- Changelog.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Changelog.md b/Changelog.md index 7eb28fcf..12c639eb 100644 --- a/Changelog.md +++ b/Changelog.md @@ -20,6 +20,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fixed public extensions exposing nested code of all access levels. #195 by @Tunous. +- Fixed broken links in the relationship graph. + #226 by @Lukas-Stuehrk. ### Changed From d65b70daafe395fbb18b506ea89cf35358eff50b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20St=C3=BChrk?= Date: Mon, 29 Mar 2021 18:33:59 +0200 Subject: [PATCH 3/4] Apply suggestions from code review Co-authored-by: Mattt --- Sources/swift-doc/Extensions/SwiftDoc+Extensions.swift | 2 +- .../swift-doc/Supporting Types/Components/Relationships.swift | 4 ++-- Sources/swift-doc/Supporting Types/Pages/TypePage.swift | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Sources/swift-doc/Extensions/SwiftDoc+Extensions.swift b/Sources/swift-doc/Extensions/SwiftDoc+Extensions.swift index f7bd046a..a25fa93f 100644 --- a/Sources/swift-doc/Extensions/SwiftDoc+Extensions.swift +++ b/Sources/swift-doc/Extensions/SwiftDoc+Extensions.swift @@ -36,7 +36,7 @@ extension Symbol { return node } - func graph(in module: Module, baseURL: String, symbolFilter: (Symbol) -> Bool) -> Graph { + func graph(in module: Module, baseURL: String, includingChildren symbolFilter: (Symbol) -> Bool) -> Graph { var graph = Graph(directed: true) do { diff --git a/Sources/swift-doc/Supporting Types/Components/Relationships.swift b/Sources/swift-doc/Supporting Types/Components/Relationships.swift index a68f0113..8e47b086 100644 --- a/Sources/swift-doc/Supporting Types/Components/Relationships.swift +++ b/Sources/swift-doc/Supporting Types/Components/Relationships.swift @@ -32,7 +32,7 @@ struct Relationships: Component { var inheritedTypes: [Symbol] let symbolFilter: (Symbol) -> Bool - init(of symbol: Symbol, in module: Module, baseURL: String, symbolFilter: @escaping (Symbol) -> Bool) { + init(of symbol: Symbol, in module: Module, baseURL: String, includingChildren symbolFilter: @escaping (Symbol) -> Bool) { self.module = module self.symbol = symbol self.inheritedTypes = module.interface.typesInherited(by: symbol) + module.interface.typesConformed(by: symbol) @@ -41,7 +41,7 @@ struct Relationships: Component { } var graphHTML: HypertextLiteral.HTML? { - var graph = symbol.graph(in: module, baseURL: baseURL, symbolFilter: symbolFilter) + var graph = symbol.graph(in: module, baseURL: baseURL, includingChildren symbolFilter: symbolFilter) guard !graph.edges.isEmpty else { return nil } graph.aspectRatio = 0.125 diff --git a/Sources/swift-doc/Supporting Types/Pages/TypePage.swift b/Sources/swift-doc/Supporting Types/Pages/TypePage.swift index 700c1dc4..345acefb 100644 --- a/Sources/swift-doc/Supporting Types/Pages/TypePage.swift +++ b/Sources/swift-doc/Supporting Types/Pages/TypePage.swift @@ -28,7 +28,7 @@ struct TypePage: Page { Heading { symbol.id.description } Documentation(for: symbol, in: module, baseURL: baseURL) - Relationships(of: symbol, in: module, baseURL: baseURL, symbolFilter: symbolFilter) + Relationships(of: symbol, in: module, baseURL: baseURL, includingChildren: symbolFilter) Members(of: symbol, in: module, baseURL: baseURL, symbolFilter: symbolFilter) Requirements(of: symbol, in: module, baseURL: baseURL) } @@ -42,7 +42,7 @@ struct TypePage: Page { \#(Documentation(for: symbol, in: module, baseURL: baseURL).html) - \#(Relationships(of: symbol, in: module, baseURL: baseURL, symbolFilter: symbolFilter).html) + \#(Relationships(of: symbol, in: module, baseURL: baseURL, includingChildren: symbolFilter).html) \#(Members(of: symbol, in: module, baseURL: baseURL, symbolFilter: symbolFilter).html) \#(Requirements(of: symbol, in: module, baseURL: baseURL).html) """# From d1b7907159da522d63f95fcefdce04bfd3733e16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20St=C3=BChrk?= Date: Mon, 29 Mar 2021 18:48:44 +0200 Subject: [PATCH 4/4] And fix my changes from code review. --- .../swift-doc/Supporting Types/Components/Relationships.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/swift-doc/Supporting Types/Components/Relationships.swift b/Sources/swift-doc/Supporting Types/Components/Relationships.swift index 8e47b086..7e647134 100644 --- a/Sources/swift-doc/Supporting Types/Components/Relationships.swift +++ b/Sources/swift-doc/Supporting Types/Components/Relationships.swift @@ -41,7 +41,7 @@ struct Relationships: Component { } var graphHTML: HypertextLiteral.HTML? { - var graph = symbol.graph(in: module, baseURL: baseURL, includingChildren symbolFilter: symbolFilter) + var graph = symbol.graph(in: module, baseURL: baseURL, includingChildren: symbolFilter) guard !graph.edges.isEmpty else { return nil } graph.aspectRatio = 0.125