Skip to content

Commit d80a059

Browse files
authored
Add symbolGraphMinimumAccessLevel option support (#82)
* Add symbolGraphMinimumAccessLevel option support * Remove experimental prefix * Fix CR suggestion
1 parent 63f47d3 commit d80a059

File tree

6 files changed

+89
-5
lines changed

6 files changed

+89
-5
lines changed

Plugins/SharedPackagePluginExtensions/PackageManager+getSymbolGraphsForDocC.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,17 @@ extension PackageManager {
3939
context: PluginContext,
4040
verbose: Bool,
4141
snippetExtractor: SnippetExtractor?,
42-
customSymbolGraphOptions: [PluginFlag]
42+
customSymbolGraphOptions: [PluginFlag],
43+
minimumAccessLevel: SymbolGraphOptions.AccessLevel? = nil
4344
) throws -> DocCSymbolGraphResult {
4445
// First generate the primary symbol graphs containing information about the
4546
// symbols defined in the target itself.
4647

4748
var symbolGraphOptions = target.defaultSymbolGraphOptions(in: context.package)
48-
49+
if let minimumAccessLevel {
50+
symbolGraphOptions.minimumAccessLevel = minimumAccessLevel
51+
}
52+
4953
// Modify the symbol graph options with the custom ones
5054
for customSymbolGraphOption in customSymbolGraphOptions {
5155
switch customSymbolGraphOption {

Plugins/Swift-DocC Convert/SwiftDocCConvert.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ import PackagePlugin
7979
context: context,
8080
verbose: verbose,
8181
snippetExtractor: snippetExtractor,
82-
customSymbolGraphOptions: parsedArguments.symbolGraphArguments
82+
customSymbolGraphOptions: parsedArguments.symbolGraphArguments,
83+
minimumAccessLevel: parsedArguments.arguments.symbolGraphMinimumAccessLevel.flatMap { .init(rawValue: $0) }
8384
)
8485

8586
if target.doccCatalogPath == nil,

Plugins/Swift-DocC Preview/SwiftDocCPreview.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ import PackagePlugin
8484
context: context,
8585
verbose: verbose,
8686
snippetExtractor: snippetExtractor,
87-
customSymbolGraphOptions: parsedArguments.symbolGraphArguments
87+
customSymbolGraphOptions: parsedArguments.symbolGraphArguments,
88+
minimumAccessLevel: parsedArguments.arguments.symbolGraphMinimumAccessLevel.flatMap { .init(rawValue: $0) }
8889
)
8990

9091
if try FileManager.default.contentsOfDirectory(atPath: symbolGraphs.targetSymbolGraphsDirectory.path).isEmpty {
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// This source file is part of the Swift.org open source project
2+
//
3+
// Copyright (c) 2022 Apple Inc. and the Swift project authors
4+
// Licensed under Apache License v2.0 with Runtime Library Exception
5+
//
6+
// See https://swift.org/LICENSE.txt for license information
7+
// See https://swift.org/CONTRIBUTORS.txt for Swift project authors
8+
9+
import Foundation
10+
11+
extension Arguments {
12+
/// The symbol graph minimum access level, if any, described by this set of command-line arguments.
13+
public var symbolGraphMinimumAccessLevel: String? {
14+
guard let accessLevelOptionIndex = firstIndex(
15+
where: { argument in
16+
return CommandLineOption.symbolGraphMinimumAccessLevel.possibleNames.contains(argument)
17+
}
18+
) else {
19+
return nil
20+
}
21+
let accessLevelIndex = index(after: accessLevelOptionIndex)
22+
guard indices.contains(accessLevelIndex) else {
23+
return nil
24+
}
25+
return self[accessLevelIndex]
26+
}
27+
}

Sources/SwiftDocCPluginUtilities/CommandLineOptions/CommandLineOption.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ extension CommandLineOption {
6060
defaultName: "--fallback-default-module-kind"
6161
)
6262

63-
/// A DocC flag that enables support for linking to other DocC archives and enables
63+
/// A DocC flag that enables support for linking to other DocC archives and enables
6464
/// other documentation builds to link to the generated DocC archive.
6565
static let enableExternalLinkSupport = CommandLineOption(
6666
defaultName: "--enable-experimental-external-link-support"
@@ -70,4 +70,9 @@ extension CommandLineOption {
7070
static let externalLinkDependency = CommandLineOption(
7171
defaultName: "--dependency"
7272
)
73+
74+
/// Specifies the symbol graph minimum access level.
75+
static let symbolGraphMinimumAccessLevel = CommandLineOption(
76+
defaultName: "--symbol-graph-minimum-access-level"
77+
)
7378
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// This source file is part of the Swift.org open source project
2+
//
3+
// Copyright (c) 2024 Apple Inc. and the Swift project authors
4+
// Licensed under Apache License v2.0 with Runtime Library Exception
5+
//
6+
// See https://swift.org/LICENSE.txt for license information
7+
// See https://swift.org/CONTRIBUTORS.txt for Swift project authors
8+
9+
import Foundation
10+
import SwiftDocCPluginUtilities
11+
import XCTest
12+
13+
final class ArgumentsSymbolGraphMinimumAccessLevelTests: XCTestCase {
14+
func testArgumentsThatContainAccessLevel() {
15+
XCTAssertEqual(
16+
Arguments(["--symbol-graph-minimum-access-level", "internal"]).symbolGraphMinimumAccessLevel,
17+
"internal"
18+
)
19+
20+
XCTAssertEqual(
21+
Arguments(["other-arg", "--symbol-graph-minimum-access-level", "internal", "--other-flag"]).symbolGraphMinimumAccessLevel,
22+
"internal"
23+
)
24+
}
25+
26+
func testArgumentsThatDoNotContainAccessLevel() {
27+
XCTAssertNil(
28+
Arguments(["--other-option", "/test-path"]).symbolGraphMinimumAccessLevel
29+
)
30+
31+
XCTAssertNil(
32+
Arguments(["other-arg", "--other-option", "/test-path", "--other-flag"]).symbolGraphMinimumAccessLevel
33+
)
34+
}
35+
36+
func testArgumentsThatContainTrailingAccessLevelFlag() {
37+
XCTAssertNil(
38+
Arguments(["--symbol-graph-minimum-access-level"]).symbolGraphMinimumAccessLevel
39+
)
40+
41+
42+
XCTAssertNil(
43+
Arguments(["other-arg", "--symbol-graph-minimum-access-level"]).symbolGraphMinimumAccessLevel
44+
)
45+
}
46+
}

0 commit comments

Comments
 (0)