Skip to content

Commit 518aac4

Browse files
authored
Merge pull request #1459 from ahoppen/testable-methods
Change methods that were only public for testing purposes to be `@_spi(Testing)`
2 parents d96f2fb + 33d803f commit 518aac4

18 files changed

+91
-94
lines changed

Sources/LanguageServerProtocolJSONRPC/MessageCoding.swift

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

1313
import LanguageServerProtocol
1414

15-
/// *Public For Testing*. A single JSONRPC message suitable for encoding/decoding.
16-
public enum JSONRPCMessage {
15+
@_spi(Testing) public enum JSONRPCMessage {
1716
case notification(NotificationType)
1817
case request(_RequestType, id: RequestID)
1918
case response(ResponseType, id: RequestID)

Sources/SKCore/BuildSystemManager.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -417,8 +417,10 @@ extension BuildSystemManager {
417417

418418
extension BuildSystemManager {
419419

420-
/// *For Testing* Returns the main file used for `uri`, if this is a registered file.
421-
public func _cachedMainFile(for uri: DocumentURI) -> DocumentURI? {
420+
/// Returns the main file used for `uri`, if this is a registered file.
421+
///
422+
/// For testing purposes only.
423+
@_spi(Testing) public func cachedMainFile(for uri: DocumentURI) -> DocumentURI? {
422424
return self.watchedFiles[uri]?.mainFile
423425
}
424426
}

Sources/SKCore/ToolchainRegistry.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public final actor ToolchainRegistry {
7171

7272
/// Create a toolchain registry with a pre-defined list of toolchains.
7373
///
74-
/// For testing purposes.
74+
/// For testing purposes only.
7575
@_spi(Testing)
7676
public init(toolchains: [Toolchain]) {
7777
self.init(

Sources/SKCore/XCToolchainPlist.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,9 @@ extension XCToolchainPlist: Codable {
105105
self.displayName = try container.decodeIfPresent(String.self, forKey: .DisplayName)
106106
}
107107

108-
/// Encode the info plist. **For testing**.
108+
/// Encode the info plist.
109+
///
110+
/// For testing purposes only.
109111
public func encode(to encoder: Encoder) throws {
110112
var container = encoder.container(keyedBy: CodingKeys.self)
111113
if identifier.starts(with: "com.apple") {

Sources/SourceKitLSP/Clang/ClangLanguageService.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ actor ClangLanguageService: LanguageService, MessageHandler {
342342
return nil
343343
}
344344

345-
func _crash() {
345+
func crash() {
346346
// Since `clangd` doesn't have a method to crash it, kill it.
347347
#if os(Windows)
348348
if self.hClangd != INVALID_HANDLE_VALUE {

Sources/SourceKitLSP/LanguageService.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,5 +237,5 @@ public protocol LanguageService: AnyObject, Sendable {
237237
func canonicalDeclarationPosition(of position: Position, in uri: DocumentURI) async -> Position?
238238

239239
/// Crash the language server. Should be used for crash recovery testing only.
240-
func _crash() async
240+
func crash() async
241241
}

Sources/SourceKitLSP/SourceKitIndexDelegate.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ import SKSupport
1818
import SwiftExtensions
1919

2020
/// `IndexDelegate` for the SourceKit workspace.
21-
///
22-
/// *Public for testing*.
23-
public actor SourceKitIndexDelegate: IndexDelegate {
21+
actor SourceKitIndexDelegate: IndexDelegate {
2422

2523
let queue = AsyncQueue<Serial>()
2624

Sources/SourceKitLSP/SourceKitLSPServer.swift

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public actor SourceKitLSPServer {
112112

113113
var languageServices: [LanguageServerType: [LanguageService]] = [:]
114114

115-
let documentManager = DocumentManager()
115+
@_spi(Testing) public let documentManager = DocumentManager()
116116

117117
/// The `TaskScheduler` that schedules all background indexing tasks.
118118
///
@@ -131,11 +131,6 @@ public actor SourceKitLSPServer {
131131
private var inProgressPackageLoadingOperations = 0
132132
private var packageLoadingWorkDoneProgress: WorkDoneProgressManager?
133133

134-
/// **Public for testing**
135-
public var _documentManager: DocumentManager {
136-
return documentManager
137-
}
138-
139134
/// Caches which workspace a document with the given URI should be opened in.
140135
///
141136
/// - Important: Must only be modified from `workspaceQueue`. This means that the value of `uriToWorkspaceCache`
@@ -495,16 +490,7 @@ public actor SourceKitLSPServer {
495490
}
496491
}
497492

498-
/// **Public for testing purposes only**
499-
public func _languageService(
500-
for uri: DocumentURI,
501-
_ language: Language,
502-
in workspace: Workspace
503-
) async -> LanguageService? {
504-
return await languageService(for: uri, language, in: workspace)
505-
}
506-
507-
func languageService(
493+
@_spi(Testing) public func languageService(
508494
for uri: DocumentURI,
509495
_ language: Language,
510496
in workspace: Workspace

Sources/SourceKitLSP/Swift/SwiftLanguageService.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ public actor SwiftLanguageService: LanguageService, Sendable {
230230
}
231231

232232
/// - Important: For testing only
233-
public func setReusedNodeCallback(_ callback: (@Sendable (_ node: Syntax) -> ())?) async {
233+
@_spi(Testing) public func setReusedNodeCallback(_ callback: (@Sendable (_ node: Syntax) -> ())?) async {
234234
await self.syntaxTreeManager.setReusedNodeCallback(callback)
235235
}
236236

@@ -340,7 +340,7 @@ extension SwiftLanguageService {
340340
}
341341

342342
/// Tell sourcekitd to crash itself. For testing purposes only.
343-
public func _crash() async {
343+
public func crash() async {
344344
let req = sourcekitd.dictionary([
345345
keys.request: sourcekitd.requests.crashWithExit
346346
])

Sources/SourceKitLSP/Swift/SyntaxHighlightingTokenParser.swift

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ struct SyntaxHighlightingTokenParser {
205205

206206
extension Range<Position> {
207207
/// Splits a potentially multi-line range to multiple single-line ranges.
208-
func splitToSingleLineRanges(in snapshot: DocumentSnapshot) -> [Self] {
208+
@_spi(Testing) public func splitToSingleLineRanges(in snapshot: DocumentSnapshot) -> [Self] {
209209
if isEmpty {
210210
return []
211211
}
@@ -234,9 +234,4 @@ extension Range<Position> {
234234
}
235235
.filter { !$0.isEmpty }
236236
}
237-
238-
/// **Public for testing**
239-
public func _splitToSingleLineRanges(in snapshot: DocumentSnapshot) -> [Self] {
240-
splitToSingleLineRanges(in: snapshot)
241-
}
242237
}

0 commit comments

Comments
 (0)