From f08921c706c3ad3a4413870df9aa5e444e029829 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20St=C3=BChrk?= Date: Mon, 26 Apr 2021 20:01:00 +0200 Subject: [PATCH 1/6] Fix the visibility of operator implementations. --- Sources/swift-doc/Subcommands/Generate.swift | 2 +- Sources/swift-doc/Supporting Types/Pages/OperatorPage.swift | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Sources/swift-doc/Subcommands/Generate.swift b/Sources/swift-doc/Subcommands/Generate.swift index 54e6183e..a54eddf6 100644 --- a/Sources/swift-doc/Subcommands/Generate.swift +++ b/Sources/swift-doc/Subcommands/Generate.swift @@ -76,7 +76,7 @@ extension SwiftDoc { case let `typealias` as Typealias: pages[route(for: `typealias`.name)] = TypealiasPage(module: module, symbol: symbol, baseURL: baseURL) case is Operator: - pages[route(for: symbol)] = OperatorPage(module: module, symbol: symbol, baseURL: baseURL) + pages[route(for: symbol)] = OperatorPage(module: module, symbol: symbol, baseURL: baseURL, includingImplementations: symbolFilter) case let function as Function where !function.isOperator: globals[function.name, default: []] += [symbol] case let variable as Variable: diff --git a/Sources/swift-doc/Supporting Types/Pages/OperatorPage.swift b/Sources/swift-doc/Supporting Types/Pages/OperatorPage.swift index d8a428a2..740e7829 100644 --- a/Sources/swift-doc/Supporting Types/Pages/OperatorPage.swift +++ b/Sources/swift-doc/Supporting Types/Pages/OperatorPage.swift @@ -9,11 +9,11 @@ struct OperatorPage: Page { let implementations: [Symbol] let baseURL: String - init(module: Module, symbol: Symbol, baseURL: String) { + init(module: Module, symbol: Symbol, baseURL: String, includingImplementations symbolFilter: (Symbol) -> Bool) { precondition(symbol.api is Operator) self.module = module self.symbol = symbol - self.implementations = module.interface.functionsByOperator[symbol]?.sorted() ?? [] + self.implementations = module.interface.functionsByOperator[symbol]?.filter(symbolFilter).sorted() ?? [] self.baseURL = baseURL } From 2a84a5c6ebc34d2fe36340f11c9c800bd773f04b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20St=C3=BChrk?= Date: Mon, 26 Apr 2021 20:13:04 +0200 Subject: [PATCH 2/6] Only include operators if they have at least one visible implementation. --- Sources/swift-doc/Subcommands/Generate.swift | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Sources/swift-doc/Subcommands/Generate.swift b/Sources/swift-doc/Subcommands/Generate.swift index a54eddf6..a209218c 100644 --- a/Sources/swift-doc/Subcommands/Generate.swift +++ b/Sources/swift-doc/Subcommands/Generate.swift @@ -76,7 +76,10 @@ extension SwiftDoc { case let `typealias` as Typealias: pages[route(for: `typealias`.name)] = TypealiasPage(module: module, symbol: symbol, baseURL: baseURL) case is Operator: - pages[route(for: symbol)] = OperatorPage(module: module, symbol: symbol, baseURL: baseURL, includingImplementations: symbolFilter) + let operatorPage = OperatorPage(module: module, symbol: symbol, baseURL: baseURL, includingImplementations: symbolFilter) + if !operatorPage.implementations.isEmpty { + pages[route(for: symbol)] = operatorPage + } case let function as Function where !function.isOperator: globals[function.name, default: []] += [symbol] case let variable as Variable: From e008eab3d67f61062b8f962bb9d1908847bc5490 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20St=C3=BChrk?= Date: Wed, 28 Apr 2021 19:38:13 +0200 Subject: [PATCH 3/6] Add changelog for #264. --- Changelog.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Changelog.md b/Changelog.md index 4d0e6f2d..5dfd7a05 100644 --- a/Changelog.md +++ b/Changelog.md @@ -15,6 +15,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed +- Fixed bug that caused operator implementations to appear in the documentation + although they should be omitted because of their lower access level. + #264 by @Lukas-Stuehrk - Fixed bug that caused prefix and postfix operators to be omitted from generated documentation. #262 by @Lukas-Stuehrk. From ca4f161dc5899be5a63d4cc59011ca9ab6a80cf9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20St=C3=BChrk?= Date: Tue, 11 May 2021 23:31:59 +0200 Subject: [PATCH 4/6] Bring back links to other symbols in declarations. --- Sources/SwiftDoc/Interface.swift | 8 ++++++++ Sources/swift-doc/Subcommands/Generate.swift | 6 +++--- .../Components/Declaration.swift | 8 ++++++-- .../Components/Documentation.swift | 8 +++++--- .../Supporting Types/Components/Members.swift | 14 +++++++++----- .../Components/OperatorImplementations.swift | 9 ++++++--- .../Components/Requirements.swift | 8 +++++--- .../swift-doc/Supporting Types/Helpers.swift | 17 +++++++++++++++++ .../Pages/ExternalTypePage.swift | 9 ++++++--- .../Supporting Types/Pages/GlobalPage.swift | 8 +++++--- .../Supporting Types/Pages/OperatorPage.swift | 10 ++++++---- .../Supporting Types/Pages/TypePage.swift | 8 ++++---- .../Supporting Types/Pages/TypealiasPage.swift | 8 +++++--- 13 files changed, 85 insertions(+), 36 deletions(-) diff --git a/Sources/SwiftDoc/Interface.swift b/Sources/SwiftDoc/Interface.swift index 8f5137ed..0fdbc1bc 100644 --- a/Sources/SwiftDoc/Interface.swift +++ b/Sources/SwiftDoc/Interface.swift @@ -190,6 +190,14 @@ public final class Interface { public func symbols(named name: String, resolvingTypealiases: Bool) -> [Symbol] { symbolsGroupedByIdentifier.named(name, resolvingTypealiases: resolvingTypealiases) } + + public func symbols(named name: String, context: String, resolvingTypealiases: Bool) -> [Symbol] { + let foundSymbols = symbols(named: "\(context).\(name)", resolvingTypealiases: resolvingTypealiases) + if !foundSymbols.isEmpty { + return symbols + } + return symbols(named: name, resolvingTypealiases: resolvingTypealiases) + } } fileprivate extension Dictionary where Key == Identifier, Value == [Symbol] { diff --git a/Sources/swift-doc/Subcommands/Generate.swift b/Sources/swift-doc/Subcommands/Generate.swift index a209218c..5e69e4aa 100644 --- a/Sources/swift-doc/Subcommands/Generate.swift +++ b/Sources/swift-doc/Subcommands/Generate.swift @@ -74,7 +74,7 @@ extension SwiftDoc { case is Class, is Enumeration, is Structure, is Protocol: pages[route(for: symbol)] = TypePage(module: module, symbol: symbol, baseURL: baseURL, includingChildren: symbolFilter) case let `typealias` as Typealias: - pages[route(for: `typealias`.name)] = TypealiasPage(module: module, symbol: symbol, baseURL: baseURL) + pages[route(for: `typealias`.name)] = TypealiasPage(module: module, symbol: symbol, baseURL: baseURL, includingOtherSymbols: symbolFilter) case is Operator: let operatorPage = OperatorPage(module: module, symbol: symbol, baseURL: baseURL, includingImplementations: symbolFilter) if !operatorPage.implementations.isEmpty { @@ -97,11 +97,11 @@ extension SwiftDoc { symbolsByExternalType[extensionDeclaration.extendedType, default: []] += [symbol] } for (typeName, symbols) in symbolsByExternalType { - pages[route(for: typeName)] = ExternalTypePage(module: module, externalType: typeName, symbols: symbols, baseURL: baseURL) + pages[route(for: typeName)] = ExternalTypePage(module: module, externalType: typeName, symbols: symbols, baseURL: baseURL, includingOtherSymbols: symbolFilter) } for (name, symbols) in globals { - pages[route(for: name)] = GlobalPage(module: module, name: name, symbols: symbols, baseURL: baseURL) + pages[route(for: name)] = GlobalPage(module: module, name: name, symbols: symbols, baseURL: baseURL, includingOtherSymbols: symbolFilter) } guard !pages.isEmpty else { diff --git a/Sources/swift-doc/Supporting Types/Components/Declaration.swift b/Sources/swift-doc/Supporting Types/Components/Declaration.swift index d17e6ad3..95f52f0d 100644 --- a/Sources/swift-doc/Supporting Types/Components/Declaration.swift +++ b/Sources/swift-doc/Supporting Types/Components/Declaration.swift @@ -10,11 +10,13 @@ struct Declaration: Component { var symbol: Symbol var module: Module let baseURL: String + let symbolFilter: (Symbol) -> Bool - init(of symbol: Symbol, in module: Module, baseURL: String) { + init(of symbol: Symbol, in module: Module, baseURL: String, includingOtherSymbols symbolFilter: @escaping (Symbol) -> Bool) { self.symbol = symbol self.module = module self.baseURL = baseURL + self.symbolFilter = symbolFilter } // MARK: - Component @@ -30,9 +32,11 @@ struct Declaration: Component { var html: HypertextLiteral.HTML { let code = symbol.declaration.map { $0.html }.joined() + let html = linkTypes(of: code, for: symbol, in: module, with: baseURL, includingSymbols: symbolFilter) + return #"""
-
\#(unsafeUnescaped: code)
+
\#(unsafeUnescaped: html)
"""# } diff --git a/Sources/swift-doc/Supporting Types/Components/Documentation.swift b/Sources/swift-doc/Supporting Types/Components/Documentation.swift index 3bc07fe0..ec272b1a 100644 --- a/Sources/swift-doc/Supporting Types/Components/Documentation.swift +++ b/Sources/swift-doc/Supporting Types/Components/Documentation.swift @@ -11,11 +11,13 @@ struct Documentation: Component { var symbol: Symbol var module: Module let baseURL: String + let symbolFilter: (Symbol) -> Bool - init(for symbol: Symbol, in module: Module, baseURL: String) { + init(for symbol: Symbol, in module: Module, baseURL: String, includingOtherSymbols symbolFilter: @escaping (Symbol) -> Bool) { self.symbol = symbol self.module = module self.baseURL = baseURL + self.symbolFilter = symbolFilter } // MARK: - Component @@ -39,7 +41,7 @@ struct Documentation: Component { Fragment { "\(documentation.summary!.description.escapingEmojiShortcodes)" } } - Declaration(of: symbol, in: module, baseURL: baseURL) + Declaration(of: symbol, in: module, baseURL: baseURL, includingOtherSymbols: symbolFilter) ForEach(in: documentation.discussionParts) { part in DiscussionPart(part, for: symbol, in: module, baseURL: baseURL) @@ -85,7 +87,7 @@ struct Documentation: Component { var fragments: [HypertextLiteralConvertible] = [] - fragments.append(Declaration(of: symbol, in: module, baseURL: baseURL)) + fragments.append(Declaration(of: symbol, in: module, baseURL: baseURL, includingOtherSymbols: symbolFilter)) if let summary = documentation.summary { fragments.append(#""" diff --git a/Sources/swift-doc/Supporting Types/Components/Members.swift b/Sources/swift-doc/Supporting Types/Components/Members.swift index 95835687..6e4e17a4 100644 --- a/Sources/swift-doc/Supporting Types/Components/Members.swift +++ b/Sources/swift-doc/Supporting Types/Components/Members.swift @@ -9,6 +9,8 @@ struct Members: Component { var module: Module let baseURL: String + let symbolFilter: (Symbol) -> Bool + var members: [Symbol] var typealiases: [Symbol] @@ -20,11 +22,13 @@ struct Members: Component { var genericallyConstrainedMembers: [[GenericRequirement] : [Symbol]] let defaultImplementations: [Symbol] - init(of symbol: Symbol, in module: Module, baseURL: String, symbolFilter: (Symbol) -> Bool) { + init(of symbol: Symbol, in module: Module, baseURL: String, symbolFilter: @escaping (Symbol) -> Bool) { self.symbol = symbol self.module = module self.baseURL = baseURL + self.symbolFilter = symbolFilter + self.members = module.interface.members(of: symbol) .filter { $0.extension?.genericRequirements.isEmpty != false } .filter(symbolFilter) @@ -66,7 +70,7 @@ struct Members: Component { Heading { Code { member.name } } - Documentation(for: member, in: module, baseURL: baseURL) + Documentation(for: member, in: module, baseURL: baseURL, includingOtherSymbols: symbolFilter) } } } @@ -83,7 +87,7 @@ struct Members: Component { Section { ForEach(in: members) { member in Heading { member.name } - Documentation(for: member, in: module, baseURL: baseURL) + Documentation(for: member, in: module, baseURL: baseURL, includingOtherSymbols: symbolFilter) } } } @@ -108,7 +112,7 @@ struct Members: Component {

\#(softbreak(member.name))

- \#(Documentation(for: member, in: module, baseURL: baseURL).html) + \#(Documentation(for: member, in: module, baseURL: baseURL, includingOtherSymbols: symbolFilter).html) """# }) @@ -128,7 +132,7 @@ struct Members: Component { \#(members.map { member -> HypertextLiteral.HTML in #"""

\#(softbreak(member.name))

- \#(Documentation(for: member, in: module, baseURL: baseURL).html) + \#(Documentation(for: member, in: module, baseURL: baseURL, includingOtherSymbols: symbolFilter).html) """# }) diff --git a/Sources/swift-doc/Supporting Types/Components/OperatorImplementations.swift b/Sources/swift-doc/Supporting Types/Components/OperatorImplementations.swift index f28fa761..fcc5ca0a 100644 --- a/Sources/swift-doc/Supporting Types/Components/OperatorImplementations.swift +++ b/Sources/swift-doc/Supporting Types/Components/OperatorImplementations.swift @@ -9,13 +9,16 @@ struct OperatorImplementations: Component { var module: Module let baseURL: String + let symbolFilter: (Symbol) -> Bool + var implementations: [Symbol] - init(of symbol: Symbol, in module: Module, baseURL: String, implementations: [Symbol]) { + init(of symbol: Symbol, in module: Module, baseURL: String, implementations: [Symbol], includingOtherSymbols symbolFilter: @escaping (Symbol) -> Bool) { self.symbol = symbol self.module = module self.baseURL = baseURL self.implementations = implementations + self.symbolFilter = symbolFilter } @@ -29,7 +32,7 @@ struct OperatorImplementations: Component { Section { Heading { implementation.name } - Documentation(for: implementation, in: module, baseURL: baseURL) + Documentation(for: implementation, in: module, baseURL: baseURL, includingOtherSymbols: symbolFilter) } } } @@ -75,7 +78,7 @@ struct OperatorImplementations: Component { \#(heading) \#(unsafeUnescaped: function.genericWhereClause.map({ #"\#($0.escaped)"# }) ?? "") - \#(Documentation(for: implementation, in: module, baseURL: baseURL).html) + \#(Documentation(for: implementation, in: module, baseURL: baseURL, includingOtherSymbols: symbolFilter).html) """# } diff --git a/Sources/swift-doc/Supporting Types/Components/Requirements.swift b/Sources/swift-doc/Supporting Types/Components/Requirements.swift index d7bf8eca..b02c5d37 100644 --- a/Sources/swift-doc/Supporting Types/Components/Requirements.swift +++ b/Sources/swift-doc/Supporting Types/Components/Requirements.swift @@ -8,11 +8,13 @@ struct Requirements: Component { var symbol: Symbol var module: Module let baseURL: String + let symbolFilter: (Symbol) -> Bool - init(of symbol: Symbol, in module: Module, baseURL: String) { + init(of symbol: Symbol, in module: Module, baseURL: String, includingOtherSymbols symbolFilter: @escaping (Symbol) -> Bool) { self.symbol = symbol self.module = module self.baseURL = baseURL + self.symbolFilter = symbolFilter } var sections: [(title: String, requirements: [Symbol])] { @@ -34,7 +36,7 @@ struct Requirements: Component { Section { ForEach(in: section.requirements) { requirement in Heading { requirement.name.escapingEmojiShortcodes } - Documentation(for: requirement, in: module, baseURL: baseURL) + Documentation(for: requirement, in: module, baseURL: baseURL, includingOtherSymbols: symbolFilter) } } } @@ -57,7 +59,7 @@ struct Requirements: Component {

\#(softbreak(member.name))

- \#(Documentation(for: member, in: module, baseURL: baseURL).html) + \#(Documentation(for: member, in: module, baseURL: baseURL, includingOtherSymbols: symbolFilter).html) """# }) diff --git a/Sources/swift-doc/Supporting Types/Helpers.swift b/Sources/swift-doc/Supporting Types/Helpers.swift index 31002335..6f8d9ae9 100644 --- a/Sources/swift-doc/Supporting Types/Helpers.swift +++ b/Sources/swift-doc/Supporting Types/Helpers.swift @@ -20,6 +20,23 @@ public func linkCodeElements(of html: String, for symbol: Symbol, in module: Mod return document.root?.description ?? html } +public func linkTypes(of html: String, for symbol: Symbol, in module: Module, with baseURL: String, includingSymbols symbolFilter: (Symbol) -> Bool) -> String { + let document = try! Document(string: html.description)! + for element in document.search(xpath: "//span[contains(@class,'type')]") { + guard let name = element.content else { continue } + + let candidates = module.interface.symbols(named: name, context: symbol.name, resolvingTypealiases: true).filter(symbolFilter) + if let candidate = candidates.filter({ $0 != symbol }).first + { + let a = Element(name: "a") + a["href"] = path(for: candidate, with: baseURL) + element.wrap(inside: a) + } + } + + return document.root?.description ?? html +} + public func sidebar(for html: String) -> String { let toc = Element(name: "ol") diff --git a/Sources/swift-doc/Supporting Types/Pages/ExternalTypePage.swift b/Sources/swift-doc/Supporting Types/Pages/ExternalTypePage.swift index febc3598..3f5e10ca 100644 --- a/Sources/swift-doc/Supporting Types/Pages/ExternalTypePage.swift +++ b/Sources/swift-doc/Supporting Types/Pages/ExternalTypePage.swift @@ -15,10 +15,13 @@ struct ExternalTypePage: Page { let properties: [Symbol] let methods: [Symbol] - init(module: Module, externalType: String, symbols: [Symbol], baseURL: String) { + let symbolFilter: (Symbol) -> Bool + + init(module: Module, externalType: String, symbols: [Symbol], baseURL: String, includingOtherSymbols symbolFilter: @escaping (Symbol) -> Bool) { self.module = module self.externalType = externalType self.baseURL = baseURL + self.symbolFilter = symbolFilter self.typealiases = symbols.filter { $0.api is Typealias } self.initializers = symbols.filter { $0.api is Initializer } @@ -49,7 +52,7 @@ struct ExternalTypePage: Page { Heading { Code { member.name } } - Documentation(for: member, in: module, baseURL: baseURL) + Documentation(for: member, in: module, baseURL: baseURL, includingOtherSymbols: symbolFilter) } } } @@ -75,7 +78,7 @@ struct ExternalTypePage: Page {

\#(softbreak(member.name))

- \#(Documentation(for: member, in: module, baseURL: baseURL).html) + \#(Documentation(for: member, in: module, baseURL: baseURL, includingOtherSymbols: symbolFilter).html) """# }) diff --git a/Sources/swift-doc/Supporting Types/Pages/GlobalPage.swift b/Sources/swift-doc/Supporting Types/Pages/GlobalPage.swift index cd8dad0f..bbb599f3 100644 --- a/Sources/swift-doc/Supporting Types/Pages/GlobalPage.swift +++ b/Sources/swift-doc/Supporting Types/Pages/GlobalPage.swift @@ -8,12 +8,14 @@ struct GlobalPage: Page { let name: String let symbols: [Symbol] let baseURL: String + let symbolFilter: (Symbol) -> Bool - init(module: Module, name: String, symbols: [Symbol], baseURL: String) { + init(module: Module, name: String, symbols: [Symbol], baseURL: String, includingOtherSymbols symbolFilter: @escaping (Symbol) -> Bool) { self.module = module self.name = name self.symbols = symbols self.baseURL = baseURL + self.symbolFilter = symbolFilter } // MARK: - Page @@ -26,7 +28,7 @@ struct GlobalPage: Page { return Document { ForEach(in: symbols) { symbol in Heading { symbol.id.description } - Documentation(for: symbol, in: module, baseURL: baseURL) + Documentation(for: symbol, in: module, baseURL: baseURL, includingOtherSymbols: symbolFilter) } } } @@ -48,7 +50,7 @@ struct GlobalPage: Page { \#(symbols.map { symbol in - Documentation(for: symbol, in: module, baseURL: baseURL).html + Documentation(for: symbol, in: module, baseURL: baseURL, includingOtherSymbols: symbolFilter).html }) """# } diff --git a/Sources/swift-doc/Supporting Types/Pages/OperatorPage.swift b/Sources/swift-doc/Supporting Types/Pages/OperatorPage.swift index 740e7829..2d979c5d 100644 --- a/Sources/swift-doc/Supporting Types/Pages/OperatorPage.swift +++ b/Sources/swift-doc/Supporting Types/Pages/OperatorPage.swift @@ -8,13 +8,15 @@ struct OperatorPage: Page { let symbol: Symbol let implementations: [Symbol] let baseURL: String + let symbolFilter: (Symbol) -> Bool - init(module: Module, symbol: Symbol, baseURL: String, includingImplementations symbolFilter: (Symbol) -> Bool) { + init(module: Module, symbol: Symbol, baseURL: String, includingImplementations symbolFilter: @escaping (Symbol) -> Bool) { precondition(symbol.api is Operator) self.module = module self.symbol = symbol self.implementations = module.interface.functionsByOperator[symbol]?.filter(symbolFilter).sorted() ?? [] self.baseURL = baseURL + self.symbolFilter = symbolFilter } // MARK: - Page @@ -27,7 +29,7 @@ struct OperatorPage: Page { return CommonMark.Document { Heading { symbol.id.description } - Documentation(for: symbol, in: module, baseURL: baseURL) + Documentation(for: symbol, in: module, baseURL: baseURL, includingOtherSymbols: symbolFilter) } } @@ -38,8 +40,8 @@ struct OperatorPage: Page { \#(softbreak(symbol.id.description)) - \#(Documentation(for: symbol, in: module, baseURL: baseURL).html) - \#(OperatorImplementations(of: symbol, in: module, baseURL: baseURL, implementations: implementations).html) + \#(Documentation(for: symbol, in: module, baseURL: baseURL, includingOtherSymbols: symbolFilter).html) + \#(OperatorImplementations(of: symbol, in: module, baseURL: baseURL, implementations: implementations, includingOtherSymbols: symbolFilter).html) """# } } diff --git a/Sources/swift-doc/Supporting Types/Pages/TypePage.swift b/Sources/swift-doc/Supporting Types/Pages/TypePage.swift index 345acefb..62dbe115 100644 --- a/Sources/swift-doc/Supporting Types/Pages/TypePage.swift +++ b/Sources/swift-doc/Supporting Types/Pages/TypePage.swift @@ -27,10 +27,10 @@ struct TypePage: Page { return CommonMark.Document { Heading { symbol.id.description } - Documentation(for: symbol, in: module, baseURL: baseURL) + Documentation(for: symbol, in: module, baseURL: baseURL, includingOtherSymbols: 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) + Requirements(of: symbol, in: module, baseURL: baseURL, includingOtherSymbols: symbolFilter) } } @@ -41,10 +41,10 @@ struct TypePage: Page { \#(softbreak(symbol.id.description)) - \#(Documentation(for: symbol, in: module, baseURL: baseURL).html) + \#(Documentation(for: symbol, in: module, baseURL: baseURL, includingOtherSymbols: 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) + \#(Requirements(of: symbol, in: module, baseURL: baseURL, includingOtherSymbols: symbolFilter).html) """# } } diff --git a/Sources/swift-doc/Supporting Types/Pages/TypealiasPage.swift b/Sources/swift-doc/Supporting Types/Pages/TypealiasPage.swift index 4c806727..305e14a2 100644 --- a/Sources/swift-doc/Supporting Types/Pages/TypealiasPage.swift +++ b/Sources/swift-doc/Supporting Types/Pages/TypealiasPage.swift @@ -7,12 +7,14 @@ struct TypealiasPage: Page { let module: Module let symbol: Symbol let baseURL: String + let symbolFilter: (Symbol) -> Bool - init(module: Module, symbol: Symbol, baseURL: String) { + init(module: Module, symbol: Symbol, baseURL: String, includingOtherSymbols symbolFilter: @escaping (Symbol) -> Bool) { precondition(symbol.api is Typealias) self.module = module self.symbol = symbol self.baseURL = baseURL + self.symbolFilter = symbolFilter } // MARK: - Page @@ -24,7 +26,7 @@ struct TypealiasPage: Page { var document: CommonMark.Document { Document { Heading { symbol.id.description } - Documentation(for: symbol, in: module, baseURL: baseURL) + Documentation(for: symbol, in: module, baseURL: baseURL, includingOtherSymbols: symbolFilter) } } @@ -35,7 +37,7 @@ struct TypealiasPage: Page { \#(softbreak(symbol.id.description)) - \#(Documentation(for: symbol, in: module, baseURL: baseURL).html) + \#(Documentation(for: symbol, in: module, baseURL: baseURL, includingOtherSymbols: symbolFilter).html) """# } } From ccc54d58a7074cb6114af5d3af75d2d65ef0e00d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20St=C3=BChrk?= Date: Tue, 18 May 2021 19:17:01 +0200 Subject: [PATCH 5/6] Refactor the search of linked symbols. --- Sources/SwiftDoc/Interface.swift | 8 -------- Sources/swift-doc/Supporting Types/Helpers.swift | 10 ++++++++-- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/Sources/SwiftDoc/Interface.swift b/Sources/SwiftDoc/Interface.swift index 0fdbc1bc..8f5137ed 100644 --- a/Sources/SwiftDoc/Interface.swift +++ b/Sources/SwiftDoc/Interface.swift @@ -190,14 +190,6 @@ public final class Interface { public func symbols(named name: String, resolvingTypealiases: Bool) -> [Symbol] { symbolsGroupedByIdentifier.named(name, resolvingTypealiases: resolvingTypealiases) } - - public func symbols(named name: String, context: String, resolvingTypealiases: Bool) -> [Symbol] { - let foundSymbols = symbols(named: "\(context).\(name)", resolvingTypealiases: resolvingTypealiases) - if !foundSymbols.isEmpty { - return symbols - } - return symbols(named: name, resolvingTypealiases: resolvingTypealiases) - } } fileprivate extension Dictionary where Key == Identifier, Value == [Symbol] { diff --git a/Sources/swift-doc/Supporting Types/Helpers.swift b/Sources/swift-doc/Supporting Types/Helpers.swift index 6f8d9ae9..2061b395 100644 --- a/Sources/swift-doc/Supporting Types/Helpers.swift +++ b/Sources/swift-doc/Supporting Types/Helpers.swift @@ -25,8 +25,8 @@ public func linkTypes(of html: String, for symbol: Symbol, in module: Module, wi for element in document.search(xpath: "//span[contains(@class,'type')]") { guard let name = element.content else { continue } - let candidates = module.interface.symbols(named: name, context: symbol.name, resolvingTypealiases: true).filter(symbolFilter) - if let candidate = candidates.filter({ $0 != symbol }).first + let candidates = module.interface.symbols(named: "\(symbol.name).\(name)", resolvingTypealiases: true).nonEmpty ?? module.interface.symbols(named: name, resolvingTypealiases: true) + if let candidate = candidates.filter(symbolFilter).filter({ $0 != symbol }).first { let a = Element(name: "a") a["href"] = path(for: candidate, with: baseURL) @@ -95,3 +95,9 @@ public func softbreak(_ string: String) -> String { return regex.stringByReplacingMatches(in: string, options: [], range: NSRange(string.startIndex.. Date: Tue, 18 May 2021 19:18:28 +0200 Subject: [PATCH 6/6] Add changelog entry for #277 --- Changelog.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Changelog.md b/Changelog.md index 2ed05c0e..856c6650 100644 --- a/Changelog.md +++ b/Changelog.md @@ -17,6 +17,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed +- Fixed links to type declarations. + #277 by @Lukas-Stuehrk. - Fixed bug that caused operator implementations to appear in the documentation although they should be omitted because of their lower access level. #264 by @Lukas-Stuehrk