This repository was archived by the owner on Jun 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 98
Build documentation for extensions on external types. #230
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
986b5ae
Build documentation for external types.
Lukas-Stuehrk 4ff1688
Display extensions in definition list
mattt 8af0722
Fix false positives for external types.
Lukas-Stuehrk 688ef0f
Better check for external symbols.
Lukas-Stuehrk 89f5e83
Refactor isExternalSymbol to perform more general symbol resolution
mattt 099ac58
Remove unnecessary parameter
mattt 0df8f0a
Add resolution for nested types through typealiases
mattt 09b9720
Use typealias resolution when creating relationships
mattt fee0c78
Add tests for extensions on typealiases.
Lukas-Stuehrk e62d777
Add changelog entry for #230
mattt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,41 @@ | ||
public struct Identifier: Hashable { | ||
public let pathComponents: [String] | ||
public let context: [String] | ||
public let name: String | ||
public let pathComponents: [String] | ||
|
||
public init(context: [String], name: String) { | ||
self.context = context | ||
self.name = name | ||
self.pathComponents = context + CollectionOfOne(name) | ||
} | ||
|
||
public func matches(_ string: String) -> Bool { | ||
(pathComponents + CollectionOfOne(name)).reversed().starts(with: string.split(separator: ".").map { String($0) }.reversed()) | ||
return matches(string.split(separator: ".")) | ||
} | ||
|
||
public func matches(_ pathComponents: [Substring]) -> Bool { | ||
return matches(pathComponents.map(String.init)) | ||
} | ||
|
||
public func matches(_ pathComponents: [String]) -> Bool { | ||
return self.pathComponents.ends(with: pathComponents) | ||
} | ||
} | ||
|
||
// MARK: - CustomStringConvertible | ||
|
||
extension Identifier: CustomStringConvertible { | ||
public var description: String { | ||
(pathComponents + CollectionOfOne(name)).joined(separator: ".") | ||
pathComponents.joined(separator: ".") | ||
} | ||
} | ||
|
||
fileprivate extension Array { | ||
func ends<PossibleSuffix>(with possibleSuffix: PossibleSuffix) -> Bool | ||
where PossibleSuffix : Sequence, | ||
Self.Element == PossibleSuffix.Element, | ||
Self.Element: Equatable | ||
{ | ||
reversed().starts(with: possibleSuffix) | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
Sources/swift-doc/Supporting Types/Pages/ExternalTypePage.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import CommonMarkBuilder | ||
import SwiftDoc | ||
import HypertextLiteral | ||
import SwiftMarkup | ||
import SwiftSemantics | ||
|
||
struct ExternalTypePage: Page { | ||
|
||
let module: Module | ||
let externalType: String | ||
let baseURL: String | ||
|
||
let typealiases: [Symbol] | ||
let initializers: [Symbol] | ||
let properties: [Symbol] | ||
let methods: [Symbol] | ||
|
||
init(module: Module, externalType: String, symbols: [Symbol], baseURL: String) { | ||
self.module = module | ||
self.externalType = externalType | ||
self.baseURL = baseURL | ||
|
||
self.typealiases = symbols.filter { $0.api is Typealias } | ||
self.initializers = symbols.filter { $0.api is Initializer } | ||
self.properties = symbols.filter { $0.api is Variable } | ||
self.methods = symbols.filter { $0.api is Function } | ||
} | ||
|
||
var title: String { externalType } | ||
|
||
var sections: [(title: String, members: [Symbol])] { | ||
return [ | ||
("Nested Type Aliases", typealiases), | ||
("Initializers", initializers), | ||
("Properties", properties), | ||
("Methods", methods), | ||
].filter { !$0.members.isEmpty } | ||
} | ||
|
||
var document: CommonMark.Document { | ||
Document { | ||
Heading { "Extensions on \(externalType)" } | ||
ForEach(in: sections) { section -> BlockConvertible in | ||
Section { | ||
Heading { section.title } | ||
|
||
Section { | ||
ForEach(in: section.members) { member in | ||
Heading { | ||
Code { member.name } | ||
} | ||
Documentation(for: member, in: module, baseURL: baseURL) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
var html: HypertextLiteral.HTML { | ||
#""" | ||
<h1> | ||
<small>Extensions on</small> | ||
<code class="name">\#(externalType)</code> | ||
</h1> | ||
\#(sections.map { section -> HypertextLiteral.HTML in | ||
#""" | ||
<section id=\#(section.title.lowercased())> | ||
<h2>\#(section.title)</h2> | ||
|
||
\#(section.members.map { member -> HypertextLiteral.HTML in | ||
let descriptor = String(describing: type(of: member.api)).lowercased() | ||
|
||
return #""" | ||
<div role="article" class="\#(descriptor)" id=\#(member.id.description.lowercased().replacingOccurrences(of: " ", with: "-"))> | ||
<h3> | ||
<code>\#(softbreak(member.name))</code> | ||
</h3> | ||
\#(Documentation(for: member, in: module, baseURL: baseURL).html) | ||
</div> | ||
"""# | ||
}) | ||
</section> | ||
"""# | ||
}) | ||
"""# | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.