Skip to content

Commit b6081e7

Browse files
committed
Group symbols by highest level path component, and separate groups by spaces.
1 parent ba1d47a commit b6081e7

File tree

1 file changed

+22
-42
lines changed

1 file changed

+22
-42
lines changed

Sources/SwiftDocCUtilities/ArgumentParsing/Subcommands/DiffDocCArchive.swift

+22-42
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,6 @@ extension Docc.ProcessArchive {
105105
let additionsToNewSet = newSet.subtracting(initialSet)
106106
let removedFromOldSet = initialSet.subtracting(newSet)
107107

108-
// Map identifier urls in differences to external urls
109-
let additionsExternalURLs = Set(additionsToNewSet.map { findExternalLink(identifierURL: $0) })
110-
let removalsExternalURLs = Set(removedFromOldSet.map { findExternalLink(identifierURL: $0) })
111-
112108
// The framework name is the path component after "/documentation/".
113109
var frameworkName: String = "No_Framework_Name"
114110
var potentialFrameworkName = try findFrameworkName(initialPath: initialDocCArchivePath)
@@ -120,24 +116,8 @@ extension Docc.ProcessArchive {
120116
frameworkName = potentialFrameworkName ?? "No_Framework_Name"
121117
}
122118

123-
124-
let additionLinks = groupSeparateSymbols(symbolLinks: additionsExternalURLs)
125-
let removalLinks = groupSeparateSymbols(symbolLinks: removalsExternalURLs)
126-
127-
128-
129-
// let sortedAdditionSymbols = groupSeparateSymbols(symbolLinks: additionsExternalURLs)
130-
// let sortedRemovalSymbols = groupSeparateSymbols(symbolLinks: removalsExternalURLs)
131-
//
132-
// var additionLinks: String = ""
133-
// for addition in sortedAdditionSymbols {
134-
// additionLinks.append("\n- <\(addition)>")
135-
// }
136-
//
137-
// var removalLinks: String = ""
138-
// for removal in sortedRemovalSymbols {
139-
// removalLinks.append("\n- <\(removal)>")
140-
// }
119+
let additionLinks = groupSymbols(symbolLinks: additionsToNewSet, frameworkName: frameworkName)
120+
let removalLinks = groupSymbols(symbolLinks: removedFromOldSet, frameworkName: frameworkName)
141121

142122
// Create markdown file with changes in the newer DocC Archive that do not exist in the initial DocC Archive.
143123
for fileNameAndContent in Docc.ProcessArchive.DiffDocCArchive.changeLogTemplateFileContent(frameworkName: frameworkName, initialDocCArchiveVersion: initialDocCArchiveVersion, newerDocCArchiveVersion: newerDocCArchiveVersion, additionLinks: additionLinks, removalLinks: removalLinks) {
@@ -242,31 +222,31 @@ extension Docc.ProcessArchive {
242222
}
243223
}
244224

245-
/// Process lists of symbols to group them according to the highest level path component.
246-
///
247-
/// If a class didn't exist in the old version but now exists in the new version:
248-
/// - print that a new class was added,
249-
/// - display the number of symbols added within that class beside it.
250-
///
251-
/// Otherwise, group symbols by their highest path component below a header, and then print a nested list.
252-
func groupSeparateSymbols(symbolLinks: Set<String>) -> String {
253-
225+
/// Process lists of symbols to group them according to the highest level path component, split by spaces.
226+
func groupSymbols(symbolLinks: Set<URL>, frameworkName: String) -> String {
254227
// Sort list alphabetically
255-
let sortedSymbols: [String] = symbolLinks.sorted { $0.localizedCompare($1) == .orderedAscending }
256-
257-
// Check matching path components
258-
// for each path component after the initial path component....
259-
// for symbol in sortedSymbols {
260-
// // example path components: ["/", "documentation", "accelerate", "vdsp", "vector-scalar_real_arithmetic_functions"]
261-
// print(symbol.pathComponents)
262-
// }
228+
let sortedSymbols: [URL] = symbolLinks.sorted { $0.absoluteString.localizedCompare($1.absoluteString) == .orderedAscending }
263229

264230
var links: String = ""
265-
for symbol in sortedSymbols {
266-
links.append("\n- <\(symbol)>")
231+
232+
// find most similar path up until framework name by iterating over path components one at a time
233+
guard var first = sortedSymbols.first else {
234+
return links
235+
}
236+
237+
for symbol in sortedSymbols.dropFirst() {
238+
let parent: String = first.absoluteString.commonPrefix(with: symbol.absoluteString)
239+
240+
// If there are no common path components, add a space. Then reset the first to find the next parent.
241+
if parent.localizedLowercase.hasSuffix(frameworkName + "/") {
242+
links.append("\n\n")
243+
first = symbol
244+
}
245+
246+
links.append("\n- <\(findExternalLink(identifierURL: symbol))>")
267247
}
268248

269-
return links // TODO: STUB
249+
return links
270250
}
271251

272252
}

0 commit comments

Comments
 (0)