Skip to content

Commit 959aa39

Browse files
Merge branch 'main' into add-extended-types-flag
2 parents e0b5fa9 + f04da08 commit 959aa39

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

Sources/snippet-extract/Utility/SymbolGraph+Snippet.swift

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,18 @@ extension SymbolGraph.Symbol {
1919
let identifier = SymbolGraph.Symbol.Identifier(precise: "$snippet__\(moduleName).\(basename)", interfaceLanguage: "swift")
2020
let names = SymbolGraph.Symbol.Names.init(title: basename, navigator: nil, subHeading: nil, prose: nil)
2121

22-
var pathComponents = snippet.sourceFile.absoluteURL.deletingPathExtension().pathComponents[...]
22+
var pathComponents = Array(snippet.sourceFile.absoluteURL.deletingPathExtension().pathComponents[...])
2323

2424
guard let snippetsPathComponentIndex = pathComponents.firstIndex(where: {
2525
$0 == "Snippets"
2626
}) else {
2727
throw SnippetExtractCommand.ArgumentError.snippetNotContainedInSnippetsDirectory(snippet.sourceFile)
2828
}
29-
pathComponents = pathComponents[snippetsPathComponentIndex...]
29+
30+
// In theory, there may be differently named snippet root directories in the future.
31+
// Replace that path component with the standardized `Snippets`.
32+
pathComponents.replaceSubrange(pathComponents.startIndex...snippetsPathComponentIndex,
33+
with: CollectionOfOne("Snippets"))
3034

3135
let docComment = SymbolGraph.LineList(snippet.explanation
3236
.split(separator: "\n", maxSplits: Int.max, omittingEmptySubsequences: false)
@@ -39,7 +43,7 @@ extension SymbolGraph.Symbol {
3943

4044
self.init(identifier: identifier,
4145
names: names,
42-
pathComponents: ["Snippets"] + Array(pathComponents),
46+
pathComponents: pathComponents,
4347
docComment: docComment,
4448
accessLevel: accessLevel,
4549
kind: kind,

Tests/SwiftDocCPluginUtilitiesTests/Snippets/SnippetSymbolTests.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,15 @@ class SnippetSymbolTests: XCTestCase {
3030
}
3131
})
3232
}
33+
34+
func testPathComponentsForSnippetSymbol() throws {
35+
let source = """
36+
// A snippet.
37+
foo() {}
38+
"""
39+
let snippet = Snippets.Snippet(parsing: source,
40+
sourceFile: URL(fileURLWithPath: "/path/to/my-package/Snippets/ASnippet.swift"))
41+
let symbol = try SymbolGraph.Symbol(snippet, moduleName: "my-package")
42+
XCTAssertEqual(["Snippets", "ASnippet"], symbol.pathComponents)
43+
}
3344
}

bin/test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ then
4949
git clone -b "${SWIFT_DOCC_RENDER_ARTIFACT_BRANCH}" "${SWIFT_DOCC_RENDER_ARTIFACT_REPO}" "$SWIFT_DOCC_RENDER_ARTIFACT_ROOT" || exit 1
5050

5151
echo "Building docc..."
52-
swift build --package-path "$SWIFT_DOCC_ROOT" --configuration release || exit 1
52+
swift build --package-path "$SWIFT_DOCC_ROOT" --product docc --configuration release || exit 1
5353

5454
export DOCC_EXEC="$(swift build --package-path "$SWIFT_DOCC_ROOT" --show-bin-path --configuration release)/docc"
5555
if [[ ! -f "$DOCC_EXEC" ]]; then
56-
echo "docc executable not found, expected at $SWIFT_DOCC_EXEC"
56+
echo "docc executable not found, expected at $DOCC_EXEC"
5757
exit 1
5858
else
5959
echo "Using docc executable: $DOCC_EXEC"

0 commit comments

Comments
 (0)