Skip to content

Commit 56b7bca

Browse files
committed
Adopt package access level
Change a l public declarations to the `package` access level, accept for: - The `LanguageServerProtocol` module - The `BuildServerProtocol` module - `InProcessClient.InProcessSourceKitLSPClient` - `LanguageServerProtocolJSONRPC` (I would like to create a more ergonomic API for this like `InProcessSourceKitLSPClient` in the future, but for now, we’ll leave it public) Unfortunately, our pattern of marking functions as `@_spi(Testing) public` no longer works with the `package` access level because declarations at the `package` access level cannot be marked as SPI. I have decided to just mark these functions as `package`. Alternatives would be: - Add an underscore to these functions, like we did for functions exposed for testing before the introduction of `SPI` - Use `@testable` import in the test targets and mark the methods as `internal` Resolves #1315 rdar://128295618
1 parent f0e8645 commit 56b7bca

File tree

149 files changed

+1517
-1573
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

149 files changed

+1517
-1573
lines changed

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version: 5.8
1+
// swift-tools-version: 5.9
22

33
import Foundation
44
import PackageDescription

Sources/Diagnose/DebugCommand.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212

1313
import ArgumentParser
1414

15-
public struct DebugCommand: ParsableCommand {
16-
public static let configuration = CommandConfiguration(
15+
package struct DebugCommand: ParsableCommand {
16+
package static let configuration = CommandConfiguration(
1717
commandName: "debug",
1818
abstract: "Commands to debug sourcekit-lsp. Intended for developers of sourcekit-lsp",
1919
subcommands: [
@@ -24,5 +24,5 @@ public struct DebugCommand: ParsableCommand {
2424
]
2525
)
2626

27-
public init() {}
27+
package init() {}
2828
}

Sources/Diagnose/DiagnoseCommand.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ fileprivate enum BundleComponent: String, CaseIterable, ExpressibleByArgument {
4040
case swiftFrontendCrashes = "swift-frontend-crashes"
4141
}
4242

43-
public struct DiagnoseCommand: AsyncParsableCommand {
44-
public static let configuration: CommandConfiguration = CommandConfiguration(
43+
package struct DiagnoseCommand: AsyncParsableCommand {
44+
package static let configuration: CommandConfiguration = CommandConfiguration(
4545
commandName: "diagnose",
4646
abstract: "Creates a bundle containing information that help diagnose issues with sourcekit-lsp"
4747
)
@@ -109,7 +109,7 @@ public struct DiagnoseCommand: AsyncParsableCommand {
109109
["/Library/Logs/DiagnosticReports", "~/Library/Logs/DiagnosticReports"]
110110
}
111111

112-
public init() {}
112+
package init() {}
113113

114114
@MainActor
115115
private func addSourcekitdCrashReproducer(toBundle bundlePath: URL) async throws {
@@ -341,7 +341,7 @@ public struct DiagnoseCommand: AsyncParsableCommand {
341341
}
342342

343343
@MainActor
344-
public func run() async throws {
344+
package func run() async throws {
345345
// IMPORTANT: When adding information to this message, also add it to the message displayed in VS Code
346346
// (captureDiagnostics.ts in the vscode-swift repository)
347347
print(

Sources/Diagnose/IndexCommand.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ private actor IndexLogMessageHandler: MessageHandler {
5252

5353
}
5454

55-
public struct IndexCommand: AsyncParsableCommand {
56-
public static let configuration: CommandConfiguration = CommandConfiguration(
55+
package struct IndexCommand: AsyncParsableCommand {
56+
package static let configuration: CommandConfiguration = CommandConfiguration(
5757
commandName: "index",
5858
abstract: "Index a project and print all the processes executed for it as well as their outputs"
5959
)
@@ -79,9 +79,9 @@ public struct IndexCommand: AsyncParsableCommand {
7979
@Option(help: "The path to the project that should be indexed")
8080
var project: String
8181

82-
public init() {}
82+
package init() {}
8383

84-
public func run() async throws {
84+
package func run() async throws {
8585
let options = SourceKitLSPOptions(
8686
backgroundIndexing: true,
8787
experimentalFeatures: Set(experimentalFeatures)

Sources/Diagnose/ReduceCommand.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ import struct TSCBasic.AbsolutePath
1818
import class TSCBasic.Process
1919
import class TSCUtility.PercentProgressAnimation
2020

21-
public struct ReduceCommand: AsyncParsableCommand {
22-
public static let configuration: CommandConfiguration = CommandConfiguration(
21+
package struct ReduceCommand: AsyncParsableCommand {
22+
package static let configuration: CommandConfiguration = CommandConfiguration(
2323
commandName: "reduce",
2424
abstract: "Reduce a single sourcekitd crash"
2525
)
@@ -65,10 +65,10 @@ public struct ReduceCommand: AsyncParsableCommand {
6565
}
6666
}
6767

68-
public init() {}
68+
package init() {}
6969

7070
@MainActor
71-
public func run() async throws {
71+
package func run() async throws {
7272
guard let sourcekitd = try await toolchain?.sourcekitd else {
7373
throw ReductionError("Unable to find sourcekitd.framework")
7474
}

Sources/Diagnose/ReduceFrontendCommand.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ import struct TSCBasic.AbsolutePath
1818
import class TSCBasic.Process
1919
import class TSCUtility.PercentProgressAnimation
2020

21-
public struct ReduceFrontendCommand: AsyncParsableCommand {
22-
public static let configuration: CommandConfiguration = CommandConfiguration(
21+
package struct ReduceFrontendCommand: AsyncParsableCommand {
22+
package static let configuration: CommandConfiguration = CommandConfiguration(
2323
commandName: "reduce-frontend",
2424
abstract: "Reduce a single swift-frontend crash"
2525
)
@@ -73,10 +73,10 @@ public struct ReduceFrontendCommand: AsyncParsableCommand {
7373
}
7474
}
7575

76-
public init() {}
76+
package init() {}
7777

7878
@MainActor
79-
public func run() async throws {
79+
package func run() async throws {
8080
guard let sourcekitd = try await toolchain?.sourcekitd else {
8181
throw ReductionError("Unable to find sourcekitd.framework")
8282
}

Sources/Diagnose/ReduceSwiftFrontend.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
@MainActor
14-
@_spi(Testing)
15-
public func reduceFrontendIssue(
14+
package func reduceFrontendIssue(
1615
frontendArgs: [String],
1716
using executor: SourceKitRequestExecutor,
1817
progressUpdate: (_ progress: Double, _ message: String) -> Void

Sources/Diagnose/RequestInfo.swift

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ import Foundation
1414
import RegexBuilder
1515

1616
/// All the information necessary to replay a sourcektid request.
17-
@_spi(Testing)
18-
public struct RequestInfo: Sendable {
17+
package struct RequestInfo: Sendable {
1918
/// The JSON request object. Contains the following dynamic placeholders:
2019
/// - `$OFFSET`: To be replaced by `offset` before running the request
2120
/// - `$FILE`: Will be replaced with a path to the file that contains the reduced source code.
@@ -27,15 +26,12 @@ public struct RequestInfo: Sendable {
2726
var offset: Int
2827

2928
/// The compiler arguments of the request. Replaces the `$COMPILER_ARGS`placeholder in the request template.
30-
@_spi(Testing)
31-
public var compilerArgs: [String]
29+
package var compilerArgs: [String]
3230

3331
/// The contents of the file that the sourcekitd request operates on.
34-
@_spi(Testing)
35-
public var fileContents: String
32+
package var fileContents: String
3633

37-
@_spi(Testing)
38-
public func request(for file: URL) throws -> String {
34+
package func request(for file: URL) throws -> String {
3935
let encoder = JSONEncoder()
4036
encoder.outputFormatting = .prettyPrinted
4137
guard var compilerArgs = String(data: try encoder.encode(compilerArgs), encoding: .utf8) else {
@@ -60,8 +56,7 @@ public struct RequestInfo: Sendable {
6056
}
6157
"""
6258

63-
@_spi(Testing)
64-
public init(requestTemplate: String, offset: Int, compilerArgs: [String], fileContents: String) {
59+
package init(requestTemplate: String, offset: Int, compilerArgs: [String], fileContents: String) {
6560
self.requestTemplate = requestTemplate
6661
self.offset = offset
6762
self.compilerArgs = compilerArgs
@@ -71,8 +66,7 @@ public struct RequestInfo: Sendable {
7166
/// Creates `RequestInfo` from the contents of the JSON sourcekitd request at `requestPath`.
7267
///
7368
/// The contents of the source file are read from disk.
74-
@_spi(Testing)
75-
public init(request: String) throws {
69+
package init(request: String) throws {
7670
var requestTemplate = request
7771

7872
// Extract offset

Sources/Diagnose/RunSourcekitdRequestCommand.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ import SourceKitD
1818

1919
import struct TSCBasic.AbsolutePath
2020

21-
public struct RunSourceKitdRequestCommand: AsyncParsableCommand {
22-
public static let configuration = CommandConfiguration(
21+
package struct RunSourceKitdRequestCommand: AsyncParsableCommand {
22+
package static let configuration = CommandConfiguration(
2323
commandName: "run-sourcekitd-request",
2424
abstract: "Run a sourcekitd request and print its result"
2525
)
@@ -39,9 +39,9 @@ public struct RunSourceKitdRequestCommand: AsyncParsableCommand {
3939
@Option(help: "line:column override for key.offset")
4040
var position: String?
4141

42-
public init() {}
42+
package init() {}
4343

44-
public func run() async throws {
44+
package func run() async throws {
4545
var requestString = try String(contentsOf: URL(fileURLWithPath: sourcekitdRequestPath))
4646

4747
let installPath = try AbsolutePath(validating: Bundle.main.bundlePath)

Sources/Diagnose/SourceKitD+RunWithYaml.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ import SourceKitD
1414

1515
extension SourceKitD {
1616
/// Parse the request from YAML and execute it.
17-
@_spi(Testing)
18-
public func run(requestYaml: String) async throws -> SKDResponse {
17+
package func run(requestYaml: String) async throws -> SKDResponse {
1918
let request = try requestYaml.cString(using: .utf8)?.withUnsafeBufferPointer { buffer in
2019
var error: UnsafeMutablePointer<CChar>?
2120
let req = api.request_create_from_yaml(buffer.baseAddress!, &error)

Sources/Diagnose/SourceKitDRequestExecutor.swift

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ import class TSCBasic.Process
1818
import struct TSCBasic.ProcessResult
1919

2020
/// The different states in which a sourcekitd request can finish.
21-
@_spi(Testing)
22-
public enum SourceKitDRequestResult: Sendable {
21+
package enum SourceKitDRequestResult: Sendable {
2322
/// The request succeeded.
2423
case success(response: String)
2524

@@ -44,8 +43,7 @@ fileprivate extension String {
4443
}
4544

4645
/// An executor that can run a sourcekitd request and indicate whether the request reprodes a specified issue.
47-
@_spi(Testing)
48-
public protocol SourceKitRequestExecutor {
46+
package protocol SourceKitRequestExecutor {
4947
@MainActor func runSourceKitD(request: RequestInfo) async throws -> SourceKitDRequestResult
5048
@MainActor func runSwiftFrontend(request: RequestInfo) async throws -> SourceKitDRequestResult
5149
}
@@ -62,8 +60,7 @@ extension SourceKitRequestExecutor {
6260
}
6361

6462
/// Runs `sourcekit-lsp run-sourcekitd-request` to check if a sourcekit-request crashes.
65-
@_spi(Testing)
66-
public class OutOfProcessSourceKitRequestExecutor: SourceKitRequestExecutor {
63+
package class OutOfProcessSourceKitRequestExecutor: SourceKitRequestExecutor {
6764
/// The path to `sourcekitd.framework/sourcekitd`.
6865
private let sourcekitd: URL
6966

@@ -80,8 +77,7 @@ public class OutOfProcessSourceKitRequestExecutor: SourceKitRequestExecutor {
8077
/// considered to reproduce the issue.
8178
private let reproducerPredicate: NSPredicate?
8279

83-
@_spi(Testing)
84-
public init(sourcekitd: URL, swiftFrontend: URL, reproducerPredicate: NSPredicate?) {
80+
package init(sourcekitd: URL, swiftFrontend: URL, reproducerPredicate: NSPredicate?) {
8581
self.sourcekitd = sourcekitd
8682
self.swiftFrontend = swiftFrontend
8783
self.reproducerPredicate = reproducerPredicate
@@ -139,8 +135,7 @@ public class OutOfProcessSourceKitRequestExecutor: SourceKitRequestExecutor {
139135
}
140136
}
141137

142-
@_spi(Testing)
143-
public func runSwiftFrontend(request: RequestInfo) async throws -> SourceKitDRequestResult {
138+
package func runSwiftFrontend(request: RequestInfo) async throws -> SourceKitDRequestResult {
144139
try request.fileContents.write(to: temporarySourceFile, atomically: true, encoding: .utf8)
145140

146141
let arguments = request.compilerArgs.replacing(["$FILE"], with: [temporarySourceFile.path])
@@ -152,8 +147,7 @@ public class OutOfProcessSourceKitRequestExecutor: SourceKitRequestExecutor {
152147
return requestResult(for: result)
153148
}
154149

155-
@_spi(Testing)
156-
public func runSourceKitD(request: RequestInfo) async throws -> SourceKitDRequestResult {
150+
package func runSourceKitD(request: RequestInfo) async throws -> SourceKitDRequestResult {
157151
try request.fileContents.write(to: temporarySourceFile, atomically: true, encoding: .utf8)
158152
let requestString = try request.request(for: temporarySourceFile)
159153
try requestString.write(to: temporaryRequestFile, atomically: true, encoding: .utf8)

Sources/Diagnose/SourceReducer.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,8 @@ import SwiftSyntax
2020
// MARK: - Entry point
2121

2222
extension RequestInfo {
23-
@_spi(Testing)
2423
@MainActor
25-
public func reduceInputFile(
24+
package func reduceInputFile(
2625
using executor: SourceKitRequestExecutor,
2726
progressUpdate: (_ progress: Double, _ message: String) -> Void
2827
) async throws -> RequestInfo {

Sources/Diagnose/Toolchain+SwiftFrontend.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ extension Toolchain {
1717
/// The path to `swift-frontend` in the toolchain, found relative to `swift`.
1818
///
1919
/// - Note: Not discovered as part of the toolchain because `swift-frontend` is only needed in the diagnose commands.
20-
@_spi(Testing)
21-
public var swiftFrontend: URL? {
20+
package var swiftFrontend: URL? {
2221
return swift?.asURL.deletingLastPathComponent().appendingPathComponent("swift-frontend")
2322
}
2423
}

Sources/InProcessClient/LocalConnection.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import LanguageServerProtocol
2626
/// conn.send(...) // handled by server
2727
/// conn.close()
2828
/// ```
29-
public final class LocalConnection: Connection, Sendable {
29+
package final class LocalConnection: Connection, Sendable {
3030
private enum State {
3131
case ready, started, closed
3232
}
@@ -46,7 +46,7 @@ public final class LocalConnection: Connection, Sendable {
4646
/// - Important: Must only be accessed from `queue`
4747
nonisolated(unsafe) private var handler: MessageHandler? = nil
4848

49-
public init(name: String) {
49+
package init(name: String) {
5050
self.name = name
5151
}
5252

@@ -58,7 +58,7 @@ public final class LocalConnection: Connection, Sendable {
5858
}
5959
}
6060

61-
public func start(handler: MessageHandler) {
61+
package func start(handler: MessageHandler) {
6262
queue.sync {
6363
precondition(state == .ready)
6464
state = .started
@@ -74,7 +74,7 @@ public final class LocalConnection: Connection, Sendable {
7474
state = .closed
7575
}
7676

77-
public func close() {
77+
package func close() {
7878
queue.sync {
7979
closeAssumingOnQueue()
8080
}
@@ -87,7 +87,7 @@ public final class LocalConnection: Connection, Sendable {
8787
}
8888
}
8989

90-
public func send<Notification: NotificationType>(_ notification: Notification) {
90+
package func send<Notification: NotificationType>(_ notification: Notification) {
9191
logger.info(
9292
"""
9393
Sending notification to \(self.name, privacy: .public)
@@ -100,7 +100,7 @@ public final class LocalConnection: Connection, Sendable {
100100
handler.handle(notification)
101101
}
102102

103-
public func send<Request: RequestType>(
103+
package func send<Request: RequestType>(
104104
_ request: Request,
105105
reply: @Sendable @escaping (LSPResult<Request.Response>) -> Void
106106
) -> RequestID {

0 commit comments

Comments
 (0)